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?
+ Reply to Thread
Results 1 to 4 of 4
-
-
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.
-
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.... -
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
-start_number 9600 is to name the output image sequence with the proper starting frame number
Similar Threads
-
Extract frames as uncompressed image files
By Fern99 in forum Newbie / General discussionsReplies: 4Last Post: 22nd Jul 2021, 10:42 -
Image sequence back into a video?
By jedi55 in forum RestorationReplies: 5Last Post: 6th May 2021, 20:42 -
Converting a sequence of images to video with variable framerate
By mantis2892 in forum Video ConversionReplies: 10Last Post: 31st May 2020, 11:38 -
HDMI video - compression and uncompressed and bitrates
By Christopher2222 in forum Capturing and VCRReplies: 1Last Post: 14th Feb 2018, 09:28 -
how to screen capture with uncompressed video?
By uglijimus in forum Video Streaming DownloadingReplies: 11Last Post: 24th Jan 2018, 10:01