Log in

View Full Version : libavcodec's mpeg-2 encoder (mencoder / ffmpeg)


ar
3rd March 2011, 16:39
Part 1. Multiplexing problem
I'm trying to encode DVD-compliant sources to output them to dvdauthor. AFAIK, i need to make mpeg-ts stream with NAV-sectors and empty VOBU-sectors. For example, one of the following lines would do what i want:
mplex -f 8 -o test_mux_mplex.vob test.m2v test.ac3
mencoder -noskip -mc 0 -oac copy -ovc copy\
-of mpeg -mpegopts format=dvd:tsaf:vwidth=720:vheight=576:vaspect=4/3:vframerate=25\
-audiofile test.ac3 test.m2v -o test_mux_mencoder.vob
And i noticed that either mplex or mencoder dropped some frames during multiplexing. I meen input mpeg-es (m2v) file consists of few more frames then output VOB.

Next wrote this script:
Video_Blank = BlankClip(length=1500,\
width=720,\
height=576,\
pixel_type="YV12",\
fps=25,\
audio_rate=48000,\
stereo=true,\
sixteen_bit=true,\
color=$000000).\
AssumeFrameBased().\
ShowFrameNumber(x=32,\
y=64,\
font="DejaVu Sans",\
size=32,\
text_color=$E0E0E0,\
halo_color=$404040).\
ColorYUV(levels="PC->TV")

return Video_Blank
Script produces progressive PAL clip with 1500 black frames with frame numbers from 0 to 1499 printed on each frame. Then i encoded video to mpeg-2 and ac3:
wine wavi test1500.avs - /R |\
ffmpeg -ar 48000 -ac 2 -acodec pcm_s16le -f s16le -i pipe:0\
-acodec ac3 -ab 192k -f ac3 test.ac3 &&\
wine avs2yuv -raw test1500.avs - | mencoder -profile mpeg2-vhq-pal-p-i420-bitrate-pass1\
-oac copy -lavcopts vbitrate=9000:aspect=4/3:threads=4\
-audiofile test.ac3 -o test.vob -
Clip in test.vob have 1500 frames and audio stream, also it can be passed to dvdautor.
Even if i tried to demux video, mpeg-es (m2v) still has 1500 frames.
mpeg2desc -v 0 -o test.m2v < test.vob
But when i multiplexing m2v and ac3 with mplex or mencoder:
mplex -f 8 -o test_out_mplex.vob test.m2v test.ac3 &&\
mencoder -oac copy -ovc copy -of mpeg\
-mpegopts format=dvd:tsaf:vwidth=720:vheight=576:vaspect=4/3:vframerate=25\
-noskip -mc 0 -audiofile test.ac3 test.vob\
-o test_mux_mencoder.vob
both clips in test_mux_mencoder.vob and test_out_mplex.vob have 1499 frames.
Then i made index for avisynth of two files. Both muxers drops frame with stamp «1498» (the last frame should have stamp «1499»).
If i run this sequence one more time then mplex drops one more frame:
mpeg2desc -v 0 -o test_again.m2v < test_out_mplex.vob &&\
mplex -f 8 -o test_again.vob test_again.m2v test.ac3
Clip in test_again.vob have only 1498 frames (without frame stamped with «1499»).

Why this occurs?

ar
21st March 2011, 18:02
Part 2. MPEG-2 encoding quality with MEncoder (libavcodec).
By default it's trash. But if i hit with a hammer -lavcopts somewhere, quality becomes very nice. For example, SSIM test on «Elephant's Dream» with PAL sequense at averange bitrate 5Mbps (peak 8.7Mbps):

CCE 2.70` (QMat=CCE3-CG2, QS=NL, AQMat=AAQM, GOP=auto, KFI=AFSCD, ME=SME, RC=VMPE, RC-M=VBR-2P): 92.65093592;
CCE 2.70` (QMat=HC, QS=NL, AQMat=none, GOP=auto, KFI=AFSCD, ME=SME, RC=VMPE, RC-M=VBR-2P): 92.43695561;
mencoder (QMat=HC, QS=NL, AQMat=none, GOP=auto, KFI=auto, A-ME=RDO, ARC=RDO, ME=EPZS-UMH, RC-M=VBR-2P, RC=Xvid): 92.79327650;
mencoder (QMat=CCE3-CG2, QS=NL, AQMat=none, GOP=auto, KFI=auto, A-ME=RDO, ARC=RDO, ME=EPZS-UMH, RC-M=VBR-2P, RC=lavc): 92.94999231;
hc (QMat=HC, QS=NL, GOP=auto, KFI=auto, A-ME=HC-best, ME=HC, RC-M=VBR-2P, RC=HC): 92.54866203;
mpeg2enc (QMat=HC, QS=L, GOP=auto, KFI=auto, ME=EPZS, RC-M=VBR-1P, RC=M2E-1P): 89.04360011.
BTW, this is very first results.

Also, my profile from mencoder.conf:12143

kieranrk
22nd March 2011, 08:28
Are you sure the GOP lengths are the same.

ar
22nd March 2011, 10:37
Are you sure the GOP lengths are the same.
What exactly do you mean? You're asking about frame drops or about CCE-SP3 vs. libavcodec?

kieranrk
24th March 2011, 14:27
What exactly do you mean? You're asking about frame drops or about CCE-SP3 vs. libavcodec?

I'm asking if the GOP lengths are the same for each encoder...i.e the keyframe interval.

ar
24th March 2011, 16:01
GOP lengths are the same for each encoder...
Both cases i set encoder's MAX_KEYINT option to 15, because i want to get DVD-compliant MPEG-2 stream. Each encoder have scene change detection feature, so GOP size never exceeds 15 frames. Also, i post configuration file.