Copy Video Chapters with FFmpeg

This article explains how to preserve and copy chapter markers from an input video to an output video using FFmpeg. You will learn the specific command-line flags required to transfer chapter metadata, whether you are transcoding the video, copying the streams directly, or merging chapters from a separate file.

The Default Behavior

By default, FFmpeg attempts to copy global metadata, including chapters, from the first input file to the output file. However, to guarantee that chapters are successfully transferred—especially when working with complex commands, multiple inputs, or specific container formats—you should explicitly use the -map_chapters flag.

Copying Chapters in a Standard Pass-Through

If you are copying the video and audio streams without re-encoding (stream copying) and want to ensure the chapters are preserved, use the following command:

ffmpeg -i input.mp4 -map_metadata 0 -map_chapters 0 -c copy output.mp4

Command Breakdown:

  • -i input.mp4: Defines the source video containing the chapters.
  • -map_metadata 0: Instructs FFmpeg to copy global metadata (like title, author, etc.) from the first input file (index 0).
  • -map_chapters 0: Explicitly copies the chapter markers from the first input file (index 0) to the output.
  • -c copy: Copies the video, audio, and subtitle streams directly without re-encoding, saving time and preserving quality.

Copying Chapters During Transcoding

If you are re-encoding the video (for example, compressing it or changing the format), the exact same mapping flags apply. Simply replace the stream copy argument with your encoding parameters:

ffmpeg -i input.mp4 -map_metadata 0 -map_chapters 0 -c:v libx264 -crf 23 -c:a aac output.mp4

In this case, FFmpeg transcodes the video to H.264 and the audio to AAC, while precisely mapping the original chapter timestamps and titles to the new file.


Copying Chapters from One File to a Different Video File

If you have a source file that contains chapter markers (source_with_chapters.mp4) and you want to inject those chapters into a different video file (target_video.mp4), you can map them from different inputs:

ffmpeg -i source_with_chapters.mp4 -i target_video.mp4 -map 1 -map_chapters 0 -c copy output.mp4

Command Breakdown:

  • -i source_with_chapters.mp4: Input index 0 (contains the chapters).
  • -i target_video.mp4: Input index 1 (contains the actual video/audio you want to keep).
  • -map 1: Instructs FFmpeg to use the video and audio streams from the second input (index 1).
  • -map_chapters 0: Instructs FFmpeg to pull chapter markers from the first input (index 0).
  • -c copy: Stream copies the data to output.mp4 without re-encoding.