Created
March 19, 2024 11:22
-
-
Save KernelPanicAUS/0e7d5cb2c6e0cc4ea599a55402ac86d7 to your computer and use it in GitHub Desktop.
Bulk encode MKV files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
trap ctrl_c INT | |
function ctrl_c() { | |
echo "** Trapped Ctrl+C **" | |
exit 0 # Exit the script with exit code 0 (successful termination) | |
} | |
input_dir=$1 | |
# an array containing all the mkv files in the input directory | |
mkv_files=$(find "$input_dir" -type f -name "*.mkv") | |
echo "--- Found $(echo "$mkv_files" | wc -l) files" | |
# check if ffmpeg is installed | |
if ! [ -x "$(command -v ffmpeg)" ]; then | |
echo 'Error: ffmpeg is not installed.' >&2 | |
exit 1 | |
fi | |
# loop through the array of mkv files and encode them to mp4 | |
for mkv_file in $mkv_files; do | |
echo "--- Encoding $mkv_file..." | |
file_name=$(basename "$mkv_file") | |
dir_name=$(dirname "$mkv_file") | |
# encode the file | |
ffmpeg -i "$mkv_file" -c copy "$dir_name/${file_name%%.*}.mp4" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment