Simple Howto for re-encoding (bluray) MKV's (linux)

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
Posts: 349
Joined: Thu Jan 14, 2010 4:23 am

Re: Simple Howto for re-encoding (bluray) MKV's (linux)

Post by skittle » Tue Aug 24, 2010 6:22 am

All files can be obtained from links in the first post.

Posts: 1
Joined: Thu May 14, 2020 8:34 am

Re: Simple Howto for re-encoding (bluray) MKV's (linux)

Post by Gerros » Thu May 14, 2020 8:35 am

skittle wrote:
Thu Apr 29, 2010 8:53 pm
This will cover my favorite method: using x264 compiled with FFmpegSource2 input directly, or if crop/resize is needed pipe from mplayer->x264. In either case, end up muxing everything together with mkvmerge gui.
I do not suggest using x264 from repository. It will likely be very outdated and not contain ffms2 input
First we need to get basic compiling dependencies (available in your repositories):
yasm, libgpac-dev, subversion, git, automake, pkg-config

Second we need to download and compile (do not use from repository) in this order: ffmpeg, ffms2, then x264:

Code: Select all

#get and compile ffmpeg and disable all but video decoders
cd /home/<usr>/source/
#svn checkout svn:// --revision {2010-07-01} ffmpeg #use this syntax to checkout older ffmpeg if current is broken
svn checkout svn:// ffmpeg
cd ffmpeg
./configure --disable-everything --enable-gpl --enable-postproc --enable-protocols --enable-demuxer=matroska,ogg,avi,h264,mov,m4v,mpegts,mpegvideo --enable-decoder=h264,vc1,wmv*,mpeg2video,mpeg1video,mpeg4,theora,vp8 --enable-parser=h264,mpeg4video,mpegvideo,vc1,vp8
sudo make install

Code: Select all

#get and compile ffms2
cd /home/<usr>/source/
svn checkout ffms2
cd ffms2
sudo make install

Code: Select all

#get and compile x264 with ffms2 input
cd /home/<user>/source/
git clone git:// x264
cd x264
sudo make install
Now that x264 is compiled, you can call it directly! Here is a simple command for a standard bluray movie using preset+tuning system in recent x264:

Code: Select all

x264 <input>.mkv --preset slow --crf 18 --tune film --level 41 --colormatrix bt709 --output <output>.mkv
x264 now supports cropping and resizing natively with the switch --vf. Please read the help page for more information.

If you want more exotic filters that are not included in x264 filter code, you can use mplayer (from repo, or compiled your self) to decode and pipe cropped/resized/filtered source input to x264. This is the most common method using linux pipes:
(NOTE: if piping from mplayer/ffmpeg you do not need to compile x264 with ffms2/lavf input)

Code: Select all

mkfifo pipe.y4m
x264 pipe.y4m --preset slow --crf 18 --tune film --level 41 --colormatrix bt709 --output <output>.mkv & mplayer <input>.mkv -vf <crop/resize/filter> -benchmark -vo yuv4mpeg:file=pipe.y4m -nosound -really-quiet
When its done, use MKVmerge(gui) to put it all back together. You can find mkverge, part of mkvtoolnix here: ... loads.html

And of course read 'x264 --fullhelp' for x264 options, and mplayer man page for more information on cropping and resizing (you can use mplayer -vf cropdetect to sort of auto cropping)

This guide was written for linux, but similar method will work in OSX/windows. (windows has to use raw stdout/stdin pipe)

update 07-03-2010: changed commandline to be more readable and avoid compile errors in ffmpeg
update 07-17-2010: x264 now supports basic crop/resize natively

Post Reply