Ask Your Question

Revision history [back]

Extracting Keyframes (I-frames) from a Video

First, a definition:

By keyframes, I mean frames in which the encoder has written all pixels instead of just the diff pixels. For example, in Adobe Premiere Pro you can specify the maximum number of frames between "Key Frames" in the export UI here:

image description

Further research, here and here, leads me to believe that these are called "I Frames" or "I-Frames".

I have a task that involves detecting these frames in videos. The range of codecs that must be supported is not specified, so if we can support a "typical" .mp4 file, it should be good enough.

In case any additional clarification is needed, it has been suggested that we can use ffprobe to find the indices of these keyframes like so:

ffprobe -select_streams v -i x.mp4 -print_format json -show_entries frame=pict_type,coded_picture_number

If it is possible, and relatively similar in terms of efficiency, I would like to do this with OpenCV instead so that we don't need to independent executables to solve the problem.

In full disclosure, this is part of a job application 'take home' challenge. I believe posting this question is a valid example of how I might approach that problem "on the job" and I will link to this question in my submission.

The Question

Can OpenCV be used to detect I-Frames? If so, what functions or parameters should I be looking at? Also, if so, would we expect OpenCV to be as efficient at this as ffprobe?

Extracting Keyframes (I-frames) from a Video

First, a definition:

By keyframes, I mean frames in which the encoder has written all pixels instead of just the diff pixels. For example, in Adobe Premiere Pro you can specify the maximum number of frames between "Key Frames" in the export UI here:

image description

Further research, here and here, leads me to believe that these are called "I Frames" or "I-Frames".

I have a task that involves detecting these frames in videos. The range of codecs that must be supported is not specified, so if we can support a "typical" .mp4 file, it should be good enough.

In case any additional clarification is needed, it has been suggested that we can use ffprobe to find the indices of these keyframes like so:

ffprobe -select_streams v -i x.mp4 -print_format json -show_entries frame=pict_type,coded_picture_number

If it is possible, and relatively similar in terms of efficiency, I would like to do this with OpenCV instead so that we don't need to independent executables to solve the problem.

In full disclosure, this is part of a job application 'take home' challenge. I believe posting this question is a valid example of how I might approach that problem "on the job" and I will link to this question in my submission.

The Question

Can OpenCV be used to detect I-Frames? If so, what functions or parameters should I be looking at? Also, if so, would we expect OpenCV to be as efficient at this as ffprobe?