VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. Member
    Join Date
    Sep 2018
    Location
    North America
    Search Comp PM
    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?
    Quote Quote  
  2. There is no such mkvmerge command.
    Quote Quote  
  3. Member
    Join Date
    Sep 2018
    Location
    North America
    Search Comp PM
    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
    Quote Quote  
  4. Originally Posted by olpdog View Post
    I am now looking to add an audio option similar to 'if no 1, use 0'
    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 09:12.
    Quote Quote  



Similar Threads