PDA

View Full Version : Mencoder won't obey bitrates


bmcotton
30th October 2006, 02:52
This is my first post, I apologise if I make a n00b mistake.

I'm trying to use mencoder to encode a DVD compliant mpeg2 stream. I've used a number of different versions of mencoder (can't tell you every version I tried) and different command lines to no avail. My last attempt was using Sagittaire's batch file. I specified a max bitrate of 9000 kbit/s and an average of 6500 kbit/s. My results:

Sagittaire's batch file using mencoder: 2454 kbit/s average, 5783 kbit/s peak.
TMPGENC /w same bitrate params: 5828 kbit/s average, 8093 kbit/s peak.

Both were done as 2-pass encodings

Any help would be much appreciated.

Thanks,
Brett

DarkZell666
30th October 2006, 11:55
I guess it's got to be your source which already has maxed out quality and doesn't need more bitrate. I'm curious about TMPGEnc's results. What resolution are you encoding to ? If it it's lower than 720*576 it could partly explain why. I would guess TMPGEnc resizes the video to 720*576 and that Sagittaire's batch doesn't.

Actually, can you post your complete command lines for us to check that you didn't indeed do something wrong ? ;)

What's your input source btw ? Is it an avisynth script ? An avi/mp4/mov/whatever video ?

Sagittaire
30th October 2006, 12:29
Certainely q2 saturation with "low bitrate" matrix. Be carefull if your average bitrate is close to your max bitrate then Mencoder's RC could have problem to respect vbv.

@echo off

@REM -----------------------------------------------------------------------------------------------
@REM
@REM MPEG2 Mencoder Profil
@REM
@REM -----------------------------------------------------------------------------------------------



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Output and Input files
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Input file name
set E_SRC=Encodage-HD-25.avs

@REM Output file name
set E_VID=MPEG2-5Mbps.m2v



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Rate control settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of bitrates
set E_BR=5000

@REM Set of max bitrates (use 9800 max for DVD compliant stream)
set VBV_MBR=9000

@REM Set of max buffer size (use 1835 max for DVD compliant stream)
set VBV_MBS=1835

@REM Set of ratio initial buffer occupency (0.9 is good value)
set VBV_IBO=0.9

@REM Set of first pass quantizer (2 is good value for high bitrate)
set E_IQ=3

@REM Set of min quantizer (1 is good value for high bitrate)
set E_MQ=2

@REM Set of quantizer variability [0.00;1.00] (0.75 is good value)
set E_VQ=0.75

@REM Set of inter quantizer masking [0.00;1.00] (0.00-0.50 is good interval)
set E_PMSK=0.25



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> GOP structure
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of max interval KFrame (use 15 for DVD PAL and 18 for DVD NTSC)
set E_MIK=15

@REM Set of max BFrames [0;4] (use 2 max for DVD compliant stream)
set E_MBF=2

@REM Set of Adaptative BFrames [0;2] (desactived is 0, fast is 1 and slow is 2)
set E_ABF=2

@REM Set of Slow Adaptative BFrames Refine [0;10] (0 is full search, higher is faster)
set E_SBF=2



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Motion estimation settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of ME range [0;9999] (use 128 for DVD compliant stream)
set E_RME=128

@REM Set of Rate Distortion Optimisation [0;2] (2 is the best)
set E_RDO=2

@REM Set of diamond size [-99;6] (negatives values are adaptative diamond)
set E_DIA=-6

@REM Set of comparison function for ME [0;2000] (0 is SAD, 1 is SSE, 2 is SADT, +256 for chroma ME)
set E_CMP=2

@REM Set of previous ME [0;2]
set E_PME=2

@REM Set of BFrame refinements [0;4] (Bframe Quality, 4 is best quality)
set E_BFR=4



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> VUI settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Display Aspect Ratio (4/3 or 16/9 for DVD compliant stream)
set E_DAR=16/9

@REM DC precision [8;10]
set E_DC=10

@REM Framerate (use 25 for PAL and 24000/1001 or 30000/1001 for NTSC)
set E_FPS=25

@REM Set intra matrix (use coef > 8 for DVD compliant stream with mencoder)
set E_INTRA=8,8,8,8,9,10,11,12,8,8,8,8,9,11,11,13,8,8,9,9,10,12,14,15,8,8,9,10,12,14,16,18,9,9,10,12,15,17,20,23,10,11,12,14,17,22,27,33,11,11,14,16,20,27,35,44,12,13,15,18,23,33,44,64

@REM Set inter matrix (use coef > 8 for DVD compliant stream with mencoder)
set E_INTER=8,8,8,8,9,9,10,10,8,8,8,8,9,9,10,10,8,8,8,9,9,10,10,11,8,8,9,9,10,10,11,13,9,9,9,10,11,12,13,15,9,9,10,10,12,14,16,20,10,10,10,11,13,16,21,25,10,10,11,13,15,20,25,32



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Mencoder CLI
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ECHO.---------------------------------------------------------------
ECHO.First pass ...
ECHO.---------------------------------------------------------------
mencoder.exe -priority idle %E_SRC% -o NUL -ovc lavc -ofps %E_FPS% -lavcopts vcodec=mpeg2video:vpass=1:turbo:sc_factor=1:vqscale=%E_IQ%:keyint=%E_MIK%:vqcomp=%E_VQ%:vmax_b_frames=%E_MBF%:vb_strategy=%E_ABF%:brd_scale=%E_SBF%:vb_qfactor=1.25:vb_qoffset=0.00:vi_qfactor=1.00:vi_qoffset=0.00:me_range=%E_RME%:preme=%E_PME%:dia=1:predia=1:mbd=%E_RDO%:precmp=0:cmp=0:subcmp=0:mv0:last_pred=0:dc=%E_DC%:psnr:aspect=%E_DAR%:inter_matrix=%E_INTER%:intra_matrix=%E_INTRA%:p_mask=%E_PMSK%:vqmin=%E_MQ%:lmin=%E_MQ%:vqblur=0.5:vrc_strategy=0 -of rawvideo -ffourcc MPG2

@REM @CLS

ECHO.---------------------------------------------------------------
ECHO.Second pass ...
ECHO.---------------------------------------------------------------
mencoder.exe -priority idle %E_SRC% -o NUL -ovc lavc -ofps %E_FPS% -lavcopts vcodec=mpeg2video:vpass=3:sc_factor=1:vbitrate=%E_BR%:keyint=%E_MIK%:vqcomp=%E_VQ%:vmax_b_frames=%E_MBF%:vb_qfactor=1.25:vb_qoffset=0.00:vi_qfactor=1.00:vi_qoffset=0.00:me_range=%E_RME%:preme=%E_PME%:dia=1:predia=1:mbd=%E_RDO%:precmp=0:cmp=0:subcmp=0:mv0:last_pred=0:dc=%E_DC%:psnr:aspect=%E_DAR%:inter_matrix=%E_INTER%:intra_matrix=%E_INTRA%:p_mask=%E_PMSK%:vqmin=%E_MQ%:lmin=%E_MQ%:vqblur=0.5:vrc_maxrate=%VBV_MBR%:vrc_buf_size=%VBV_MBS%:vrc_strategy=0 -of rawvideo -ffourcc MPG2

@REM @CLS

ECHO.---------------------------------------------------------------
ECHO.Last pass ...
ECHO.---------------------------------------------------------------
mencoder.exe -priority idle %E_SRC% -o %E_VID% -ovc lavc -ofps %E_FPS% -lavcopts vcodec=mpeg2video:vpass=2:sc_factor=1:vbitrate=%E_BR%:keyint=%E_MIK%:vqcomp=%E_VQ%:vmax_b_frames=%E_MBF%:bidir_refine=%E_BFR%:vb_qfactor=1.25:vb_qoffset=0.00:vi_qfactor=1.00:vi_qoffset=0.00:me_range=%E_RME%:preme=%E_PME%:dia=%E_DIA%:predia=%E_DIA%:mbd=%E_RDO%:precmp=%E_CMP%:cmp=%E_CMP%:subcmp=%E_CMP%:mv0:last_pred=3:trell:cbp:dc=%E_DC%:psnr:aspect=%E_DAR%:inter_matrix=%E_INTER%:intra_matrix=%E_INTRA%:p_mask=%E_PMSK%:vqmin=%E_MQ%:lmin=%E_MQ%:vqblur=0.5:vrc_maxrate=%VBV_MBR%:vrc_buf_size=%VBV_MBS%:vrc_strategy=0 -of rawvideo -ffourcc MPG2

@pause

bmcotton
30th October 2006, 17:02
My input source is an AVS script, and I'm not processing audio. I also did not allow TMPGENC to resize, so both videos are the same resolution I'm comparing.

Maybe I am using the wrong matrices. What should I be using for high bitrates?

Is there a stats reader that can read the divx2pass.log output from the first pass of mencoder?

My modified Sagittaire command line:

@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Rate control settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of bitrates
set E_BR=6500

@REM Set of max bitrates (use 9800 max for DVD compliant stream)
set VBV_MBR=9000

@REM Set of max buffer size (use 1835 max for DVD compliant stream)
set VBV_MBS=1835

@REM Set of ratio initial buffer occupency (0.9 is good value)
set VBV_IBO=0.9

@REM Set of first pass quantizer (2 is good value for high bitrate)
set E_IQ=2

@REM Set of min quantizer (1 is good value for high bitrate)
set E_MQ=2

@REM Set of quantizer variability [0.00;1.00] (0.75 is good value)
set E_VQ=0.75

@REM Set of inter quantizer masking [0.00;1.00] (0.00-0.50 is good interval)
set E_PMSK=0.25



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> GOP structure
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of max interval KFrame (use 15 for DVD PAL and 18 for DVD NTSC)
set E_MIK=18

@REM Set of max BFrames [0;4] (use 2 max for DVD compliant stream)
set E_MBF=2

@REM Set of Adaptative BFrames [0;2] (desactived is 0, fast is 1 and slow is 2)
set E_ABF=1

@REM Set of Slow Adaptative BFrames Refine [0;10] (0 is full search, higher is faster)
set E_SBF=2



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Motion estimation settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Set of ME range [0;9999] (use 128 for DVD compliant stream)
set E_RME=128

@REM Set of Rate Distortion Optimisation [0;2] (2 is the best)
set E_RDO=2

@REM Set of diamond size [-99;6] (negatives values are adaptative diamond)
set E_DIA=-6

@REM Set of comparison function for ME [0;2000] (0 is SAD, 1 is SSE, 2 is SADT, +256 for chroma ME)
set E_CMP=2

@REM Set of previous ME [0;2]
set E_PME=2

@REM Set of BFrame refinements [0;4] (Bframe Quality, 4 is best quality)
set E_BFR=4



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> VUI settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Display Aspect Ratio (4/3 or 16/9 for DVD compliant stream)
set E_DAR=4/3

@REM DC precision [8;10]
set E_DC=10

@REM Framerate (use 25 for PAL and 24000/1001 or 30000/1001 for NTSC)
set E_FPS=30000/1001

@REM Set intra matrix (use coef > 8 for DVD compliant stream with mencoder)
set E_INTRA=8,16,16,16,17,18,21,24,16,16,16,16,17,19,22,25,16,16,17,18,20,22,25,29,16,16,18,21,24,27,31,36,17,17,20,24,30,35,41,47,18,19,22,27,35,44,54,65,21,22,25,31,41,54,70,88,24,25,29,36,47,65,88,115

@REM Set inter matrix (use coef > 8 for DVD compliant stream with mencoder)
set E_INTER=20,20,20,20,21,22,23,24,20,20,20,20,21,22,24,25,20,20,20,21,22,24,26,28,20,20,21,22,24,27,29,32,21,21,22,24,28,31,34,39,22,22,24,27,31,37,42,49,23,24,26,29,34,42,52,60,24,25,28,32,39,49,60,80



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Mencoder CLI
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ECHO.---------------------------------------------------------------
ECHO.First pass ...
ECHO.---------------------------------------------------------------
%mencoder% -priority idle %E_SRC% -o NUL -nosound -ovc lavc -ofps %E_FPS% -lavcopts vcodec=mpeg2video:vpass=1:turbo:sc_factor=1:vqscale=%E_IQ%:keyint=%E_MIK%:vqcomp=%E_VQ%:vmax_b_frames=%E_MBF%:vb_strategy=%E_ABF%:brd_scale=%E_SBF%:vb_qfactor=1.25:vb_qoffset=0.00:vi_qfactor=1.00:vi_qoffset=0.00:me_range=%E_RME%:preme=%E_PME%:dia=1:predia=1:mbd=%E_RDO%:precmp=0:cmp=0:subcmp=0:mv0:last_pred=0:dc=%E_DC%:aspect=%E_DAR%:inter_matrix=%E_INTER%:intra_matrix=%E_INTRA%:p_mask=%E_PMSK%:vqmin=%E_MQ%:lmin=%E_MQ%:vqblur=0.5 -of rawvideo -ffourcc MPG2

@REM @CLS

ECHO.---------------------------------------------------------------
ECHO.Second pass ...
ECHO.---------------------------------------------------------------
%mencoder% -priority idle %E_SRC% -o %E_VID% -nosound -ovc lavc -ofps %E_FPS% -lavcopts vcodec=mpeg2video:vpass=2:sc_factor=1:vbitrate=%E_BR%:keyint=%E_MIK%:vqcomp=%E_VQ%:vmax_b_frames=%E_MBF%:vb_qfactor=1.25:vb_qoffset=0.00:vi_qfactor=1.00:vi_qoffset=0.00:me_range=%E_RME%:preme=%E_PME%:dia=1:predia=1:mbd=%E_RDO%:precmp=0:cmp=0:subcmp=0:mv0:last_pred=0:dc=%E_DC%:aspect=%E_DAR%:inter_matrix=%E_INTER%:intra_matrix=%E_INTRA%:p_mask=%E_PMSK%:vqmin=%E_MQ%:lmin=%E_MQ%:vqblur=0.5:vrc_maxrate=%VBV_MBR%:vrc_buf_size=%VBV_MBS%:vrc_strategy=0 -of rawvideo -ffourcc MPG2


I should also note that the output resolution in these cases are 448x304 because the AVS script I'm using wasn't originally intended to be put on DVD, however was a good video to test with. I guess I'll start a run at 720x480.

-Brett

bmcotton
30th October 2006, 18:10
Results of 720x480 encoding (same bitrate params):

Mencoder: 4644 kbit/s avg, 10173 kbit/s peak
TMPGENC: 6065 kbit/s avg, 7898 kbit/s peak

NOTE: I used two different versions of mencoder in this test becuase mencoder kept locking up (100% CPU usage, no progress) at frame 520 of the second pass for some reason. First pass version: MEncoder dev-SVN-r20525-3.2.3. Second pass version: MEncoder dev-CVS-060515-06:00-4.0.3.

I'm running 2 complete passes using the MEncoder dev-CVS-060515-06:00-4.0.3 version and will post results if different from above.

EDIT: The results were the same.

Pookie
9th November 2006, 09:51
Well organized batch file, Sagittaire. :)