Add Chapters to Video with FFmpeg Metadata File

Adding chapters to your video files improves navigation and user experience, especially for long-form content. This guide provides a direct, step-by-step tutorial on how to write custom chapter markers in an external text file and merge them into your MP4 or MKV videos using FFmpeg without re-encoding.

Step 1: Create the Chapter Metadata File

FFmpeg uses a specific text format called FFMETADATA to define chapters. Create a new text file named chapters.txt and open it in any text editor.

Paste the following structure into the file:

;FFMETADATA1

[CHAPTER]
TIMEBASE=1/1000
START=0
END=15000
title=Introduction

[CHAPTER]
TIMEBASE=1/1000
START=15000
END=120000
title=Getting Started

[CHAPTER]
TIMEBASE=1/1000
START=120000
END=345000
title=Conclusion

Understanding the Metadata Fields:

Step 2: Merge the Chapters into the Video

Once your chapters.txt file is saved in the same directory as your video, open your terminal or command prompt and run the following FFmpeg command:

ffmpeg -i input.mp4 -i chapters.txt -map_metadata 1 -codec copy output.mp4

Command Breakdown: