VideoHelp Forum




+ Reply to Thread
Results 1 to 4 of 4
  1. Following responses to an earlier post ('Extract frames as uncompressed image files') I used ffmpeg to extract ALL frames from a short video as images in an uncompressed (.bmp) format.

    I now have a long video from which I'd like to extract just a SHORT sequence of frames in .bmp format.

    A tutorial at https://ottverse.com/trim-cut-video-using-start-endtime-reencoding-ffmpeg/ gives the following code to extract a short sequence from a long video:

    ffmpeg -ss 00:00:03 -i inputVideo.mp4 -to 00:00:08 -c:v copy -c:a copy trim_ipseek_copy.mp4

    The tutor says this is unlikely to make a frame-accurate cut because ffmpeg has to start and end on the nearest i-frame to avoid re-encoding video data.

    I want to extract frames in .bmp format, so I thought a solution to that problem would be to extract images from the nearest i-frame BEFORE the desired start-point, and up to the nearest i-frame AFTER the desired end-point. Any unwanted images this produced could then be discarded.

    I'm new to ffmpeg, and a search for a way to do this has found nothing so far. Does anyone with more experience know if ffmpeg can be used to extract all frames from the nearest i-frame before the required start point to the nearest i-frame after the required end-point?
    Quote Quote  
  2. Just use -ss and -to to extract the exact portion as BMP files directly from the long video. There are no i-frame requirements when doing so. Put both -ss and -to (starting and ending times of the segment you want) after importing the source:

    Code:
    ffmpeg -i "source.mp4" -ss 17:52.238 -to 17:52.446 pic%05d.bmp
    Last edited by jagabo; 8th Dec 2021 at 17:24.
    Quote Quote  
  3. I'm sill struggling with this.

    I'd like to extract frames 9600 to 10226 (626 frames) from a video.
    There's a frame rate of 25 fps, so I calculated the start time would be 6:24.0 and the end time would be 6:49.1. (I'm not very good with numbers).

    I modified the line jagabo kindly provided so that it read:

    ffmpeg -i "video_file.mts" -ss 6:24.0 -to 6:49.1 frame_no_%05d.bmp

    This produced 163 bmp files. I was expecting 623. (i.e from frame 9600 to 10226 inclusive)

    Furthermore, some of the images were distorted, with horizontal lines running through them.

    I've battled with this for some time, so any help would be much appreciated....
    Quote Quote  
  4. Use -vf trim
    https://ffmpeg.org/ffmpeg-filters.html#trim

    If they are "HD" resolution , usually you would use bt709 to convert to RGB . This assumes progressive source, otherwise, you have to use interlaced flag for the RGB conversion . So the scale filter specifies bt709 in the example

    Code:
    ffmpeg -i "video_file.mts" -vf trim=start_frame=9600:end_frame=10267,scale=out_color_matrix=bt709,format=rgb24 -start_number 9600 out_%05d.bmp
    Notice the end frame in -vf trim is 10267, because that's the 1st frame that is excluded from the end

    -start_number 9600 is to name the output image sequence with the proper starting frame number
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!