Skip to content
systemcoding.dev
Media

Cut a clip of fixed length with -t

Use -t as an output option in FFmpeg 7.1 to keep exactly the first N seconds of a stream, and know how it differs from -to.

1 min read
Summarize in AI

-t sets a duration, not an end time, and it stops reading the input after that much output has been written. That makes it the simplest way to take a fixed-length sample, such as a ten second preview from the start or from a point you chose with -ss.

Shell
ffmpeg -ss 90 -i input.mp4 -t 10 -c copy preview.mp4
ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 preview.mp4
Text
10.000000

The printed value is what the second command reports for a clip whose first frame lands on a keyframe. With -c copy the real duration can be a little longer or shorter than 10 seconds, because packets are kept whole and the clip starts on a keyframe. Re-encoding gives you the length you asked for to within a frame.

-t and -to do the same job from two directions: -t 10 means ten seconds of output, -to 100 means stop when the timestamp reaches 100. If both are given, -t wins, as the ffmpeg manual states. Placed before -i, -t limits how much of the input is read instead, which is rarely what you meant if you also use -ss after the input.

Taggedffmpeg
Share

More snippets

Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.