How to Use FFmpeg -t and -to to Cut Videos
This guide explains how FFmpeg handles the -t and
-to options when trimming video files. While users often
attempt to combine -t and -to to define the
start and end of a middle clip, FFmpeg treats these two flags as
mutually exclusive duration limiters rather than a start-and-stop pair.
To extract a specific middle section of a video, you must combine either
-t or -to with the seek flag
(-ss). Below is a straightforward breakdown of how these
flags interact and the exact commands needed to extract your clip.
Understanding -ss,
-t, and -to
To cut a middle segment, you must define where the segment begins and where it ends. The relevant flags serve distinct purposes:
-ss(Start Time): Seeks to a specific timestamp (e.g.,-ss 00:01:30). This is mandatory for extracting a middle section; without it, FFmpeg begins at the very start of the file (00:00:00).-t(Duration): Specifies the length of the clip to capture from the start point (e.g.,-t 30extracts 30 seconds of footage).-to(Stop Position): Specifies an absolute timestamp where encoding or copying should stop (e.g.,-to 00:02:00).
Why You Cannot
Combine -t and -to Together
In FFmpeg, -t and -to both define when to
stop processing. According to official FFmpeg specifications,
-t and -to are mutually exclusive. If you
specify both options in the same output context, -t takes
precedence, and -to is ignored.
Furthermore, neither -t nor -to defines a
start point. Running a command using only -t and
-to will cause FFmpeg to start from the beginning of the
video (00:00:00) and apply whichever duration flag takes
priority, failing to capture a middle section.
Correct Methods to Extract a Middle Section
To isolate a middle section, pair -ss with either
-t or -to.
Method 1: Start Time +
Duration (-ss and -t)
Use this method when you know where the clip starts and exactly how long it should run.
ffmpeg -ss 00:02:00 -i input.mp4 -t 00:00:45 -c copy output.mp4-ss 00:02:00: Starts trimming at the 2-minute mark.-t 00:00:45: Captures 45 seconds of video from that point.-c copy: Copies audio and video streams without re-encoding, ensuring fast processing.- Result: The output contains the video segment
between
00:02:00and00:02:45.
Method 2: Start
Time + End Timestamp (-ss and -to)
Use this method when you know the exact start and end timestamps in the original video.
ffmpeg -ss 00:02:00 -to 00:02:45 -i input.mp4 -c copy output.mp4-ss 00:02:00: Fast-seeks to the 2-minute mark before reading input packets.-to 00:02:45: Stops reading at the 2-minute, 45-second mark of the source file.- Result: The output contains the segment between
00:02:00and00:02:45.
Important Placement Notes
- Input Seeking (
-ssbefore-i): Placing-ssbefore-imakes FFmpeg seek using keyframes, which is nearly instantaneous. When-tois used alongside an input-ss, it refers to the original source timestamp. - Output Seeking (
-ssafter-i): Placing-ssafter-iforces FFmpeg to decode frames sequentially from the start until it reaches the specified time. In this configuration,-tois interpreted relative to the new start point rather than the original video timeline. - Frame Accuracy: If stream copying
(
-c copy) cuts slightly before or after your specified time, remove-c copyto re-encode the video. Re-encoding allows FFmpeg to cut precisely on non-keyframes (P-frames or B-frames):
ffmpeg -ss 00:02:00 -i input.mp4 -to 00:02:45 -c:v libx264 -c:a aac output.mp4