How to specify start and end frames when making a video with ffmpeg

Question:

I am working with python in a jupyter notebook, and I am trying to use ffmpeg to specify the start and end images and convert several images from a folder into a single video. I have a folder, ‘images’, with the images inside labeled, ‘image0’, ‘image1’, ‘image2’, etc. I would like to specify the start and end images in my video. For example, I would like to be able to make the video using ‘image100’, to ‘image200’. Right now, I have:

!/home/jovyan/ffmpeg-dir/ffmpeg -i /home/jovyan/images/image%d.bmp -frames:v 1000 /home/jovyan/output.mp4

This is making the video correctly, but I believe it is just taking the first 1000 images.

Thanks!

Asked By: supercool

||

Answers:

You can try this:

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

OR

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -c copy cut.mp4 

The -t option specifies a duration, not an end time. The above command will encode 8s of video starting at 3s. To start at 3s and end at 8s use -t 5. If you are using a current version of ffmpeg you can also replace -t with -to in the above command to end at the specified time.

Answered By: Shamsheer

Use -start_number.

Use the -start_number option to declare a starting number for the sequence. This is useful if your sequence does not start with img001.jpg but is still in a numerical order.

(source: https://ffmpeg.org/faq.html#toc-How-do-I-encode-single-pictures-into-movies_003f)

For example, I would like to be able to make the video using ‘image100’, to ‘image200’.

You need to combine -start_number 100 and -frames:v 101 (101 frames from image100.jpg to image200.jpg).

Answered By: Pamphile

I was faced with one task to encode each 60-th frame with jpeg-lossless codec.
The yuv-sequence had a fixed frame rate = 60fps. I applied the following ‘-ss 00:00:01’ to access 60-th frame:

ffmpeg -pix_fmt yuv420p -video_size 1920×1080 -r 60 -ss 00:00:01 -i test_1920x1080.yuv -frames:v 1 -vcodec jpegls -pix_fmt yuv420p -y test_frame60_ls.jpg

Notice: despite i explicitly declared the output format = yuv420p, the format rgb24 was used instead.

Answered By: Shevach Riabtsev
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.