Extracting specific sections or clips from a larger video is a common task in video editing. You may want to create clips from an existing video to share on social media. Or you may want to give users a preview in the form of a clip so they can get a sample of your content.
If you're looking for somewhere to host and stream your videos for you, Mux's Video API has everything you need to manage video for your application.
Check out Mux's Video API!Method 1: Using the -ss and -t options
This is the most straightforward method for extracting a clip from a video.
ffmpeg -i input_file.mp4 \
-ss 00:01:30 \
-t 00:00:30 \
-c copy output.mp4Breakdown of the command:
- -i input_file.mp4: Specifies the input video file
- -ss 00:01:30: Sets the start time (1 minute and 30 seconds into the video)
- -t 00:00:30: Sets the duration of the clip (30 seconds)
- -c copy: Copies the streams without re-encoding (faster)
- output.mp4: Name of the output file
Method 2: Using -ss and -to for precise end time
If you prefer to specify the exact end time instead of duration:
ffmpeg -i input_file.mp4 \
-ss 00:01:30 -to 00:02:00 \
-c copy output.mp4Here -to 00:02:00 specifies the end time of the clip (2 minutes into the original video)
Method 3: Re-encoding for higher precision
For more precise cutting, especially at the beginning of the clip, you can place the -ss option before the input file and re-encode:
ffmpeg -ss 00:01:30 \
-i input_file.mp4 \
-t 00:00:30 \
-c:v libx264 \
-c:a aac output.mp4This method is slower but can provide a more accurate cut, especially for the starting point.
Advanced techniques
Extracting multiple clips
To extract multiple clips in one command:
ffmpeg -i input_file.mp4 \
-filter_complex \
"[0:v][0:a]trim=start=00:01:30:end=00:02:00,setpts=PTS-STARTPTS[v1][a1]; \
[0:v][0:a]trim=start=00:03:00:end=00:03:30,setpts=PTS-STARTPTS[v2][a2]; \
[v1][a1][v2][a2]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4This command extracts two 30-second clips (1:30-2:00 and 3:00-3:30) and concatenates them.
Cutting without re-encoding at I-frames or keyframes
For faster cutting at I-frames:
ffmpeg -i input_file.mp4 \
-ss 00:01:30 \
-to 00:02:00 \
-c copy -avoid_negative_ts make_zero output.mp4The -avoid_negative_ts make_zero option helps maintain audio-video sync when cutting at non-keyframes.
Tips for successful video clipping
- Use the right time format: FFmpeg accepts various time formats. HH:MM:SS.mmm is the most readable.
- Consider keyframes: When using `-c copy`, FFmpeg will cut at the nearest keyframe, which might not be exactly where you specified.
- Re-encode for precision: If you need frame-accurate cuts, re-encode the video instead of using -c copy.
- Check your output: Always verify the output video to ensure it contains the exact clip you intended.
- Handle audio carefully: When cutting precisely, ensure that audio doesn't get out of sync, especially when starting cuts on non-keyframes.
Clipping with Mux
If you have videos hosted with the Mux Video API you can create clips from Assets and Live Streams.
This article already has "Clipping with Mux" as an H2 at the end, so it doesn't need another headline with "Mux" added.
However, it doesn't have an FAQ section, so I'll create one:
Video clipping FAQs
What's the difference between using -c copy vs re-encoding when clipping?
-c copy (stream copy) is much faster because it copies video/audio streams without decoding and re-encoding. However, it can only cut at keyframes (I-frames), which typically occur every few seconds, so your cut points may be slightly off. Re-encoding (without -c copy) is slower but allows frame-accurate cuts at any point. Use -c copy for quick rough cuts and re-encode when precision matters.
Why doesn't my clip start exactly where I specified?
When using -c copy, FFmpeg can only cut at keyframes (I-frames), not at any arbitrary frame. If you specify -ss 00:01:30 but the nearest keyframe is at 00:01:28, your clip will start there instead. For frame-accurate cuts, remove -c copy to re-encode the video, which allows cutting at any frame but takes longer to process.
Should I place -ss before or after the -i input flag?
Placing -ss before -i makes FFmpeg seek before decoding, which is much faster for clips from late in long videos. However, it may be slightly less accurate. Placing -ss after -i is slower (FFmpeg decodes from the start) but more accurate, especially when re-encoding. For -c copy operations, place -ss before -i for speed since you're cutting at keyframes anyway.
How do I extract multiple non-contiguous clips from one video?
Run separate FFmpeg commands for each clip, or use the complex filter with concat to extract and combine multiple segments in one pass. For example, extract minutes 1-2 and 5-6, then concatenate them. The command becomes complex quickly, so for multiple clips, running separate extraction commands is often simpler and easier to troubleshoot.
Why is my clipped video out of sync (audio doesn't match video)?
Audio sync issues typically occur when cutting at non-keyframes with -c copy, especially if the video has variable frame rate. The -avoid_negative_ts make_zero flag helps prevent this. If issues persist, re-encode the clip without -c copy or use -async 1 to resample audio for sync. Always verify clips before using them in production.
Can I clip videos without knowing the exact timestamps?
Yes, but you'll need to identify timestamps first. Use media players with timestamp displays, ffprobe to analyze the video structure, or video editing tools with preview capabilities. Some players let you mark in/out points that you can then translate to FFmpeg commands. For precise clipping workflows, identify timestamps in a player first, then execute FFmpeg commands.
What's the best format for specifying time in FFmpeg?
Use HH:MM:SS or HH:MM:SS.mmm format for readability (e.g., 00:01:30.500 for 1 minute, 30.5 seconds). FFmpeg also accepts seconds as a decimal (90.5 for 1m30.5s), but the colon format is more intuitive. For very short clips, you can use just SS.mmm (e.g., 5.25 for 5.25 seconds).
How do I create clips at scale from many videos?
Write shell scripts that loop through video files and apply clipping commands, or use video APIs that provide clipping functionality programmatically. For production environments processing many clips, APIs like Mux handle clipping at scale without managing FFmpeg infrastructure yourself. This approach also provides benefits like automatic storage, delivery optimization, and analytics on clipped content.