Registered User
Join Date: Feb 2009
Posts: 16
|
libavcodec 54 vs. 57: rate controller regression?
Preamble
A few years ago i encoded sequence from Elephant's Dream (see source) with different MPEG-2 encoding libraries. I downloaded all pngs, and then made AVI with lossless FFV1 (bgr0 pixel format). It helped to reduce size from 21 to 12,4 GiB. Avisynth script:
Code:
InputRGB = ImageReader("%05d.png", \
start=00001, \
end=15691, \
fps=24, pixel_type="rgb24").\
AssumeFPS(24000, 1001)
return InputRGB ++ \
InputRGB.Trim(15690, 15690)
Then i converted film 1080p RGB to PAL YV12 and encoded to AVI with lossless FFVH. Avisynth script:
Code:
InputVideo_RGB = AVISource("ed-film-1080p-ffv1.avi", \
audio=false, \
pixel_type="RGB32", \
fourCC="FFV1")
InputVideo_YUV = InputVideo_RGB.\
BilinearResize(720, 576).\
ConvertToYV12(matrix="Rec601", interlaced=false).\
AssumeFPS(25, 1)
return InputVideo_YUV
So, i passed data to MPEG-encoders through Avisynth (see script ed-pal.avs):
Code:
original = AVISource("ed-pal-i420-ffvh.avi", \
audio=false, \
pixel_type="YV12", \
fourCC="FFVH")
return original
Command for the first pass:
Code:
intra="8,16,19,22,26,27,29,34,\
16,16,22,24,27,29,34,37,\
19,22,26,27,29,34,34,38,\
22,22,26,27,29,34,37,40,\
22,26,27,29,32,35,40,48,\
26,27,29,32,35,40,48,58,\
26,27,29,34,38,46,56,69,\
27,29,35,38,46,56,69,83"
inter="16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16,\
16,16,16,16,16,16,16,16"
intra=$(echo $intra | sed -e "s/[^0-9,]//g;")
inter=$(echo $inter | sed -e "s/[^0-9,]//g;")
wine avs2yuv -raw ed-pal.avs - | \
mencoder -demuxer rawvideo -rawvideo fps=25:pal=yes:i420=yes \
-of mpeg=yes -mpegopts format=dvd:tsaf=yes -ofps 25 -noskip -ovc lavc=yes \
-lavcopts vcodec=mpeg2video:vstrict=1 \
-lavcopts vbitrate=4800:vrc_maxrate=8700:vpass=1:vqblur=0.5:vb_strategy=2 \
-lavcopts vqmin=1:vqmax=31:vqdiff=3:dc=10 \
-lavcopts vb_qfactor=1.25:vi_qfactor=0.8:vb_qoffset=1.25:vi_qoffset=0 \
-lavcopts vlelim=0:vcelim=0 \
-lavcopts lmin=0.5:lmax=20:mblmin=0.5:mblmax=20:vqsquish=1 \
-lavcopts vrc_minrate=0:vrc_strategy=0:vrc_buf_size=1835 \
-lavcopts vqcomp=0.5 \
-lavcopts keyint=15:cgop=yes \
-lavcopts vmax_b_frames=2 \
-lavcopts sc_threshold=1000000000 \
-lavcopts vme=4:me_range=0:preme=2:bidir_refine=4 \
-lavcopts predia=-1:dia=-1 \
-lavcopts mbd=0:mbcmp=6:precmp=6:cmp=6:subcmp=6:skipcmp=6 \
-lavcopts mv0_threshold=256 \
-lavcopts subq=8 \
-lavcopts intra_matrix=${intra} \
-lavcopts inter_matrix=${inter} \
-lavcopts nr=0 \
-lavcopts aspect=16/9:threads=4 \
-passlogfile pass_ed-pal_menc50mpeg-nlqs.log \
-o /dev/null -
and the second pass:
Code:
wine avs2yuv -raw ed-pal.avs - | \
mencoder -demuxer rawvideo -rawvideo fps=25:pal=yes:i420=yes \
-of mpeg=yes -mpegopts format=dvd:tsaf=yes -ofps 25 -noskip -ovc lavc=yes \
-lavcopts vcodec=mpeg2video:vstrict=1 \
-lavcopts vbitrate=4800:vrc_maxrate=8700:vpass=2:vqblur=1.0 \
-lavcopts vqmin=1:vqmax=31:vqdiff=3:dc=10 \
-lavcopts vb_qfactor=1.25:vi_qfactor=0.8:vb_qoffset=1.25:vi_qoffset=0 \
-lavcopts vlelim=0:vcelim=0 \
-lavcopts lmin=0.5:lmax=20:mblmin=0.5:mblmax=20:vqsquish=1 \
-lavcopts vrc_minrate=0:vrc_strategy=0:vrc_buf_size=1835 \
-lavcopts vqcomp=0.5 \
-lavcopts keyint=15:cgop=yes \
-lavcopts vmax_b_frames=2 \
-lavcopts sc_threshold=1000000000 \
-lavcopts vme=4:me_range=0:preme=2:bidir_refine=4 \
-lavcopts predia=-1:dia=-1 \
-lavcopts mbd=0:mbcmp=6:precmp=6:cmp=6:subcmp=6:skipcmp=6 \
-lavcopts mv0_threshold=256 \
-lavcopts subq=8 \
-lavcopts intra_matrix=${intra} \
-lavcopts inter_matrix=${inter} \
-lavcopts nr=0 \
-lavcopts aspect=16/9:threads=4 \
-passlogfile pass_ed-pal_menc50mpeg-nlqs.log \
-o ed-pal_menc50mpeg-nlqs.vob -
I got ed-pal_menc50mpeg-nlqs.vob with very nice picture quality (compared to CCE and HCenc) and averange bitrate 4797 kbps.
The matter
Today i have tried to reproduce results with actual versions of libavcodec (encoders: ffmpeg 2.8.7, mencoder 1.1.1 and mencoder 1.3.0). For mencoder 1.1.1 command was the same, for others see commands bellow.
For mencoder 1.3.0:
Code:
wine avs2yuv -raw ed-pal.avs - | \
mencoder -demuxer rawvideo -rawvideo fps=25:pal=yes:i420=yes \
-of mpeg=yes -mpegopts format=dvd:tsaf=yes -ofps 25 -noskip -ovc lavc=yes \
-lavcopts vcodec=mpeg2video:vstrict=1 \
-lavcopts vbitrate=4800:vrc_maxrate=8700:vpass=1:vqblur=0.5:vb_strategy=2 \
-lavcopts vqmin=1:vqmax=31:vqdiff=3:dc=10 \
-lavcopts vb_qfactor=1.25:vi_qfactor=0.8:vb_qoffset=1.25:vi_qoffset=0 \
-lavcopts o=luma_elim_threshold=0:o=chroma_elim_threshold=0 \
-lavcopts lmin=0.5:lmax=31:mblmin=0.5:mblmax=31 \
-lavcopts vrc_minrate=0:vrc_strategy=0:vrc_buf_size=1835 \
-lavcopts vqcomp=0.5 \
-lavcopts keyint=15:cgop=yes \
-lavcopts vmax_b_frames=2 \
-lavcopts sc_threshold=1000000000 \
-lavcopts vme=4:me_range=0:preme=2:bidir_refine=4 \
-lavcopts predia=-1:dia=-1 \
-lavcopts mbd=0:mbcmp=6:precmp=6:cmp=6:subcmp=6:skipcmp=6 \
-lavcopts mv0_threshold=256 \
-lavcopts subq=8 \
-lavcopts intra_matrix=${intra} \
-lavcopts inter_matrix=${inter} \
-lavcopts aspect=16/9:threads=4 \
-passlogfile pass_ed-pal_menc50mpeg-nlqs.log \
-msglevel global=0 \
-o /dev/null -
wine avs2yuv -raw ed-pal.avs - | \
mencoder -demuxer rawvideo -rawvideo fps=25:pal=yes:i420=yes \
-of mpeg=yes -mpegopts format=dvd:tsaf=yes -ofps 25 -noskip -ovc lavc=yes \
-lavcopts vcodec=mpeg2video:vstrict=1 \
-lavcopts vbitrate=4800:vrc_maxrate=8700:vpass=2:vqblur=1.0 \
-lavcopts vqmin=1:vqmax=31:vqdiff=3:dc=10 \
-lavcopts vb_qfactor=1.25:vi_qfactor=0.8:vb_qoffset=1.25:vi_qoffset=0 \
-lavcopts o=luma_elim_threshold=0:o=chroma_elim_threshold=0 \
-lavcopts lmin=0.5:lmax=31:mblmin=0.5:mblmax=31 \
-lavcopts vrc_minrate=0:vrc_strategy=0:vrc_buf_size=1835 \
-lavcopts vqcomp=0.5 \
-lavcopts keyint=15:cgop=yes \
-lavcopts vmax_b_frames=2 \
-lavcopts sc_threshold=1000000000 \
-lavcopts vme=4:me_range=0:preme=2:bidir_refine=4 \
-lavcopts predia=-1:dia=-1 \
-lavcopts mbd=0:mbcmp=6:precmp=6:cmp=6:subcmp=6:skipcmp=6 \
-lavcopts mv0_threshold=256 \
-lavcopts subq=8 \
-lavcopts intra_matrix=${intra} \
-lavcopts inter_matrix=${inter} \
-lavcopts nr=0 \
-lavcopts aspect=16/9:threads=4 \
-passlogfile pass_ed-pal_menc50mpeg-nlqs.log \
-msglevel global=0 \
-o ed-pal_men50mpeg-nlqs-lavc57.vob -
For ffmpeg 2.8.7:
Code:
ffmpeg -i ed-pal-i420-ffvh.avi \
-vcodec mpeg2video -strict strict \
-pass 1 \
-b:v 4800k -maxrate 8700k -minrate 0 -bufsize 1835k -rc_strategy 0 \
-g 15 -bf 2 -b_strategy 2 -flags cgop \
-qcomp 0.1 -qblur 0.5 \
-qmin 1 -qmax 28 -qdiff 3 -dc 10 -non_linear_quant 1 \
-lmin 0 -lmax 767 -mblmin 1 -mblmax 31 \
-i_qfactor 0.8 -i_qoffset 0 -b_qfactor 1.25 -b_qoffset 1.25 -ibias 96 -pbias 0 \
-luma_elim_threshold 0 -chroma_elim_threshold 0 \
-sc_threshold 1000000000 \
-me_method epzs -me_range 0 -dia_size -1 -pre_dia_size -1 -preme 2 -bidir_refine 4 -mv0_threshold 256 \
-mbd simple -cmp rd -subcmp rd -mbcmp rd -precmp rd -skipcmp rd -subq 8 -brd_scale 0 \
-intra_matrix ${intra} \
-inter_matrix ${inter} \
-nr 0 \
-aspect 16/9 -threads 4 \
-f dvd \
/dev/null -y
ffmpeg -i ed-pal-i420-ffvh.avi \
-vcodec mpeg2video -strict strict \
-pass 2 \
-b:v 4800k -maxrate 8700k -minrate 0 -bufsize 1835k -rc_strategy 0 \
-g 15 -bf 2 -flags cgop \
-qcomp 0.1 -qblur 1.0 \
-qmin 1 -qmax 28 -qdiff 3 -dc 10 -non_linear_quant 1 \
-lmin 0 -lmax 767 -mblmin 1 -mblmax 31 \
-i_qfactor 0.8 -i_qoffset 0 -b_qfactor 1.25 -b_qoffset 1.25 -ibias 96 -pbias 0 \
-luma_elim_threshold 0 -chroma_elim_threshold 0 \
-sc_threshold 1000000000 \
-me_method epzs -me_range 0 -dia_size -1 -pre_dia_size -1 -preme 2 -bidir_refine 4 -mv0_threshold 256 \
-mbd simple -cmp rd -subcmp rd -mbcmp rd -precmp rd -skipcmp rd -subq 8 -brd_scale 0 \
-intra_matrix ${intra} \
-inter_matrix ${inter} \
-nr 0 \
-aspect 16/9 -threads 4 \
-f dvd \
ed-pal_men50mpeg-nlqs-lavc56.vob -y
The results
Code:
encoder library version max min avg. ssim 0.24
bitrate, bitrate, bitrate,
kbps kbps kbps
================================================================================
cce sp3 cceserver2 1.0.1.4 9434 159 4779 92,65
hcenc hcenc 0.25 9181 118 4788 92,55
mencoder libavcodec 52.72.2 9048 118 4797 92,97
mencoder libavcodec 54.23.100 9390 118 4796 92,98
ffmpeg libavcodec 56.60.100 9018 167 4792 92,67
mencoder libavcodec 57.25.100 9472 167 3516 91,83
As you can see, rate controller of libavcodec 57.25.100 lowers bitrate and accepts too high quantizers, thus encoded sequence looks blocky; the result of encoding with libavcodec 56.60.100 looks ugly too (so i had to reduce qmax to 28).
The question
How to make it good again? How to make libavcodec 56/57 to reduce quantizers for low motion scenes? Which keys for ffmpeg/mencoder?
Any ideas?
Last edited by ar; 5th June 2016 at 10:19.
Reason: fixed command for ffmpeg (-lmax 767) and results.
|