Split Large Video Files with FFmpeg on Linux
This article provides a straightforward guide on how to slice large video files into smaller, manageable chunks using FFmpeg via the Linux command line. You will learn how to split videos by specifying exact time durations, cutting specific time segments, and leveraging fast seeking to process files without losing quality or re-encoding.
Splitting by Fixed Time Duration
If you want to break a long video into multiple segments of equal
length (for example, every 10 minutes), the -f segment
muxer is the most efficient tool for the job.
ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment output_%03d.mp4-i input.mp4: Specifies your source video file.-c copy: Copies the video and audio streams directly without re-encoding. This makes the process incredibly fast and preserves original quality.-map 0: Ensures all streams (video, audio, subtitles) from the input are included in the outputs.-segment_time 00:10:00: Sets the duration of each chunk (HH:MM:SS format).output_%03d.mp4: Names the resulting files sequentially (e.g.,output_001.mp4,output_002.mp4).
Extracting a Specific Time Segment
When you only need a single specific clip out of a larger file, you can define the exact start time and duration or end time.
Method A: Using Duration
ffmpeg -ss 00:01:30 -i input.mp4 -t 00:05:00 -c copy output_clip.mp4-ss 00:01:30: The starting point of the cut (1 minute and 30 seconds in). Placing this before the-iflag enables “fast seeking,” which utilizes keyframes for near-instant processing.-t 00:05:00: The total duration of the clip you want to extract (5 minutes long).
Method B: Using an End Time
ffmpeg -ss 00:01:30 -i input.mp4 -to 00:06:30 -c copy output_clip.mp4-to 00:06:30: The exact timestamp where the clip should stop.
Handling Keyframe Mismatches
Using -c copy is fast because it doesn’t re-encode, but
it relies on existing keyframes (I-frames). If you split a video at a
second that doesn’t land on a keyframe, the video might freeze or show a
black screen for a few seconds at the beginning of the chunk.
If precision is more important to you than speed, force FFmpeg to re-encode the video by removing the stream copy command:
ffmpeg -ss 00:01:30 -i input.mp4 -to 00:06:30 -c:v libx264 -c:a aac output_precise.mp4By omitting -c copy and explicitly defining codecs like
-c:v libx264 (for video) and -c:a aac (for
audio), FFmpeg will cut exactly at the requested timestamp and generate
brand-new keyframes at the split points.