Log in

View Full Version : FFMPEG - copying metadata


buffyangel108
21st March 2016, 03:40
I'm probably missing something simple, but here goes!

I have hundreds of .MKV files with the following streams:

- video
- audio 1 (DTS)
- audio 2 (AAC)
- subtitle 1
- subtitle 2

I'm trying to replace the DTS track in each of these with a newly created AC3 (which I've mastered in another program) using FFMPEG to mux. So the new file looks like:

- video
- audio 1 (new AC3)
- audio 2 (AAC)
- subtitle 1
- subtitle 2

How do I correctly map the metadata from the original file to the new one? If I use -map_metadata 0, the video, subtitle and audio 2 tracks have the correct metadata in the new file but the metadata from the original audio 1 (DTS) isn't copied over to the new audio 1 (AC3). But if I manually map the metadata from the original audio 1 to the new audio 1, the metadata from the other tracks isn't carried across. I can't find a way to combine the two - if that makes sense!

I would just do a manual -map_metadata for each stream, but I'm looking to do this in a batch file and some of the .mkvs have less than 2 subtitle streams (and FFMPEG balks if I try to map metadata to a stream that doesn't exist).

Any ideas?

buffyangel108
22nd March 2016, 17:32
Just to update this: I've found a solution, albeit a long-winded one.

I've amended the batch file to first run ffprobe on the original MKV file, parse the language of audio1 (DTS) to a variable, then apply it using -metadata to the new file (which doesn't disable -map_metadata for the other tracks). So the other tracks (video, audio2 and subs) in the new file have the metadata copied from the original file (using -map_metadata 0) and the new audio1 (AC3) track gets it metadata set from the ffprobe data.

Probably horribly inefficient, but it works!

smok3
23rd March 2016, 17:31
How about a combo of mkvmerge/mkvextract? (Hopefully mkvmerge might be enough)

DarkSpace
27th March 2016, 10:21
No idea if that will actually work, but how about
ffmpeg -i video.mkv -i audio.ac3 -map_metadata 0 -map_metadata:a:0 0:a:0 out.mkv
as a simple solution? What I think it will do is:
It first carries over all the metadata from input file 0 (video.mkv) to the output file.
Then, it maps the metadata from input file 0, audio stream 0 to the output file's audio stream 0.

Reference (https://ffmpeg.org/ffmpeg-all.html#Advanced-options)

buffyangel108
12th April 2016, 15:29
No idea if that will actually work, but how about
ffmpeg -i video.mkv -i audio.ac3 -map_metadata 0 -map_metadata:a:0 0:a:0 out.mkv
as a simple solution? What I think it will do is:
It first carries over all the metadata from input file 0 (video.mkv) to the output file.
Then, it maps the metadata from input file 0, audio stream 0 to the output file's audio stream 0.

Reference (https://ffmpeg.org/ffmpeg-all.html#Advanced-options)

Sadly not! The second -map_metadata cancels out the first. :(

buffyangel108
12th April 2016, 15:30
How about a combo of mkvmerge/mkvextract? (Hopefully mkvmerge might be enough)

Sounds similar to what I'm doing now with ffmpeg/ffprobe - will give it a look to see if it's simpler.

Glad to see I wasn't just overlooking something simple, though - thanks everyone!