How to add chapters to ogg file? - ffmpeg

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.

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.

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.

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.

Related

Invalid data error during ffmpeg .m4a conversion

I wanted to edit my .m4a voice recording from Samsung Voice Recorder using ffmpeg 2.2.2, however, I got the error Invalid data found when processing input. I tried to open it through Audacity, but it returned an error claiming that the ffmpeg library is missing, which is definitely not the case. Eventually I tried to use online .m4a to .mp3 converters, but they all returned error, so I assume there may be an issue with the encoding of the original file and ffmpeg should be configured accordingly. What settings shall I use? (The original file can be played on the phone without any problem.)
ffmpeg -ss 00:00:19 -i "C:\Your\Folder\original.m4a" edited.m4a

FFMPEG DASH - Live Streaming a Sequence of MP3 Clips

I am attempting to create a online radio application using FFMPEG - an audio only DASH stream.
I have a directory of mp3 clips (all of the same bitrate and sample size) which I am encoding to the AAC format and outputting to a mpd.
This is the current command I am working with to stream a single mp3 file:
ffmpeg -re -i <input>.mp3 -c:a aac -use_timeline 1 -use_template 1 -window_size 5 -f dash <out>.mpd
(Input and output paths have been substituted for < input >.mp3 and < output >.mpd in this snippet)
I am running a web server and have made the mpd accessible on it. I am testing the stream using VLC player at the moment.
The problem:
Well, the command works, but it will only work for one clip at a time. Once the next command is run immediately proceeding the completion of the first, VLC player will halt and I need to refresh the player to continue.
I'm aiming for an uninterrupted stream wherein the clips play in sequence.
I imagine the problem is that a new mpd is being created with no reference to the previous one, and what I ought to be doing is appending segments to the existing mpd - but I don't know how to do that using FFMPEG.
The question: Is there such a command to append segments to a previously existing mpd file in FFMPEG? or am I coming at this problem all wrong? Perhaps I should be using FFMPEG to format the clips into these segments, but then adjusting the mpd file manually.
Any help or suggestions would be very much appreciated!

How to use codec type properly in NPM

Trying to use '-acodec libopus' in my npm project as I use in the command line like in the following format;
ffmpeg -acodec libopus -i 1.webm 1.wav
This works perfectly! But I would like to make it possible in my NPM project.
How can I set the parameters?
This is what I have , but not working. The output file is broken in a way that some of the frames of the audio file are missing. It is like there is sound and then there is not. And vice versa.
var proc = new ffmpeg({
source: file,
nolog: false
});
format = "opus"; // or could be wav as well!
proc.addOptions([
'-f ' + format,
'-acodec libopus',
'-vn'
]);
The purpose is to take audio file from the video file seamlessly.
Without the codec libopus, I get the following errors in the command prompt, so I assume I should handle the same issue in my NPM project as well.
[opus # 00000000006d4520] LBRR frames is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[opus # 00000000006d4520] Error decoding a SILK frame.
[opus # 00000000006d4520] Error decoding an Opus frame.
My library is up to date, I just need to use the codec libopus properly.
Any suggestions?
\node-js>ffmpeg -version
ffmpeg version N-86175-g64ea4d1 Copyright (c) 2000-2017 the FFmpeg
developers
built with gcc 6.3.0 (GCC)
Output in command line;
xtranscribe transcodeWatson: file : ./data/that/2.webm
progress 62.625273103421605%
progress 100.01224534515762%
SAVED - transcodeWatson : .mp3
out of transcode!
fileSizeInBytes : 16284033
According to the README, you can add input options to the process:
proc.addInputOption('-acodec libopus');
It matters where you place an option in ffmpeg. If you put it before -i, it applies to that particular input. If you put it before an output file name, it applies to that output.

FFmpeg record rtsp stream to file error

I use ffmpeg to record rtsp stream, it work good but the output file got some proble, when I use use K-Lite Codec Pack to open the output (avi) file the video cant be seek, forward, backward and dont display video time. It lock like i am viewing streaming.
here is the command i used
ffmpeg -i rtsp://27.74.xxx.xxx:55/ufirststream -acodec copy -vcodec copy abc.avi
video playing error with K-Lite Codec Park image
Looks like header file not been updated on output file. It's recommended to close output file by pressing "q" button while ffmpeg reads input stream to properly finalize output file.

Transfer custom (all) metadata using ffmpeg

How to transfer metadata using FFMPEG or other tools with CMD ?
I'm trying to encode video/audio and since they already have metadata inside obviously i want to preserve them into my new file
btw since i'm using mediamonkey as main player, there's also some Custom metadata. this is the one who wont transfer
for Video output file using mp4/mkv (using x264)
for Audio output file using m4a (using neroAac)
Thank You!
ps. which container is best for neroAac and x264? since i can't seem to edit mkv metadata (when i remove from mediamonkey playlist, they're all gone), mp4 is fine though and i can't seem to play AAC, although it's fine when muxed into video
Copy all custom and global metadata tag information using the following command:
ffmpeg <inputfile> -movflags use_metadata_tags -c copy <outputfile>

Resources