Log in

View Full Version : Scene Change Detection and Keyframe Insertion


Dali Lama
29th October 2002, 00:51
Hello,

While taking the advice of the wise manono, concerning lowering Divx 5's keyframe threshold to better detect scene changes. I was wondering if the same could be done with Xvid? I remember -h saying that Xvid will only use I-frames when its smaller in size than P-frames.

However, what about the scene changes? Is it a myth that I-frames are needed at every scene change?

I was thinking about using aviutl's scene change filter, which finds scene changes and forces the MPEG-4 codec to use that as keyframes. This might turn out to be a lot of uneeded work, though.

Manono and another fellow at the divx forums, Eckard, suggested setting max keyframes to 600-900 to prevent the codec from inserting unneeded keyframes. Makes sense, but what about the MPEG-4 spec? -h has said that anything over 132 max is a violation.

Sorry I have so many questions and few answers. But I can say that lowering the max keyframe interval to anything below 10s is asking for trouble when it comes to compressability. Also, I remember TMPG having a pretty good scene change detection filter that allowed you to see the frames detected as keyframes and adjust accordingly. I actually did that for a trailer once and noticed marked improvement at the places the regular codec did not pick up. I was encoding to MPEG1/2 though.

Please share your thoughts and experiences on the issue,

Dali

P.S. Right now I am using max keyframe interval of 600 and min of 5 and Koepi's regular settings of consecutive I-frame reduction.

Koepi
29th October 2002, 10:27
You're mixing up some things, Dali.

DivX and XviD are 2 completely different codecs. You can't compare them on this level as they work and behave differently there.

If you change min/max iframe distance in xvid, you'll change _exactly_ only that. XviD's iframe decision is quite stable and it inserts iframes when over 50% of the MBs of an image are kblocks.
You won't get a "better" iframe decision by changing those values (I don't know much about divx5 but if it works that way there you should report it as bug).
A distance of 132 frames for kblocks has nothing to do with iframes! You _can_ force this behaviour that way, but look into your debugview output during first pass: all the kblocks there are in pframes already, so you shouldn't need to set iframe max distance of 132 (and we weren't sure that this is required by the latest mpeg4 docs anymore).

And for iframes at scene changes, well, they _should_ be there as a pframe with many kblocks seems to look worse than an iframe, if the quantization levels differ (you need to look at the quantization matrix to understand why).

I hope this helps you out of your confusion.

Regards
Koepi

sysKin
29th October 2002, 12:23
Dali Lama, Koepi is right. Do you really think that xvid puts i-frames wrong? If you're really really sure, convince us and we'll check it ourselves, possibly fixing some thresholds.
However, I believe it's not the case. Noone seemed to notice such behaviour before...
Originally posted by Dali Lama
However, what about the scene changes? Is it a myth that I-frames are needed at every scene change?

It's not a myth. Bitstream really needs I-frames from time to time, and scene change is the only place where you don't waste bits to make a scene change. Actually, codec usually not only doesn't waste the bits, but saves them there.

Dali Lama
29th October 2002, 15:40
First, thank you Koepi and Syskin.

Yes, I am more clear now of how xvid inserts keyframes. I was wondering what kblocks were in debugview. :)

Regarding Syskins's comment if I found Xvid not inserted keyframes at scene changes. Well, I ran the video through TMPG's automatic scene change detection filter, and Xvid was surprisingly accurate in its keyframe placement at scene changes only. However, there were times when Xvid missed scene changes and did not insert keyframes.

Note: I am not saying TMPG's scene change detection filter is better than Xvid. Actually its much worse, but I used that filter to go frame by frame looking for scene changes and comparing it with debugview's log.

I found eight scene changes that were not picked up by xvid in the first 5000 frames of the source.

I don't know what this means,

Dali

HarryM
29th October 2002, 16:02
Originally posted by Dali Lama
First, thank you Koepi and Syskin.

Yes, I am more clear now of how xvid inserts keyframes. I was wondering what kblocks were in debugview. :)

Regarding Syskins's comment if I found Xvid not inserted keyframes at scene changes. Well, I ran the video through TMPG's automatic scene change detection filter, and Xvid was surprisingly accurate in its keyframe placement at scene changes only. However, there were times when Xvid missed scene changes and did not insert keyframes.

Note: I am not saying TMPG's scene change detection filter is better than Xvid. Actually its much worse, but I used that filter to go frame by frame looking for scene changes and comparing it with debugview's log.

I found eight scene changes that were not picked up by xvid in the first 5000 frames of the source.

I don't know what this means,

Dali



I don't know much about XviD's SCD.
But I think- When at least 50% of frame not newly defined (new macroblocks)- XviD don't use keyframe, only b-frame.
But exist many, many regular scene changes (mainly, e.g. majority of frame is night=static black background), where I CAN INSERT KEYFRAME (I want, I want!), but XviD don't... :(

I often observe bitrate window at encoding process in vdub and I can easily identify these 'hidden' scene changes (one-frame-peak of bitrate)...
XviD don't see this?