Split MKV into Chapters Using FFmpeg
This guide demonstrates how to split a Matroska (MKV) video file into individual segment files based on its internal chapter markers using FFmpeg. You will learn the exact command-line instructions needed to automatically detect chapters and extract them either instantly without losing quality or with frame-accurate precision.
The Fast Method: Split Without Re-encoding (Lossless)
To split an MKV file quickly, you can copy the video and audio streams directly. This process takes only a few seconds because it does not re-encode the video.
Run the following command in your terminal or command prompt:
ffmpeg -i input.mkv -c copy -map 0 -f segment -segment_at_chapters 1 output_%03d.mkvHow this command works: * -i input.mkv:
Specifies your source video file. * -c copy: Copies all
video, audio, and subtitle streams without re-encoding, preserving
original quality. * -map 0: Ensures all streams (multiple
audio tracks, subtitles) from the input file are included in the split
files. * -f segment: Tells FFmpeg to use the segment muxer
to split the file. * -segment_at_chapters 1: Instructs
FFmpeg to split the video at the exact timestamps defined by the
internal chapter markers. * output_%03d.mkv: Defines the
output naming convention. %03d is a placeholder that
generates sequential numbers starting at 000 (e.g.,
output_000.mkv, output_001.mkv).
Note: Because this method copies the streams without re-encoding, FFmpeg must split the file at the nearest keyframe (I-frame) to the chapter marker. This may result in slight timing discrepancies of a fraction of a second at the start or end of a segment.
The Precise Method: Frame-Accurate Splitting (With Re-encoding)
If your splits must be frame-accurate down to the exact millisecond of the chapter marker, you must re-encode the video. This process takes longer but ensures the video cuts precisely at the chapter line.
Run this command to re-encode the segments using the x264 video encoder and AAC audio encoder:
ffmpeg -i input.mkv -c:v libx264 -crf 22 -c:a aac -map 0 -f segment -segment_at_chapters 1 output_%03d.mkvHow this command works: * -c:v libx264:
Re-encodes the video stream to H.264 format. * -crf 22:
Sets the Constant Rate Factor for quality (lower values mean higher
quality; 18–23 is standard). * -c:a aac: Re-encodes the
audio stream to AAC.