Skip to main content
  1. Posts/

Process video in a certain time range with FFmpeg?

··304 words·2 mins·
Tools Ffmpeg
Table of Contents

When dealing with videos, we may want to process video in a specific time range, for example, to only process video from 50 seconds to 70 seconds. How do we specify the time range in ffmpeg?

To specify the start position, use -ss option. This option can be used as an input option (before -i) or output option (after -i). When used as an input option, ffmpeg will directly seek the video file to that position. When used as an output option, ffmpeg will still decode frames before that position, but discards those frames. So using -ss as an input option may accelerate the processing speed dramatically.

To specify the end position, we can use -to option1. Another way is to use -t to specify a time duration.

The format for time can be found here:

There are two accepted syntaxes for expressing time duration.

[-][HH:]MM:SS[.m...]

HH  expresses the number of hours,  MM  the number of minutes for a maximum of 2 digits, and  SS  the number of seconds for a maximum of 2 digits. The  m  at the end expresses decimal value for  SS.

_or_

[-]S+[.m...][s|ms|us]

S  expresses the number of seconds, with the optional decimal part  m. The optional literal suffixes ‘s’, ‘ms’ or ‘us’ indicate to interpret the value as seconds, milliseconds or microseconds, respectively.

In both expressions, the optional ‘-’ indicates negative duration.

So to extract frame from 50 seconds to 70 seconds, we can use either of the following commands:

ffmpeg -ss 00:00:50 -to 00:01:10 -i input.mp4 -r 1 out-%2d.jpg
ffmpeg -ss 00:00:50 -t 20 -i input.mp4 -r 1 out-%2d.jpg
ffmpeg -ss 50 -t 20 -i input.mp4 -r 1 out-%2d.jpg

References
#


  1. Note that use -to as an input option, you need to use ffmpeg v4.0+. ↩︎

Related

How to Extract Key Frames from A Video with FFmpeg
··426 words·2 mins
Tools Ffmpeg Video
Audio Processing Using FFmpeg
··158 words·1 min
Tools Audio Ffmpeg
Notes on FFmpeg (1)
··530 words·3 mins
Tools Ffmpeg Video