[FFmpeg-devel] H264 keyframe detection not working

Ivan Schreter schreter
Sat Feb 7 20:04:02 CET 2009

Hi Lee,

Lee Essen wrote:
> Hi,
> I've just been working with some BBC HD content and have noticed that  
> the keyframe detection isn't working.
Yes. I noticed it as well and made a series of patches, which address 
the issue. See my post "Fix MPEG-TS seek" (today 01:50 CET) and 
"H.264/AVCHD interlaced fixes" (today 13:45 CET). I'm waiting for review 
of those patches. Your content should work with them fine, though. 
Please let me know, if it works and if not, please upload a sample (or 
send a link).

> The code seems to assume that you'll get a NAL_IDR_SLICE, but this  
> media doesn't contain any!  I get slice types 9, 7, 8, 6, 1 on  
> keyframe sequences then just 9, 6, 1 for everything else. So a  
> keyframe is never detected despite them cleary being there if you  
> examine the slice header for the slice type.
In contrast to MPEG-2, H.264 has so-called "recovery points", which tell 
you, how many frames to decode from this point until the result is 
acceptable. My patches decodes SEI recovery point message and marks 
frames having this message as key frames. Although recovery count is not 
passed to higher layers yet, this should be no problem, since I didn't 
see any file yet having recovery count > 0.

> I've had a quick look at the standard and it does seem to imply there  
> should be an idr slice, but it's just not there in the media!
Yes, there is one usually at the very beginning. But it is in principle 
not necessary - you could start decoding a live stream somewhere in the 
middle and use recovery point to synchronize the decoder.



More information about the ffmpeg-devel mailing list