Log in

View Full Version : Adding metadata from file into MP4 with ffmpeg


LigH
5th July 2025, 18:28
To add metadata from a pre-edited file (or from an export from another file), ffmpeg supports an FFMETADATA file format. This is mainly documented to add chapters to MP4 files.

It should also support adding general, global meta tags, like a file comment and a movie title, despite an existing separate command line parameter.

If I am not completely wrong,

-meta comment="This is my movie comment" -meta title="This is the movie title"

should be equivalent to:

-i movie.ffmetadata -map_metadata 1

movie.ffmetadata
;FFMETADATA1
comment=This is my movie comment
title=This is the movie title

I already used the metadata file successfully to add chapters to an MP4 file, like this:

;FFMETADATA1
[CHAPTER]
TIMEBASE=1/1000
START=0
END=10010
title=My first chapter
[CHAPTER]
TIMEBASE=1/1000
START=10010
END=19186
title=My second chapter

But if I merge both into the same metadata file, the chapters are added but the global tags get lost.

Kurt.noise
6th July 2025, 05:26
Did you try something like that ?


;FFMETADATA1
title=My Awesome Movie
comment=This is a global comment about the movie.
genre=Documentary

[CHAPTER]
TIMEBASE=1/1000
START=0
END=60000
title=Introduction


[CHAPTER]
TIMEBASE=1/1000
START=60000
END=120000
title=Chapter 1


[CHAPTER]
TIMEBASE=1/1000
START=120000
END=180000
title=Chapter 2

Jamaika
6th July 2025, 05:34
I think you've already put pressure on the creators. There is some correction, but it doesn't add much.
https://github.com/FFmpeg/FFmpeg/commit/30043cc167516ab01e460f0146038675fd0f5711
You should not use ffmetadata because there are errors.
I also don't know what the message in MediaInfo means
Error Detection Type : Per level 1
Metadata information in ffmpeg is treated modestly. Each container has different metadata and I don't even know if there are limits to the size of info in comments. What about track title information? There isn't. Each track or metadata can have a separate title without the possibility of opening links. In matroska containers, comment titles can be multilingual.

LigH
6th July 2025, 06:43
@Kurt.noise: Exactly like this. Just fewer empty lines in between. Chapters were generated by chapterEditor 1.45, general tags added manually.

@Jamaika: I did not mention it to the ffmpeg issue tracker yet. And I need the preparation of a file to be able to use the same call in a batch for different movies.

Jamaika
6th July 2025, 07:14
If you're going to add error information, ask why double chapter menus are created for mp4.
ffmpeg_avx2.exe -i 111.hevc -i 111.aac -i 111.txt -map_metadata 1 -c copy 111.mp4
Menu #1
ID : 3
Codec ID : text
Duration : 25 min 5 s
Language : English
Menu For : 1,2
XX:XX:XX.XXX :xxxx
...
Bit rate mode : VBR

Menu #2
XX:XX:XX.XXX :xxxx
...

LigH
7th July 2025, 17:21
ffmpeg ticket #11660 (https://trac.ffmpeg.org/ticket/11660) created.

LigH
12th July 2025, 19:54
I will use MP4Box instead; it supports chapters and tags in UTF-8 text files while multiplexing.

MP4Box -add video.m4v -add audio.m4a -chap chapters.ogm.txt -itags tags.ini.txt movie.mp4

Chapters in OGM Chapters format (CHAPTER01=HH:MM:SS.XXX\nCHAPTER01NAME=Name), iTunes compatible tags in name=value pairs (similar to Windows INI)

@Jamaika: And it inserts the chapters only once.

Z2697
14th July 2025, 16:42
-map_metadata 2

LigH
14th July 2025, 16:48
And why? Where can I find verbose documentation about this ultra-secret magic parameter?

StainlessS
14th July 2025, 19:59
any good,

https://superuser.com/questions/996223/using-ffmpeg-to-copy-metadata-from-one-file-to-another

More results from SuperUser.com
ffmpeg "-map_metadata" site:superuser.com
https://www.google.com/search?q=ffmpeg%20%22-map_metadata%22%20site%3Asuperuser.com

EDIT:
https://ffmpeg.org/ffmpeg.html#Advanced-options
About 75% down the page. [EDIT: about 1 or two screens past where above link enters]
-map_metadata[:metadata_spec_out] infile[:metadata_spec_in] (output,per-metadata)

Set metadata information of the next output file from infile. Note that those are file indices (zero-based), not filenames. Optional metadata_spec_in/out parameters specify, which metadata to copy. A metadata specifier can have the following forms:

g

global metadata, i.e. metadata that applies to the whole file
s[:stream_spec]

per-stream metadata. stream_spec is a stream specifier as described in the Stream specifiers chapter. In an input metadata specifier, the first matching stream is copied from. In an output metadata specifier, all matching streams are copied to.
c:chapter_index

per-chapter metadata. chapter_index is the zero-based chapter index.
p:program_index

per-program metadata. program_index is the zero-based program index.

If metadata specifier is omitted, it defaults to global.

By default, global metadata is copied from the first input file, per-stream and per-chapter metadata is copied along with streams/chapters. These default mappings are disabled by creating any mapping of the relevant type. A negative file index can be used to create a dummy mapping that just disables automatic copying.

For example to copy metadata from the first stream of the input file to global metadata of the output file:

ffmpeg -i in.ogg -map_metadata 0:s:0 out.mp3

To do the reverse, i.e. copy global metadata to all audio streams:

ffmpeg -i in.mkv -map_metadata:s:a 0:g out.mkv

Note that simple 0 would work as well in this example, since global metadata is assumed by default.


EDIT: copy metadata using exiftool
https://stackoverflow.com/questions/70261246/ffmpeg-metadata-copy-all

EDIT:
ffmpeg "-map_metadata" site:stackoverflow.com
https://www.google.com/search?q=ffmpeg%20%22-map_metadata%22%20site%3Astackoverflow.com&sclient=gws-wiz-serp

LigH
15th July 2025, 09:46
I did find the chapter in the official ffmpeg documentation. And I see no explanation of the meaning of a "1" or "2" there.

In other articles, which are no official documentation I hoped for, I even read about the existence of a "-1". So, apparently, third-party talks about that topic are the only reliable reference...