Skip to content

Instantly share code, notes, and snippets.

@markbahnman
Last active April 20, 2016 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markbahnman/72c6301348dc2b2ab147f150d80fbfe6 to your computer and use it in GitHub Desktop.
Save markbahnman/72c6301348dc2b2ab147f150d80fbfe6 to your computer and use it in GitHub Desktop.
Nice script to convert your mkvs to mp4s using ffmpeg
#!/bin/sh
LOG="$HOME/convert-to-mp4.log"
for arg; do
if [ -d "$arg" ]; then
echo "$arg is a directory\n"
find ${arg%/} -type f -name "*.mkv" -print0 | while IFS= read -r -d '' file; do
DIR=$(dirname "${file}")
BASE=$(basename "${file}" ".mkv")
cd "${DIR}"
MKV=$(find . -maxdepth 1 -name "${BASE}.mkv" -print0)
MP4=$(find . -maxdepth 1 -name "${BASE}.mp4" -print0)
if [ -f "$MKV" ] && [ ! -f "$MP4" ]; then
printf "Converting ${file}\n" >> $LOG
ffmpeg -i "${BASE}.mkv" -c copy "${BASE}.mp4"
MKV=$(find . -maxdepth 1 -name "${BASE}.mkv" -print0)
MP4=$(find . -maxdepth 1 -name "${BASE}.mp4" -print0)
if [ -f "$MKV" ] && [ ! -f "$MP4" ]; then
printf "Converter FAILED\n" >> $LOG
else
printf "Converter SUCCESSFUL\n" >> $LOG
fi
else
printf "Already converted ${file}\n" >> $LOG
fi
done
else
printf "${arg%/} is not a directory\n" >> $LOG
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment