Copy Chapters from Input to Output in FFmpeg
This article explains how to preserve and copy chapter markers from a source video or audio file to a newly generated output file using FFmpeg. You will learn the exact command-line arguments required to map chapter metadata successfully, whether you are transcoding the file or simply copying the streams.
By default, FFmpeg does not always copy chapter markers
automatically, depending on the input and output container formats. To
guarantee that chapters are copied from the first input file to the
output file, you must use the -map_chapters option.
The Standard Command
To copy chapters along with the video and audio streams without re-encoding, use the following command:
ffmpeg -i input.mp4 -c copy -map_chapters 0 output.mp4Command Breakdown
-i input.mp4: Specifies the source file containing the original chapters. FFmpeg indexes this first input file as0.-c copy: Copies the video, audio, and subtitle streams directly without re-encoding, which saves time and preserves quality.-map_chapters 0: Tells FFmpeg to copy the chapter markers from the first input file (index0) to the output file.output.mp4: The destination file where the media streams and chapters will be written.
Copying Chapters While Re-encoding
If you are transcoding the video or audio instead of stream-copying,
the -map_chapters flag works exactly the same way:
ffmpeg -i input.mkv -c:v libx264 -c:a aac -map_chapters 0 output.mp4Important Considerations
- Container Support: Ensure that your output container format supports chapter markers. Formats like MP4, MKV, M4B, and WebM natively support chapters, while formats like AVI do not.
- Multiple Inputs: If you are merging multiple files
and want chapters from a specific file, change the index in
-map_chapters. For example,-map_chapters 1will copy chapters from the second input file.