How to Extract Chapters and Timestamps Using FFmpeg
Extracting chapters and their corresponding start times from video files is a common task for video editors, archivists, and developers. This article provides a straightforward guide on how to use the FFmpeg suite to quickly extract chapter names and start times from a video file and save them directly to a text or JSON file.
Method 1: Extracting Clean Chapter Lists Using FFprobe
FFprobe (which comes bundled with FFmpeg) is the best tool for gathering media information in a readable format. You can extract chapter names and start times directly to a text file using the following command:
ffprobe -v error -show_entries chapter=title,start_time -of default=noprint_wrappers=1 input.mp4 > chapters.txtHow it works:
-v error: Suppresses unnecessary log details, showing only errors.-show_entries chapter=title,start_time: Specfies that you only want to extract the chapter title and its start time.-of default=noprint_wrappers=1: Formats the output as a clean list without extra XML/JSON-like tags.input.mp4: Replace this with the path to your video file.> chapters.txt: Saves the console output directly to a file namedchapters.txt.
The resulting chapters.txt file will look like this:
start_time=0.000000
title=Introduction
start_time=125.500000
title=Chapter 1: Getting Started
Method 2: Extracting Chapters in JSON Format
If you need to use the data in a programming script or web application, you can export the chapter details in JSON format:
ffprobe -v error -print_format json -show_chapters input.mp4 > chapters.jsonThis creates a structured chapters.json file containing
start times, end times, timebases, and chapter titles.
Method 3: Extracting Standard FFmpeg Metadata
If you plan to import these chapters into another video file later using FFmpeg, you should export the metadata in FFmpeg’s native format:
ffmpeg -i input.mp4 -f ffmetadata metadata.txtThis generates a metadata.txt file containing the global
metadata and specific chapter blocks formatted like this:
[CHAPTER]
TIMEBASE=1/1000
START=0
END=125500
title=Introduction