videovideo-streamingkeyframe

How to find keyframe in MPEG-2 stream, packed in MPEG-TS


I've written MPEG-TS demuxer. It unpacks transport stream to PES packets. Now I want to drop all frames till I meet keyframe.

How can I do it? Should I find for Sequence block in each PES frame?


Solution

  • You should be able to look for a set Random Access Indicator bit in the MPEG-TS adaptation field. If you are dealing with a transport stream that does not use RAI bits, you'll need to rely on information in the contained elementary stream. For example, if you are processing an H.264 stream, you'll need to look for IDR slice NAL units (type 5).