FFMPEG extract intra-frames I,P,B frames

ffmpegvideo

Is there a way to extract the intra-frames and preserve them as-is from FFMPEG or similar program? I know you can extract frames to a sequence of JPEG images using -f image2. But those are full images of each of the frames. I would like to only export the image of the change in motion, so I would have the P and B frames only showing the change in motion excluding or masking the non-changed area of the images.

Is this possible?

The basic frame export command I'm using. This gives me full framed images of each frame, at the specified FPS.

ffmpeg -i input.mp4 -r 12 -an -b 1024k -y -f image2 frame%4d.jpg

I'm hoping to export the frames so that I have a folder of frames where the first frame would be a full image, the next frame would only be the image data where the image needs to be redrawn. Exposing the temporal redundancy between the two frames (isn't this what I,P,B frames do?)

Best Answer

To extract a certin type of frame use the select filter:

select=eq(pict_type\,<x>)

where <x> is one of the following: pict_type (video only) the type of the filtered frame, can assume one of the following values: I, P, B, S, SI, SP, BI

So for example:

ffmpeg -i <inputfile> -vf '[in]select=eq(pict_type\,B)[out]' b.frames.mp4

To understand more about the output, add the showinfo filter:

ffmpeg -i <inputfile> -vf '[in]select=eq(pict_type\,B),showinfo[out]' b.frames.mp4

Related Question