I have been working on a project for some time now looking to automate a large number of steps in creating predefined video files. The next step I am looking to automate is using mkvmerge to combine the original mp4 video/audio file with an srt subtitle. Some also have chapter markers which I would prefer to keep in the final mkv file, but I would also like to learn the command that will remove the chapter markers if I choose to do so in the future. The problem I am facing is some of the original mp4 files have both an aac and ac3 audio while others have only the ac3 audio. I only want the ac3 audio format in the final mkv file. The ac3 audio is sometimes the 2nd audio and sometimes the 1st audio, so telling mkvmerge to grab solely audio 0 or audio 1 will not work. Is there a command available that will tell mkvmerge to grab only the ac3 audio file and ignore the aac audio file?
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 4 of 4
Thread
-
-
I was afraid of that. I did write a simple batch file that works the majority of the time as the AAC audio is the 1st audio in the file and the AC3 audio the 2nd more often than not. I also added the link to the subtitle file which I label the same as the video file. Here's what I put together that has worked, so far anyway:
for %%A IN (*.mp4) do (mkvmerge -o "%%~nA.mkv" --language 0:eng "C:\%%~nA.srt" --language 0:eng -a 1 -d 2 "%%~A")
This works fine unless there is only 1 audio file in the .mp4 container. If there is only 1 audio file the current process is stopped, so I am now looking to add an audio option similar to 'if no 1, use 0' . If you've got any suggestions they would be greatly appreciated. Thank you -
A very basic way would be to run mkvmerge twice. First with a command assuming there are 2 audios. Then check mkvmerge's error return code and run the second command assuming there is only 1 audio track.
A less basic way would be to first parse mkvmerge --identify to find the AC-3 track's ID:
Code:for %%a in (*.mp4) do ( for /f "tokens=3 delims=: " %%b in ('mkvmerge --identify -F text --ui-language en "%%~a" ^| findstr /c:^(AC-3^)') do ( mkvmerge -o "output\%%~na.mkv" --audio-tracks %%~b "%%~a" --language 0:eng "%%~na.srt" ) )
Last edited by sneaker; 11th Aug 2019 at 10:12.
Similar Threads
-
MKVMERGE Batch Muxing multiple audio and subtitle tracks?
By jahob000 in forum Newbie / General discussionsReplies: 38Last Post: 30th May 2023, 20:13 -
Mux audio and Video in Mkvmerge using Batch File
By Daringbaaz in forum Newbie / General discussionsReplies: 2Last Post: 18th Oct 2019, 05:30 -
Batch Mkvmerge change default audio, subitle + delete audio
By alloar in forum Newbie / General discussionsReplies: 2Last Post: 8th Jan 2018, 16:38 -
Convert 5.1 audio AAC to AC3 DVD - Pal Vob- no audio for voices
By allrounder55 in forum AudioReplies: 0Last Post: 20th Aug 2017, 03:22 -
MKVMerge - Batch Mux Video and Audio File but provide ID?
By m3 in forum Newbie / General discussionsReplies: 25Last Post: 7th Sep 2015, 20:41