Use the segment muxer to write chunks
The `segment` muxer writes the output as a sequence of files, each containing a fixed duration of the input. It is the right tool for generating chunks for an HLS or DASH playlist, or for breaking a long recording into manageable pieces for a CDN.
The command
ffmpeg -i in.mp4 -c:v libx264 -crf 20 -f segment -segment_time 10 -reset_timestamps 1 chunk_%03d.mp4What it does
The command encodes the input and writes a new file every 10 seconds. The `chunk_%03d.mp4` template is the filename pattern; `%03d` is a zero-padded 3-digit counter. The `reset_timestamps 1` flag resets the timestamp counter at the start of each segment, so each file is a standalone 10-second video. The output is a sequence of MP4 files you can serve from a static host or a CDN.
Requirements
A muxer built into FFmpeg. The encode runs once, so the CPU cost is the same as a single output. The disk cost is multiplied by the number of segments. For a 1-hour input with 10-second segments, the output is 360 files.
Things to avoid
- Using the segment muxer for a single output. The muxer is designed for multiple files; for a single output, use the default MP4 muxer.
- Forgetting the `reset_timestamps 1` flag. Without it, each segment starts where the previous one left off, so the concatenation will not be seamless.
- Using a very short segment time. A 1-second segment is fine for low-latency streaming, but it produces a huge number of files and increases the manifest size.
- Expecting the muxer to write an HLS manifest. The muxer writes the segments; the manifest (`.m3u8` file) is a separate output. Use the `hls` muxer for a single command that writes both.