video editing,

Add chapters to mp4

agowa338 agowa338 May 26, 2018 · 1 min read
Share this

  1. Get the frame rate of your source video (assuming you have 30fps and the video is called input.mp4 for later steps)
  2. Calculate Timebase value
    • Timestamp fps*1000 => Timestamp 30000
    • Timebase 1/Timestamp => Timebase 1/30000
  3. Calculate all start and end timestamps:
    • Note: timestamp 02:03:04.005 => 2 hours, 3 minutes, 4 seconds, 5 millisecond
    • timestamp = (hours*60^2 + minutes*60^1 + seconds*60^0 + millisecond*10^-3) * timebase
    • END Timestamp = Starting Timestamp of the following chapter - 1
    • Timestamp for this example: 221520150
    • And if this is the timestamp for chapter n, the end timestamp of chapter n-1 is: 221520149
  4. Use the following template to create a text file named meta.txt
    ;FFMETADATA1
    TITLE=ENTER_VIDEO_TITLE_HERE
    PRODUCER=ENTER_PRODUCER_HERE
    [CHAPTER]
    TIMEBASE=1/30000
    START=0
    END=221520149
    title=Chapter 01 - ENTER_TITLE_OF_CHAPTER_01
    [CHAPTER]
    TIMEBASE=1/30000
    START=221520150
    END=443020300
    title=Chapter 02 - ENTER_TITLE_OF_CHAPTER_02
  5. Use ffmpeg to combine the metadata and source video:
    ffmpeg -i input.mp4  -i meta.txt -c copy -map_metadata 1 output.mp4
  6. Open output.mp4 using vlc and verify that all timestamps are correct.

agowa338
Written by agowa338