Add chapter markers to podcast/audio using FFmpeg
Josh Chen
Posted on September 29, 2021
Chapter markers are an easier way for listeners to navigate your podcast, see what's coming up, or skip over spoilers they don't want to hear. So I want to add the support for users to add chapter markers on JustCast. To do this, I turn to my weapons of choice, FFmpeg (v4.4).
Add chapter markers
FFmpeg can take metadata from a file and save it to the audio file.
ffmpeg -i "input-ep1-hello-world.mp3" -i "ep1-hello-world-metadata.txt" -map_metadata 1 -codec copy "output-ep1-hello-world.mp3"
ep1-hello-world-metadata.txt
;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0
END=60000
title=chapter 1
[CHAPTER]
TIMEBASE=1/1
START=60
END=90
title=chapter 2
We need to ensure two things: 1. end time needs to be greater than the start time, 2. the chapter start time needs to be greater than the last chapter end time.
https://ffmpeg.org/ffmpeg-formats.html#Metadata-1
fluent-ffmpeg
ffmpeg(url)
.input(metafile)
.audioCodec('copy')
// .outputOptions('-metadata', 'title=song x')
.outputOptions([
"-map_metadata 0" // # 0 means copy whatever in the existing meta, 1 means ignore the existing
])
.toFormat('mp3')
.saveToFile(this.outputFilePath)
.on('codecData', (audioData) => {
// console.log(getSecondsFromHHMMSS(audioData.duration))
this.duration = getSecondsFromHHMMSS(audioData.duration);
})
💖 💪 🙅 🚩
Josh Chen
Posted on September 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.