How to add chapters to ogg file?

3k Views Asked by At

I am trying to add chapters to a ogg file containing vorbis audio.

From this link I copied the following ffmpeg command.

ffmpeg -threads auto -y -i in.ogg -i metadata_OGG.txt -map_metadata 1 -codec copy out_METADATA.ogg

My metadata_OGG.txt file is as given below.

CHAPTER00=00:00:00.000
CHAPTER00NAME=Chapter 01
CHAPTER01=00:00:05.000
CHAPTER01NAME=Chapter 02
CHAPTER02=00:00:10.000
CHAPTER02NAME=Chapter 03

I am getting the following error.

[ogg @ 00000000006d6900] Unsupported codec id in stream 0
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

But if i change -codec copy to -acodec copy there is no error in ffmpeg but the text file is converted to video. i.e. the output file will have a static video frame with the text of metadata_OGG.txt in it. Also, I observe the following log message during conversion.

  Stream #1:0 -> #0:0 (ansi (native) -> theora (libtheora))
  Stream #0:0 -> #0:1 (copy)

Anybody please tell me what is going wrong here?

Also, I would like to know what is the right way to add chapters to ogg. I searched for some tools also. I did not get any.

3

There are 3 best solutions below

0
MayurK On

I found the issue.

For ffmpeg to work, the metadata file should have the following header.

;FFMETADATA1

I followed the steps given in ffmpeg documentation for metadata.

But the issue is not resolved completely.

With the above steps I am able to add metadata to mp4, mkv and other container files but not to ogg files. I am not sure whether ffmpeg supports adding chapters to ogg files.

0
Totor On

Here is what worked for me using ffmpeg 4.3.1.

I have a metadata file which almost respects ffmpeg's metadata file format:

;FFMETADATA1
title=Evolution theory

[CHAPTER]
TIMEBASE=1/1000
START=0
END=
title=Darwin's point of view

[CHAPTER]
TIMEBASE=1/1000
START=78880
END=
title=Genghis Khan's children

Notice the file format requires an END time, but leaving it empty didn't bother in my case.

Now I add chapter information to my opus/ogg file:

ffmpeg -i darwin.opus.ogg -i darwin_chapters.txt -map_metadata 1 -c copy darwin_withchapters.opus.ogg

Note: if you want to overwrite existing chapter information from the file, you may need to add a -map_chapters 1 parameter in the ffmpeg command line above.

That creates the file darwin_withchapters.opus.ogg. I check if chapter info has really been added to the file:

opusinfo darwin_withchapters.opus.ogg

You would use ogginfo for Ogg/Vorbis files.

And here is the result (I removed a few irrelevant lines):

ENCODER=opusenc from opus-tools 0.1.10
ENCODER_OPTIONS=--bitrate 112
title=Evolution theory
CHAPTER000=00:00:00.000
CHAPTER000NAME=Darwin's point of view
CHAPTER001=00:01:19.880
CHAPTER001NAME=Genghis Khan's children
[...]

Here you go. ffmpeg did the conversion between its metadata file format to the vorbis tag/comment chapter format.

You could also directly write metadata in the Vorbis Chapter Extension format, and use the classic vorbiscomment tool, or other tools which allow editing of opus/ogg in-file tags.

0
David Eckardt On

Opus has been mentioned here. I was trying to make opusenc from opus-tools add chapters when encoding and couldn’t find a command line example anywhere. Thanks to the hints in this thread I managed to figure it out, perhaps someone may find it helpful.

opusenc --comment "CHAPTER000=00:00:00.000" --comment "CHAPTER000NAME=Hello" --comment "CHAPTER001=01:23:45.678" --comment "CHAPTER001NAME=World" input.wav output.opus

The chapter key/value scheme is the aforementioned Ogg/Matroska one. Of course, more metadata options like --title, --artist etc. can be added.

Using ffmpeg to add the chapters resulted in two problems for me: The artwork image in the ogg/opus input file was missing in the output file, and ffmpeg rejected empty END chapter times.

I did this on Windows 10 using

  • opusenc opus-tools 0.2-3-gf5f571b (using libopus 1.3)
  • ffmpeg version 4.4.1-essentials_build-www.gyan.dev
  • opusinfo, MPC-HC (64-bit) v1.7.11 and VLC Media Player 3.0.14 Vetinari to confirm.