[MPlayer-users] mencoder, x264 and mbtree => different frame count with 2 pass encoding

Wolfgang Breyha wbreyha at gmx.net
Sun Sep 19 20:22:18 CEST 2010


Hi!

I'm using mencoder (r32106-svn) with the following commandline:
mencoder -v -o /var/tmp/test.avi -passlogfile /var/tmp/test_mbtree.2passlog
-ovc x264 -x264encopts
pass=x:threads=1:bitrate=600:weightp=0:no8x8dct:cqm=flat:subme=6:force_cfr:frameref=5:bframes=1:me=umh:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=125:rc_lookahead=40
-vf scale=800:-2,crop=800:600:0:0,scale=-10:-1,harddup -oac faac -faacopts
br=96:mpeg=4:object=2 -channels 2 -srate 44100 -ofps 25 /var/tmp/test.mkv

If I run pass 1 mencoder produces
x264 [info]: frame I:21    Avg QP:15.48  size: 28443
x264 [info]: frame P:1606  Avg QP:18.42  size:  3631
x264 [info]: frame B:843   Avg QP:23.67  size:   797
==> 2470 frames

The 2nd pass produces...
x264 [error]: Incomplete MB-tree stats file.
x264_encoder_encode failed
x264 [error]: 2nd pass has more frames than 1st pass (2470)
x264 [error]: continuing anyway, at constant QP=18
x264 [error]: disabling adaptive B-frames
...
x264 [info]: frame I:22    Avg QP:14.10  size: 30477
x264 [info]: frame P:1631  Avg QP:17.11  size:  3983
x264 [info]: frame B:867   Avg QP:20.42  size:   742
==> 2520 frames

I tried to figure out why...

The main reason seems to be the fact that libx264 produces different
encoder delays in both passes. Since rc_lookahead=40 and mbtree is active
there is a delay of 40 frames in the 1st pass. In the second pass this
delay is not in place and only the number of threads used affects the delay
(eg. 2 threads => 4 frames).

Since the encoder_delay is used to calculate the AV_Delay in mencoder.c:1611++
---
    AV_delay -= (float) mux_a->encoder_delay *
mux_a->h.dwScale/mux_a->h.dwRate;
    AV_delay += (float) mux_v->encoder_delay *
mux_v->h.dwScale/mux_v->h.dwRate;
---
it results in different framecounts. But even setting mux_v->encoder_delay
to 1 for a test is not enough to produce same frame count in both passes.

It seems impossible to use x264/mbtree without -mc 0 and -noskip.

Regards, Wolfgang
-- 
Wolfgang Breyha <wbreyha at gmx.net> | http://www.blafasel.at/
Vienna University Computer Center | Austria


More information about the MPlayer-users mailing list