Add Chapters to Video with FFmpeg and Text File

Adding chapter markers to your videos improves navigation and user experience for your viewers. This guide provides a direct, step-by-step walkthrough on how to write custom chapter metadata into a simple text file and merge it directly into a video file using the powerful command-line tool FFmpeg.

Step 1: Create the Metadata Text File

FFmpeg uses a specific metadata format to define chapters. Open a plain text editor (like Notepad, TextEdit, or VS Code) and create a new file named chapters.txt.

Paste the following template into the file:

;FFMETADATA1
title=My Video

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

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

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

Understanding the Metadata Format:

Save and close the chapters.txt file in the same folder as your video.

Step 2: Merge the Chapters into the Video

To merge the metadata file into your video without re-encoding (which ensures no loss of video quality and takes only a few seconds), use the FFmpeg command line.

Open your terminal or command prompt, navigate to the folder containing your video and chapters.txt, and run the following command:

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

Command Breakdown:

Once the command finishes running, you will have a new video file called output.mp4 with your custom chapters embedded. You can verify the chapters by playing the video in media players like VLC or MPC-HC.