Skip to content

Instantly share code, notes, and snippets.

@cibernox
Created April 25, 2024 14:10
Show Gist options
  • Save cibernox/139dbdb5d82fd5c954365ed86293fc57 to your computer and use it in GitHub Desktop.
Save cibernox/139dbdb5d82fd5c954365ed86293fc57 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Default pixel format
pixel_format="yuv420p10le"
# Parse command line options
while getopts ":pix_fmt:" opt; do
case ${opt} in
p )
pixel_format="$OPTARG"
;;
\? )
echo "Usage: $0 [-pix_fmt <pixel_format>] [<input_file>]"
exit 1
;;
esac
done
shift $((OPTIND -1))
# Check if an input file argument is provided
if [ $# -eq 1 ]; then
input_file="$1"
# Check if the file exists and is a regular file
if [ ! -f "$input_file" ]; then
echo "Input file does not exist or is not a regular file: $input_file"
exit 1
fi
files=("$input_file")
else
# No filename provided, process all MKV files in the folder
files=(*.mkv)
fi
# Loop through all MKV files
for file in "${files[@]}"; do
# Get the filename without extension
filename=$(basename "$file" .mkv)
echo "Name of the file without extension: "$filename""
# Check if the output file already exists
if [ ! -f "${filename}-AV1.mkv" ]; then
# Define the output filename
output="${filename}-AV1.mkv"
# Run ffmpeg command
echo "About to convert file named "$file""
ffmpeg -i "$file" -pix_fmt "$pixel_format" -map 0 -c:v libsvtav1 -crf 35 -preset 6 -svtav1-params tune=0 -g 240 -c:a libopus -b:a 128k -ac 2 -c:s copy "$output"
echo "Conversion complete for "$file""
else
echo "Output file ${filename}-AV1.mkv already exists. Skipping conversion for $file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment