PDA

View Full Version : x264 doesn't respect the bitrate [SOLVED]


Guilllo
24th July 2006, 23:23
Hi !!

I've got a problem encoding with x264

I'v got latest svn versions of mplayer and x264.

Here is my encoding script

mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=3:turbo=0:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi

I've got a small file of 300Mb which overall bitrate is 540 kb/s.

Where is the problem ?
Thanks

foxyshadis
25th July 2006, 02:40
Did you do all three passes? Or just start at pass 3?

Guilllo
25th July 2006, 08:51
I made the first pass with the" corect settings and the average bitrate was already low : 310 kbits/s.

Then I made the second pass.

check
25th July 2006, 08:56
can you please post the settings you used for the first and second passes?

Guilllo
25th July 2006, 09:26
For the first pass :

mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf pp=lb,crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=1:turbo=2:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi

For the second pass :

mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf pp=lb,crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=3:turbo=0:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi

nm
25th July 2006, 10:28
Um, what's with the "&& mencoder ... pass=3 ..." part after both pass 1 and pass 2? You are actually doing 5 passes with those commands! This should work:

mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf pp=lb,crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=1:turbo=2:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi
mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf pp=lb,crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=3:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi
mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob -vf pp=lb,crop=704:432:10:72 -nosound -ovc x264 -x264encopts bitrate=1208:pass=3:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi

Guilllo
25th July 2006, 10:44
Well I've made a mistake posting the commands

Take a look at the commands i really used

Guilllo
25th July 2006, 10:46
I tried your commands and it's the same : bitrate is about 550 kbits . But I really don't know why, it's now faster encoding, 50 fps...

Manao
25th July 2006, 10:59
Guillo : how is the visual quality ? what happens if you make an encoding at constant quantizer = 10 ?

Guilllo
25th July 2006, 11:05
Visual quality ?? Lot of macroblocks in certains scenes but really good for a such bitrate.

How to encode with constant quantizer ? (option name)

Manao
25th July 2006, 12:18
vqscale=10 ( no need for 3 passes, nor to specify a bitrate )

Guilllo
25th July 2006, 13:21
vqscale=10

Huh ? I've found qp_constant=10 in mencoder doc. With this I've got a 6000 kbits file.

Manao
25th July 2006, 14:26
What is the duration of the file you obtain ? How do you compute the bitrate ?

Guilllo
25th July 2006, 15:40
With my script I obtain a 104 minutes file of 330 mo.

I calculated bitrate with 104 minutes with 64 kbits for sound on a 880 Mo file.

It said me 1208

Guilllo
26th July 2006, 15:50
Same problem with an other video source

nm
26th July 2006, 16:05
Perhaps your shell or mencoder can't read the command line completely for some reason. Open the resulting file in a hex (or a suitable text) editor and search for the x264 option string written there. Check if the bitrate option is the same as the one you gave to mencoder.

Then there's the possibility that the stats file can't be written to. You could try giving a specific location for it with the -passlogfile parameter and check that the file is actually created and that it grows while encoding.

Which Mencoder version or build are you using, by the way?

Manao
26th July 2006, 16:09
I don't know well enough mencoder, but does 'mencoder /windows/D/Narco/VIDEO_TS/VTS_01_1.vob' select all the vobs ? Or only the first one ?

nm
26th July 2006, 16:26
Ah yes, the first one only. To encode the whole title, you'll need to use "dvd://2 -dvd-device /windows/D/Narco/VIDEO_TS/" (where 2 is the number of the title; try playing it with mplayer and the same dvd-device option to select the right one). -dvd-device also accepts an iso image file.

celtic_druid
26th July 2006, 16:28
Just the first one. For all the VOB's I guess you would need something like cat *.VOB | mencoder

edit: yes if you have more than just VOB's, then specifying the title would work.

Guilllo
26th July 2006, 17:28
I've got only one vob

Guilllo
26th July 2006, 18:15
I've tried without any options and it seems to be the same

nm
26th July 2006, 18:53
Did you take a look at the avi file to see if any of the x264encopts are passed through to the x264 code?

Guilllo
26th July 2006, 19:39
No. Don' know how to do this

Guilllo
26th July 2006, 19:54
Here is what I can see at the end of the third pass (I stopped it before the end when I saw it was wrong and he video really bad)


MEncoder dev-SVN-r19186-4.1.0 (C) 2000-2006 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.20GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

success: format: 0 data: 0x0 - 0x201bf800
MPEG-PS file format detected.
VIDEO: MPEG2 720x576 (aspect 3) 25.000 fps 9800.0 kbps (1225.0 kbyte/s)
[V] filefmt:2 fourcc:0x10000002 size:720x576 fps:25.00 ftime:=0.0400
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 576 (preferred colorspace: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.
Try adding the scale filter, e.g. -vf spp,scale instead of -vf spp.
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b
Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))
==========================================================================
VDec: vo config request - 720 x 576 (preferred colorspace: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
SwScaler: using unscaled 0x32315659 (21VY) -> 0x32315659 (21VY) special converter
x264 [info]: using SAR=64/45
x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2
New_Face failed. Maybe the font path is wrong.n 0mb A-V:0.000 [0:0]
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.

1 duplicate frame(s)!
Writing header...
ODML: vprp aspect is 16:9.
Writing header...
ODML: vprp aspect is 16:9.
Writing header...5f ( 0%) 0.41fps Trem: 0min 0mb A-V:0.000 [0:0]
ODML: vprp aspect is 16:9.
Pos: 305.2s 7635f ( 5%) 7.37fps Trem: 316min 366mb A-V:0.000 [519:0]]]
Flushing video frames
x264 [error]: specified frame type is not compatible with max B-frames
x264 [error]: slice=P but 2pass stats say B
Writing index...
Writing header...
ODML: vprp aspect is 16:9.

Video stream: 519.246 kbit/s (64905 B/s) size: 19819622 bytes 305.360 secs 7635 frames
x264 [info]: slice I:33 Avg QP:26.00 size: 8507
x264 [info]: slice P:2892 Avg QP:26.00 size: 4086
x264 [info]: slice B:4708 Avg QP:27.71 size: 1631
x264 [info]: mb I I16..4: 70.8% 20.5% 8.7%
x264 [info]: mb P I16..4: 6.2% 6.0% 1.2% P16..4: 12.1% 4.6% 1.4% 0.1% 0.0% skip:68.3%
x264 [info]: mb B I16..4: 1.1% 2.6% 0.4% B16..8: 7.0% 0.7% 1.0% direct: 1.9% skip:85.5%
x264 [info]: 8x8 transform intra:49.2% inter:60.7%
x264 [info]: ref P 60.3% 19.5% 9.0% 6.4% 4.8%
x264 [info]: ref B 60.4% 16.2% 8.7% 7.1% 7.6%
x264 [info]: kb/s:518.1

nm
26th July 2006, 20:07
Try this: grep -a x264 file.avi > options.txt
Then open the options.txt file in some text editor or run "hd options.txt" or "hexdump -C options.txt".

The grep command should cut the part we're interested in (and some binary data at the same "line") from the binary file so that normal text editors can open it without too much problems.

From the Mencoder log, it is clear that x264 uses the default QP of 26, so at least the bitrate parameter is not passed through. To save encoding time, you should first try to get the bitrate parameter working with one pass. It is not necessary to encode all three at this point of solving the problem.

akupenguin
26th July 2006, 20:13
strings file.avi | grep x264 > options.txt
...gets rid of the binary part

Guilllo
26th July 2006, 20:54
I see this in the options.txt :

x264 - core 47 svn-518 - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=0:0:0 analyse=0x3:0x133 me=umh subme=7 brdo=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 chroma_qp_offset=0 slices=2 nr=0 decimate=1 bframes=3 b_pyramid=1 b_adapt=1 b_bias=0 direct=1 wpredb=1 bime=0 keyint=250 keyint_min=25 scenecut=40 rc=2pass bitrate=1351 ratetol=1.0 rceq='blurCplx^(1-qComp)' qcomp=0.60 qpmin=26 qpmax=10 qpstep=51 cplxblur=20.0 qblur=0.5 ip_ratio=1.40 pb_ratio=1.30



If I understand well qpmin is 26 but its not in my command :

mencoder /windows/D/THX1138/VIDEO_TS/VTS_01_1.vob -nosound -ovc x264 -x264encopts bitrate=1351:pass=3:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=7:threads=2:chroma_me:mixed_refs -o x264.avi

I tried the same movie with the same settings in avidemux2 and it seems to works great

Is there an option to display, in mencoder, during the encoding process, th quantizer used for each frame ?

Thanks for helping me

Guilllo
26th July 2006, 21:43
Here is a try at qp constant of 18 and it only uses 10. Normal ???

guilo@linux:~> mencoder /windows/D/THX1138/VIDEO_TS/VTS_01_1.vob -nosound -ovc x264 -x264encopts qp_constant=18:pass=1:keyint=250:keyint_min=25:scenecut=40:frameref=5:bframes=3:b_pyramid:nodeblock:cabac:qp_min=10:qp_max=51:qp_step=4:weight_b:i4x4:i8x8:b8x8mv:8x8mv:4x4mv:8x8dct:me=3:me_range=16:subq=2:threads=2:chroma_me:mixed_refs -o x264.avi
MEncoder dev-SVN-r19188-4.1.0 (C) 2000-2006 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.20GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

success: format: 0 data: 0x0 - 0x201bf800
MPEG-PS file format detected.
VIDEO: MPEG2 720x576 (aspect 3) 25.000 fps 9800.0 kbps (1225.0 kbyte/s)
[V] filefmt:2 fourcc:0x10000002 size:720x576 fps:25.00 ftime:=0.0400
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 576 (preferred colorspace: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.
Try adding the scale filter, e.g. -vf spp,scale instead of -vf spp.
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b
Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))
==========================================================================
VDec: vo config request - 720 x 576 (preferred colorspace: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
SwScaler: using unscaled 0x32315659 (21VY) -> 0x32315659 (21VY) special converter
x264 [info]: using SAR=64/45
x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2
New_Face failed. Maybe the font path is wrong.n 0mb A-V:0.000 [0:0]
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.

1 duplicate frame(s)!
Writing header...
ODML: vprp aspect is 16:9.
Writing header...
ODML: vprp aspect is 16:9.
Writing header...5f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
ODML: vprp aspect is 16:9.
Pos: 3.2s 83f ( 0%) 8.67fps Trem: 0min 0mb A-V:0.000 [3560:0]
Flushing video frames
Writing index...
Writing header...
ODML: vprp aspect is 16:9.

Video stream: 3903.815 kbit/s (487976 B/s) size: 1600564 bytes 3.280 secs 83 frames
x264 [info]: slice I:1 Avg QP:10.00 size: 184
x264 [info]: slice P:34 Avg QP:10.00 size: 37851
x264 [info]: slice B:46 Avg QP:11.67 size: 6790
x264 [info]: mb I I16..4: 99.9% 0.0% 0.1%
x264 [info]: mb P I16..4: 5.2% 8.5% 22.8% P16..4: 2.8% 1.5% 4.1% 1.5% 1.1% skip:52.4%
x264 [info]: mb B I16..4: 0.0% 0.1% 0.9% B16..8: 3.8% 0.3% 2.8% direct: 2.3% skip:89.8%
x264 [info]: final ratefactor: 190.02
x264 [info]: 8x8 transform intra:21.1% inter:29.4%
x264 [info]: ref P 80.6% 10.5% 4.3% 2.6% 2.1%
x264 [info]: ref B 92.2% 6.9% 0.6% 0.2% 0.1%
x264 [info]: kb/s:3949.3
guilo@linux:~>

nm
26th July 2006, 22:30
Here is a try at qp constant of 18 and it only uses 10. Normal ???
Nope, the average should show 18, and it does work fine for me with the same command line. There seems to be something fishy in your mencoder build. Did you compile it yourself or who packaged it? Try another package from some other archive, if possible, or try compiling it yourself (pretty easy once you get used to doing it). The x264 version used by your Mencoder build is a bit old anyway.

Guilllo
26th July 2006, 23:32
The x264 version used by your Mencoder build is a bit old anyway.


This must be the problem. I'm using latest svn. When i type x264 it says me its rev 538.....

Retrying download and build again.

It's the same for mencoder. I've built it myself from latest svn

nm
26th July 2006, 23:47
There's probably an older version of the x264 library installed somewhere on your system (/usr/lib perhaps) and the mplayer configure script detects and uses it instead of the newer one.

Guilllo
26th July 2006, 23:55
Yes, I've detected a conflict with an old package

Guilllo
26th July 2006, 23:59
Thanks a lot for your help it now works great