How to add chapters into mp4/mkv file using ffmpeg

2019-05-10 19:19发布

问题:

Currently i'm using MKVToolNix for my needs which is fine but i would prefer some CLI also. As far as i know ffmpeg supports chapters management.

回答1:

The ffmetadata format allows you to add chapters to a file.

Have a look at https://ffmpeg.org/ffmpeg-formats.html#Metadata-1 for an example.



回答2:

Sorry maybe I'm not clear, and editing the answer I have messed up worst. I'm not English.

Like Alex Zubkov I want add chapters to video with ffmpeg via cmd.

The instruction in the page linked by MRousse don help me at all, but help me to solve 1st problem:

  1. Problem file was not in UTF-8.
  2. Problem was not unix.

So I take the file from the video with ffmpeg -i input.mkv -f ffmetadata metafile

I left the file without extension and edited with notepad++, as visible in this pic

that are unix.

If I create a new file with notepad++ it is like this

and not work, maybe was because I'm on windows and not on linux.

This is the file used for add chapters:

;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1
START=0
END=180
title=chapter \#1
[CHAPTER]
TIMEBASE=1/1
START=181
END=350
title=chapter \#2
[CHAPTER]
TIMEBASE=1/1
START=351
END=600
title=chapter \#3

With this I insert the chapter in the video file:

ffmpeg -i "input.mp4" -i meta -map_metadata 1 -codec copy output[with_meta].mp4

This solved the problem I have. Hope now I'm more clear, or I've not understood the question and I'm sorry.