2023-09-28 04:07:20 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-09-27 22:59:16 +00:00
|
|
|
|
|
|
|
# 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
|
2023-09-28 04:07:20 +00:00
|
|
|
*".m4v")
|
2023-09-27 22:59:16 +00:00
|
|
|
oldfile=$file
|
2023-09-28 04:07:20 +00:00
|
|
|
newfile=${oldfile/%.m4v/.mp4}
|
2023-09-27 22:59:16 +00:00
|
|
|
;;
|
2023-09-28 04:07:20 +00:00
|
|
|
*".avi")
|
2023-09-27 22:59:16 +00:00
|
|
|
oldfile=$file
|
2023-09-28 04:07:20 +00:00
|
|
|
newfile=${oldfile/%.avi/.mp4}
|
2023-09-27 22:59:16 +00:00
|
|
|
;;
|
2023-09-28 04:07:20 +00:00
|
|
|
*".mkv")
|
2023-09-27 22:59:16 +00:00
|
|
|
oldfile=$file
|
2023-09-28 04:07:20 +00:00
|
|
|
newfile=${oldfile/%.mkv/.mp4}
|
2023-09-27 22:59:16 +00:00
|
|
|
;;
|
2023-09-28 04:07:20 +00:00
|
|
|
*".mp4")
|
2023-09-27 22:59:16 +00:00
|
|
|
oldfile=$file
|
2023-09-28 04:07:20 +00:00
|
|
|
newfile=${oldfile/%.mp4/.NEW.mp4}
|
2023-09-27 22:59:16 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# 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
|