Log on
Main page Graphics Photography Audio Video Tools Web Design Documents Space & Astro Amiga Funny Surreal Gallery Links & Contact

Loss conversion of MKV to MPEG4

A linux/unix guide

This example script will convert an H.264/AAC based .mkv file into an .mp4 (iso-mpeg4) file without loosing any quality at all. Please notice that you'll need to know the exact framerate of the original file before converting.

Simply copy the following code into a text file called "convert.sh", then set the +x permissions on the file, and run ./convert.sh

# lossless mkv to mp4 guide
# usage: reencode <input file> <framerate>
# requires: "media-video/mkvtoolnix", "media-video/mpeg4ip"
# todo: make it automatically figure out the framerate to avoid AV sync issues

rm video.264 audio.aac output.srt output.mp4 >/dev/null
mkvextract tracks "$1" 1:video.264 2:audio.aac 3:output.srt 4:more_tracks_than_expected
mp4creator -rate=$2 -create=video.264 output.mp4
mp4creator -create=audio.aac output.mp4
rm video.264 audio.aac

This will result in a file called "output.mp4" and perhaps in a file called "output.srt" if track 3 happens to be a subtitle track.

If you also get a file called "more_tracks_than_expected" it means that the original .mkv file had more than 4 tracks, and you'll need to modify this the way this script handles the different tracks of that file.

Website by Joachim Michaelis