Log in

View Full Version : Why do I get an extra frame in my Xvid encode?


kypec
3rd April 2007, 10:23
First, let me describe which tools have been used to get my results:

Frameserver = Avisynth 2.5.7
MPEG2 Indexer = DGMPGDec 1.4.9 beta 17
Encoder = xvid.cvs.head.MTK.2007.03.10.7z with xvid_encraw.exe dated Feb 3 2007
Viewer = AvsP 1.3.7
Source material = PAL DVD Frasier Season 1 Episode 1

I have processed the input VOB file and feeded the resulting d2v project file via PALvideo.avs script:
LoadPlugin("C:\Program Files\AVTools\DGMPGDec\DGDecode.dll")
MPEG2Source("E:\footage\Frasier\VTS_01_1.d2v")
Trim(0,1499)
TDeint(mode=0)
Spline36Resize(640,480)
When I preview this script in AvsP then the frame #24 (1500 frames in total) looks like this
http://img144.imageshack.us/img144/5430/original24iu2.th.png (http://img144.imageshack.us/my.php?image=original24iu2.png)

Then I ran my batch command first_pass.bat
"C:\Program Files\AVTools\XviD_Encraw\xvid_encraw.exe" -i PALvideo.avs -type 2 -avi video1.avi -max_bframes 2 -bquant_ratio 150 -bquant_offset 100 -framerate 25.0 -bitrate 2048 -max_key_interval 250 -pass1 pass1.xvid -vhqmode 3 -bvhq -qmatrix "C:\Program Files\AVTools\matrices\eqm_v3hr.xcm" -nopacked -par 1 -progress 25 -stats

Here comes the report on encoding process:
xvid_encraw - raw mpeg4 bitstream encoder written by Christoph Lampert 2002-2003

Trying to retrieve width and height from input header
xvid [info]: Avisynth detected
xvid [info]: Input colorspace is YV12
xvid [info]: Input is 640 x 480, 25.000fps (25/1), starting from frame 0
xvid [info]: Number of frames to encode: 1500, Bitrate = 2048kbps
xvid [info]: xvidcore build version: xvid-1.2.0-dev
xvid [info]: Bitstream version: 1.2.-127
xvid [info]: Detected CPU flags: ASM MMX MMXEXT SSE SSE2 TSC
xvid [info]: Detected cpus = 2, threads requested = 2, threads in use = 2
1501 frames(100%) encoded, 11.67 fps, Average Bitrate = 2252kbps

Tot: enctime(ms) =128671.00, length(bytes) = 16907460
Avg: enctime(ms) = 85.67, fps = 11.67, length(bytes) = 11256, psnr y = 44.31, psnr u = 44.94, psnr v = 46.14
I frames: 11 frames, size = 71694/ 788641, quants = 2 / 2.00 / 2
P frames: 505 frames, size = 25051/ 12650772, quants = 2 / 2.00 / 2
B frames: 978 frames, size = 3546/ 3467999, quants = 4 / 4.00 / 4
N frames: 6 frames, size = 8/ 48

Now, can anyone explain to me why is there being reported one more frame encoded than the source contains? 1501 versus 1500 :confused:
Also when I examine the resulting AVI file in AvsP through the simple script:DirectShowSource("E:\footage\Frasier\video1.avi")
and move the pointer to frame #24 it looks like this
http://img84.imageshack.us/img84/350/xvid24mb8.th.png (http://img84.imageshack.us/my.php?image=xvid24mb8.png)
which is precisely one frame before the original frame. In general one can observe that the whole resulting AVI clip is shifted one frame behind the original and the very last frame is missing from it altogether because it really contains only 1500 frames (which is good IMO) :mad:

squid_80
3rd April 2007, 12:12
The "1501 frames(100%) encoded" is a bug. Add up the total number of frames from the other stats (I+P+B+N) and you get 1500. (Actually it's not really a bug, just an inaccuracy).
The reason the input vs. output frames don't line up is because you're using -nopacked with an avi file which causes problems when seeking.

Edit: You're also using directshowsource to open an avi file in avisynth. That's what avisource is for.

kypec
3rd April 2007, 14:19
@squid_80
:thanks: for your explanation. OK, I'll try without -nopacked option and see whether the output's frame numbering will match the input. I will use AVISource() as well, just didn't notice there is something like that before :stupid:
Where from comes that "inaccuracy" in frames counting? I thought the frame counts are ALWAYS integers, therefore no floating math should be involved.
BTW is it normal that I achieve only such low encoding speed?
I mean less than 12fps with that simple script at Pentium4 @ 2.4GHz + 512M RAM seems kinda slow to me :confused:

kypec
10th April 2007, 09:11
Well, I have tested with omitted -nopacked option and the frames appear to be in correct order and sync'ed with the source.
My standalone PIONEER DV-2850 seems to play the resulting AVI file (packed bitstream, 2 B-VOPS, custom quant. matrix) just fine so I'm a lucky guy now :cool:

Terranigma
10th April 2007, 19:05
Well, I have tested with omitted -nopacked option and the frames appear to be in correct order and sync'ed with the source.
My standalone PIONEER DV-2850 seems to play the resulting AVI file (packed bitstream, 2 B-VOPS, custom quant. matrix) just fine so I'm a lucky guy now :cool:

From my experience, I found that b-frames were the no.1 factor affecting perfect audio sync (Using mpeg-1 - h.264). It seems, for me, that perfect synchronization starts at 3-bframes. Anything less needs to be delayed by roughly 29 seconds. Maybe i'm just spewing out stuff here, so anybody feel free to correct me.