Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st March 2016, 03:40   #1  |  Link
buffyangel108
Scared of Iguanas
 
Join Date: Aug 2006
Posts: 32
FFMPEG - copying metadata

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?

Last edited by buffyangel108; 21st March 2016 at 03:54.
buffyangel108 is offline   Reply With Quote
Old 22nd March 2016, 17:32   #2  |  Link
buffyangel108
Scared of Iguanas
 
Join Date: Aug 2006
Posts: 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!
buffyangel108 is offline   Reply With Quote
Old 23rd March 2016, 17:31   #3  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
How about a combo of mkvmerge/mkvextract? (Hopefully mkvmerge might be enough)
smok3 is offline   Reply With Quote
Old 27th March 2016, 10:21   #4  |  Link
DarkSpace
Registered User
 
Join Date: Oct 2011
Posts: 204
No idea if that will actually work, but how about
Code:
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
DarkSpace is offline   Reply With Quote
Old 12th April 2016, 15:29   #5  |  Link
buffyangel108
Scared of Iguanas
 
Join Date: Aug 2006
Posts: 32
Quote:
Originally Posted by DarkSpace View Post
No idea if that will actually work, but how about
Code:
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
Sadly not! The second -map_metadata cancels out the first.
buffyangel108 is offline   Reply With Quote
Old 12th April 2016, 15:30   #6  |  Link
buffyangel108
Scared of Iguanas
 
Join Date: Aug 2006
Posts: 32
Quote:
Originally Posted by smok3 View Post
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!
buffyangel108 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:17.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.