7

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?)

2 Answers 2

9

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

4
  • 1
    The [in] and [out] is not needed in the first example.
    – slhck
    Commented Jun 7, 2013 at 9:41
  • 1
    Nice answer, but I recommend providing links to the official documentation for each filter mentioned: select and showinfo.
    – llogan
    Commented Jun 7, 2013 at 16:17
  • while this does work, I was hoping for a solution that would export all the frame types, but preserve the frames as they are (some being only the image area that needs to be re-drawn, and some being full redraws)
    – ndmweb
    Commented Jun 7, 2013 at 23:07
  • 2
    @ndmweb You cannot export a non-intra frame "as it is". There is no valid picture information—a P or B macroblock/frame, simply said, only stores the differences between the next picture. I'm afraid in order to do what you want you'd have to look into coding it with MATLAB or similar tools. At least I'm not aware of any existing solution.
    – slhck
    Commented Jun 8, 2013 at 8:15
4

P and B frames do not usually contain new image data for each of the areas that have changed. Rather, the picture is broken into macroblocks of different types. Some types of macroblocks contain new image data, but most compute the contents based on other reference pictures and motion vectors.

Not exactly what you were asking for, but this will use color to show you the type of each macroblock:

ffmpeg -debug vis_mb_type -i input.mp4 output.mp4

or

ffplay -debug vis_mb_type input.mp4

This will also show you the motion vectors:

ffplay -debug vis_mb_type -vismv 7 input.mp4

Refer to the link for more information about the colors of each MB:

Debug Macroblocks and Motionsvectors FFMpeg documentation

1
  • Nice info to have, if only to understand that an entire frame does not only have to consist of intra-coded macroblocks.
    – slhck
    Commented Jun 8, 2013 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .