Last active
April 20, 2016 17:35
-
-
Save markbahnman/72c6301348dc2b2ab147f150d80fbfe6 to your computer and use it in GitHub Desktop.
Nice script to convert your mkvs to mp4s using ffmpeg
This file contains 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
#!/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