The `-t` flag caps the output duration. It works on any input and any output format, and it stops the encode as soon as the limit is reached. The most common use is grabbing the first N seconds of a clip for a preview, a test, or a social-media post.

The command

ffmpeg -i in.mp4 -t 30 -c copy out.mp4

What it does

The command reads the input, writes the first 30 seconds, and stops. With stream copy, the output is the exact first 30 seconds of the source, container and all. With a re-encode, the encoder is told to stop after 30 seconds, and the output is a normal 30-second file. The flag works on the output side, so a 60-second input with `-t 30` produces a 30-second output.

Requirements

Any input FFmpeg can read. The flag is a no-op for inputs shorter than the limit, so passing `-t 30` on a 10-second file just produces the 10-second file. No special hardware, no special build.

Things to avoid

  • Confusing `-t` with `-to`. `-t` is a duration (relative), `-to` is a timestamp (absolute). The same 30-second output can be produced with `-t 30` (from the start) or `-to 00:00:30` (until 30 seconds in).
  • Using `-t` on a file with a variable frame rate. The output may end mid-frame, which can produce a malformed last GOP in the output container. Use `-t` with `-c copy` for an exact cut, or re-encode for a clean cut.
  • Forgetting that the flag stops the encode, not the demuxer. If the source has audio longer than the video, the audio is truncated to match.
  • Setting `-t` very high on a file that is already short. The flag is a no-op, but it can mask a typo in the input filename.