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.
Method 1: Using the -ss and -t options
This is the most straightforward method for extracting a clip from a video.
Breakdown 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:
Here -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:
This 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:
This 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:
The -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.