Anyway, here's the script, it will recursively remux all your mkv's to mp4's. It might not work with every mkv you find, but most of the "scene" stuff uses either AC3/AAC/DTS audio, and it will work for those. If you run into any problems, let me know, I'll try and make the script work as well as possible. I did once run into a problem where ffmpeg hosed up the audio in the resultant mp4, that's why there are those commented lines using mplayer and faac. If you find that ffmpeg is not converting the audio properly, comment the two lines that contain
- Code: Select all
ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac
- Code: Select all
#!/bin/bash
find . -type f | grep .mkv$ | while read file
do
directory=`dirname "$file"`
title=`basename "$file" .mkv`
AC3=`mkvinfo "$file" | grep AC3` #check if it's AC3 audio or DTS
AAC=`mkvinfo "$file" | grep AAC`
order=`mkvinfo "$file" | grep "Track type" | sed 's/.*://' | head -n 1 | tr -d " "` #check if the video track is first or the audio track
if [ "$order" = "video" ]; then
fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | head -n 1` #store the fps of the video track
if [ -n "$AC3" ]; then
mkvextract tracks "$file" 1:"${title}".264 2:"${title}".ac3
ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac
# mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3
# faac -o "${title}".aac "${title}".wav
elif [ -n "$AAC" ]; then
mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac
else
mkvextract tracks "$file" 1:"${title}".264 2:"${title}".dts
ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac
fi
else
fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | tail -n 1`
if [ -n "$AC3" ]; then
mkvextract tracks "$file" 1:"${title}".ac3 2:"${title}".264
ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac
# mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3
# faac -o "${title}".aac "${title}".wav
elif [ -n "$AAC" ]; then
mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac
else
mkvextract tracks "$file" 1:"${title}".dts 2:"${title}".264
ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac
fi
fi
MP4Box -new "${directory}/${title}".mp4 -add "${title}".264 -add "${title}".aac -fps $fps
rm -f "$title".aac "$title".dts "$title".ac3 "$title".264 "${title}".wav
# if [ -f "${directory}/${title}".mp4 ]; then
# rm -f "$file"
# fi
done
