Jump to content

Help with ffmpeg command - Inject an Audio Track into MKV


ginjaninja

Recommended Posts

ginjaninja

Can any one advise please how do inject the aac audio track into the mkv...

 

I have an original MKV with 1 Video track, 1 or More Audio Tracks, 0 or more Subtitle tracks, 0 or more chapters called movie.mkv

I have an aac encoded version of the original MKV's dts track called movie.aac

 

I would like to end up with....

(i need the command to work in a script with multiple different files with different numbers of tracks)

 

Originals Video Track

AAC Track

Originals Audio Tracks

Originals Subtitle Tracks

Originals Chapters

 

 

or even more generically...Keep the MKV exactly the same except inject the aac as the primary audio track.

 

I found this command on the internet but it doesnt work

ffmpeg -v quiet -i %%~nF.mkv -i %%~nF.aac -vcodec copy -map 0:v:0 -acodec copy -map 1:a:0 -scodec copy -map 0:s:0 %%~nF.AAC.mkv

Also, is it possible to stop ffmpeg injecting additional garbadge streams into mkv...like tags .....so its identical just with an extra audio track.?

 

thanks

Edited by ginjaninja
Link to comment
Share on other sites

thefirstofthe300

Are you using Windows or Linux or Mac? That would make a difference as the windows ffmpeg command is ffmpeg.exe.

 

Depending on the above, here is what I would use:

ffmpeg -i movie.mkv movie.aac -map 0:0 -map 1:0 -map 0:{stream_number_for_subtitle_stream} -v:c copy -a:c copy -s:c copy movie.AAC.mkv

Change what is in brackets to the appropriate number base on the output of ffprobe (the number of the stream in the video file.

Link to comment
Share on other sites

ginjaninja

Are you using Windows or Linux or Mac? That would make a difference as the windows ffmpeg command is ffmpeg.exe.

 

Depending on the above, here is what I would use:

ffmpeg -i movie.mkv movie.aac -map 0:0 -map 1:0 -map 0:{stream_number_for_subtitle_stream} -v:c copy -a:c copy -s:c copy movie.AAC.mkv
Change what is in brackets to the appropriate number base on the output of ffprobe (the number of the stream in the video file.
Thanks its windows

Ps i cant hardcode eg subtitle steam numbers as it needs to work accross multiple files...is there a solution?

Link to comment
Share on other sites

thefirstofthe300

I think I saw somewhere that doing

ffmpeg -i movie.mkv movie.aac -map 0 -map 1 -map 0 -v:c copy -a:c copy -s:c copy movie.AAC.mkv

would work. I haven't tried it myself though. You should test it on something that isn't important to you.

Link to comment
Share on other sites

ginjaninja

thanks you pointed me in the right direction

ffmpeg -v verbose -i filmname.mkv -i filmname.aac -map 0:0 -map 1 -map 0:a -map 0:s -vcodec copy -acodec copy -scodec copy filmname.AAC.mkv

as long as the first stream is the one and only video stream (which it always is)..this command works

 

problem is it creates loads of tags which im keen to remove...but also it seems to alter the dts track rather than copy it (not that it has an adverse affect)

[matroska @ 00000000003def60] Non-monotonous DTS in output stream 0:2; previous:
 7294762, current: 7294751; changing to 7294762. This may result in incorrect ti
mestamps in the output file.

Screenshot%202015-02-25%2013.20.27.png

Link to comment
Share on other sites

ginjaninja
mkvmerge.exe --disable-track-statistics-tags --track-order 0:0,1:0 -o filmname.aac.mkv --no-global-tags --no-track-tags filmname.mkv --no-global-tags --no-track-tags filmname.aac

its simpler (and quicker)  with mkv merge....and no alteration of dts track...

turns out mkvmerge also generates the tags... but --disable-track-statistics-tags disables...

 

https://github.com/mbunkus/mkvtoolnix/wiki/Automatic-tag-generation

seems to suggest the tags are a good thing though...still i wanted to keep the file the same (apart from the aac track)

Edited by ginjaninja
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...