mkmp4.sh/mkmp4.bash

71 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
# Daniel Bowling <swaggboi@slackware.uk>
# Dec 2020
# The double-quotes around the directory/files names are important
# because torrent'd files have some ridiculous file names
# Is this what you want??
while :; do
cat <<EOF
This script will attempt to traverse the current directory (and any
child directories) for video files to convert to .mkv format with
ffmpeg. Continue?? (y/N)
EOF
read -r answer
case "$answer" in
Y*|y*)
break
;;
*)
echo "bye"
exit 65
;;
esac
done
# Define this recursive function
conv_vid() {
# Begin a big ol loop for every file
for file in "$PWD"/*; do
if [ -f "$file" ]; then
case "$file" in
*".m4v")
oldfile=$file
newfile=${oldfile/%.m4v/.mp4}
;;
*".avi")
oldfile=$file
newfile=${oldfile/%.avi/.mp4}
;;
*".mkv")
oldfile=$file
newfile=${oldfile/%.mkv/.mp4}
;;
*".mp4")
oldfile=$file
newfile=${oldfile/%.mp4/.NEW.mp4}
;;
*)
# Next iteration of big ol loop
continue
;;
esac
if [ "$oldfile" ]; then
# Convert the file now
ffmpeg -i "$oldfile" -vcodec libx264 -acodec aac "$newfile"
fi
elif [ -d "$file" ]; then
(
cd "$file" || exit 64
conv_vid
)
fi
done
}
# Call the function
conv_vid