Log in

View Full Version : transcoding .264


jofarmer
23rd September 2008, 13:34
I am still finding the optimum way of backing up my Blu-ray disks. In the end there should be a .m2ts that I can burn to a BD9 (DVD-DL).

Thanks to tsmuxer I found a way to "edit" the content (throw away all those commentarys and languages I have no need for) and get all the small parts at the beginning into one file (darn those studios that produce clutter by having the title played in different languages).

So now I have a all the languages I want (tsmuxer) with the quality I want (eac3to) and the .sup (-title) tracks I want, all I need to do is transcode the .264 stream to a lower bitrate.

Any good hints how to do that possibly using x264, maybe even in Ubuntu...? if not x264, the tool has to be multi-threaded.

nm
23rd September 2008, 14:54
MEncoder+x264 is a good choice on Linux. To build MEncoder with the latest x264 GIT, try something like this:

1. Install GCC and some essential tools, remove any existing MPlayer/MEncoder installationssudo apt-get install build-essential xorg-dev git-core subversion yasm
sudo apt-get remove mplayer mplayer-nogui

Note: If you are using Hardy, the yasm version in the repository is too old. See step 3. in http://ubuntuforums.org/showthread.php?t=786095

2. Build and install x264git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-shared
make
sudo make install
sudo ldconfig
cd ..

3. Build and install MPlayer/MEncodersvn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd mplayer
./configure --enable-largefiles
make
sudo make install
cd ..

4. Check that MEncoder has been correctly installed and linked against the new x264 library:
ldd /usr/local/bin/mencoder | grep x264... it should print something like this (the version and hex part doesn't have to be the same):
libx264.so.64 => /usr/local/lib/libx264.so.64 (0x00007fdd46190000)


I may have forgotten to list some required tools or steps, but once you get it working, you can use x264 through MEncoder like this:

mencoder -nosound -noskip -ovc x264 -x264encopts crf=20:frameref=3:mixed_refs:me=umh:bframes=3:b_adapt=2:weight_b:brdo:bime:b_pyramid:8x8dct:subq=7:trellis=2:psy_rd=1.0,1.0:threads=0 -of rawvideo -o output.264 input.264

If you are not yet familiar with x264, note that the settings above are quite heavy (high quality but slow). Search for x264 CLI usage advice on Doom9 and read the MEncoder manual page (search for x264encopts) and HTML documentation.

Since your output size is limited (DVD9), you'll probably want to set a target bitrate instead of using CRF. Use two-pass mode with faster first-pass encoding settings (there is a turbo shortcut in MEncoder, but if you use b_adapt=2, it is probably better to set the reduced parameters yourself). For Blu-ray compatibility, you'll need to also change keyint, add VBV buffer settings and set the correct level (level_idc=41). These have been discussed elsewhere.

jofarmer
23rd September 2008, 17:40
..a lot! Installed everything and now I can use x264, which I am not so very new to. It is slowly churnig away at ~4fps now ;-)

Will have to experiment with CBR and VBR a little, but now I can!

:thanks:

Should this thread be found by other semi-newbies like me, I found this (http://mewiki.project357.com/wiki/X264_Settings) site a good insight into x264 settings (though not Blu-ray-specific)

jofarmer
24th September 2008, 06:59
I may have forgotten to list some required tools or steps, but once you get it working, you can use x264 through MEncoder like this:


Thanks. I seem to be running into one specific problem using mencoder whenever I use x264opts other than yours (for instance these (http://forum.doom9.org/showthread.php?t=141376)):

Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
FATAL: Cannot initialize video driver.

Needless to say I have no idea why any scaling should be necessary, if that is at all the problem (sar=1:1 did not help).

I have not found a solution to that in this forum, this (http://forum.doom9.org/showthread.php?t=101268&highlight=FATAL%3A+initialize+video+driver.), this (http://forum.doom9.org/showthread.php?t=139878&highlight=FATAL%3A+initialize+video+driver.), this (http://forum.doom9.org/showthread.php?t=115525&highlight=FATAL%3A+initialize+video+driver.) or any other thread did not help me at all :-(

jofarmer
24th September 2008, 07:19
Using these options:mencoder -nosound -noskip -ovc x264 -x264encopts level_idc=41:keyint=24:min-keyint=1:mixed-refs:no-fast-pskip:bframes=3:b-pyramid:b-rdo:bime:weightb:direct=auto:subme=7:trellis=2:partitions=none:vbv-bufsize=15000:vbv-maxrate=11880:scenecut=32:me=umh:merange=24:threads=8:aq-strength=0.9:mvrange=511:aud -vf scale=1920:1080 -of rawvideo -o output.264 input.264
and thus adding -vf scale=1920:1080 to the mencoder input lets it complain about something different: Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
[swscaler @ 0xb8c920]using unscaled yuv420p -> yuv420p special converter
x264 [error]: no ratecontrol method specified
x264_encoder_open failed.
FATAL: Cannot initialize video driver.


I DO have a method of ratecontrol specified and I still do not understand what mencoder wants from me...

Sagekilla
24th September 2008, 14:56
No where in that command line do I see any rate control.


x264encopts
level_idc=41
keyint=24
min-keyint=1
mixed-refs:
no-fast-pskip
bframes=3
b-pyramid
b-rdo
bime
weightb
direct=auto
subme=7
trellis=2
partitions=none
vbv-bufsize=15000
vbv-maxrate=11880
scenecut=32
me=umh
merange=24
threads=8
aq-strength=0.9
mvrange=511
aud -vf scale=1920:1080
-of rawvideo
-o output.264
input.264

None of that is rate control. Where's the specified bitrate? Or CRF, or QP? You defined no rate control. VBV-maxrate and VBV-bufsize != rate control!

nm
24th September 2008, 16:58
Thanks. I seem to be running into one specific problem using mencoder whenever I use x264opts other than yours (for instance these (http://forum.doom9.org/showthread.php?t=141376)):

Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
FATAL: Cannot initialize video driver.
You can ignore the prescaling message. MEncoder doesn't actually resize unless you tell it to (by using -vf scale). Here it just notifies that it detected the correct movie aspect ratio (16:9) and passes it forward to the encoder or the muxer.

The actual error message is probably earlier in the output, maybe in the first lines. Most likely you used x264 syntax for some parameter instead of the slightly different MEncoder syntax. Post the full command line if you still have problems with some parameter.

Needless to say I have no idea why any scaling should be necessary, if that is at all the problem (sar=1:1 did not help).
There is usually no need to manually specify the aspect ratio.

jofarmer
25th September 2008, 15:14
...for all the help. I have been trying adding options one by one and one culprit seems to be nal-hrd - it just won't work with it (as a mencoder x264 suboption, that is).

nm
25th September 2008, 15:20
...for all the help. I have been trying adding options one by one and one culprit seems to be nal-hrd - it just won't work with it (as a mencoder x264 suboption, that is).
Have you patched your x264 source tree with the nal-hrd patch before compiling? It isn't in vanilla x264 git.

jofarmer
25th September 2008, 15:54
Have you patched your x264 source tree with the nal-hrd patch before compiling? It isn't in vanilla x264 git.

Oops. No. It wasn't in your how-to, so... But I could have thought of that, since it isn't an option described here (http://mewiki.project357.com/wiki/X264_Settings) - I took the wiki to be outdated.

But according to this (http://forum.doom9.org/showthread.php?p=1160838#post1160838) post I don't necessarily need it as long as I mux the final BD with tsmuxer, right?

But if I want HD-DVD compatibility I need it, so where can it be found? Please bear with me, my learning curve in this forum is steep... ;-)

jofarmer
25th September 2008, 18:58
Nevermind, I figured it out by myself, reading this (http://forum.doom9.org/showthread.php?t=130364) thread and using this (http://komisar.gin.by/x.patch/last.used/x264_hrd_pulldown.09_interlace.diff) diff...