VideoHelp Forum
+ Reply to Thread
Results 1 to 2 of 2
Thread
  1. I've got 1000's of videos that need to be checked to make sure that English is the default audio track and foreign language audio tracks removed. This normally isn't an issue because I found a script that does just that, however, for audio tracks that are not labeled I have to check them manually. Part of the problem is I'm not sure which video files do not have properly labeled audio tracks and my second issue is how do I quickly process all these videos manually. I have been adding them to MKVToolnix GUI and removing the foreign language track, but this is super tedious as it requires me to load the video and figure out which track is English. Is there a faster way? Perhaps there is a "file explorer" for MKV videos that will show me how many audio tracks there are and the language for multiple files at once?

    Below is the vbs script I use for isolating English audio when properly labeled, I found it somewhere on this forum.

    Code:
    Option Explicit
    Dim strInputFileName
    Dim strBaseFileNameNoExt
    Dim strTempFileName
    Dim strOutputFileName
    Dim MediaObjectList
    Dim objArgs
    Dim objFSo
    Dim objShell
    Dim strTitle
    Dim strTitleChunks
    Dim TrackSelection
    Set objArgs = WScript.Arguments
    Set objFSo = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    
    For Each strInputFileName in objArgs
    Call GetBaseFileNameNoExt ' FQ FileName without extension
    Call ParseTitle ' Filename without Path or Extension
    Call GetTrackInfo ' Identify Desired Tracks
    Call RenameInputFile ' Rename Input to .tmp in case input is already .mkv
    Call SetOutputFileName ' FQ FileName with MKV extension
    Call RemuxFile ' Remux
    'Call DeleteSource ' Delete Source if Output Created
    Next 
    
    Sub GetBaseFileNameNoExt
    strBaseFileNameNoExt = Trim(Left(strInputFileName,InstrRev(strInputFileNa me,".")-1))
    End Sub 'GetBaseFileNameNoExt
    
    Sub RenameInputFile
    strTempFileName = strInputFileName & ".tmp"
    objFSO.MoveFile strInputFileName ,strTempFileName
    End Sub 'RenameInputFile
    
    Sub SetOutputFileName
    strOutputFileName = strBaseFileNameNoExt & ".mkv"
    End Sub 'SetOutputFileName
    
    Sub ParseTitle
    strTitleChunks = Split(strBaseFileNameNoExt,"\")
    strTitle = strTitleChunks(UBound(strTitleChunks))
    If Instr(strTitle,"[") Then strTitle = Trim(Left(strTitle,InstrRev(strTitle,"[")-1))
    End Sub 'ParseTitle
    
    Sub GetTrackInfo
    Dim CommandLine
    Dim MediaObject
    Dim MediaObjects
    Dim Track
    Dim VideoTracks
    Dim AudioTracks
    Dim SubTracks
    Dim TrackOrder
    TrackSelection = ""
    
    CommandLine = """" & GetMKVExecutable & """ "
    CommandLine = CommandLine & "-i -F verbose-text "
    CommandLine = CommandLine & """" & strInputFileName & """ "
    Set MediaObjectList = objShell.Exec(CommandLine)
    MediaObjects = Split(MediaObjectList.StdOut.ReadAll, vbCrLf)
    For Each MediaObject In MediaObjects
    Select Case Left(MediaObject,8)
    Case "Track ID"
    Track = Split(MediaObject," ",5)
    Select Case Track(3)
    Case "video"
    TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
    VideoTracks = VideoTracks & " " & Replace(Track(2),":","")
    Case "audio"
    If Instr(Track(4),"language:eng") Then 
    TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
    AudioTracks = AudioTracks & " " & Replace(Track(2),":","")
    ElseIf Instr(Track(4),"language") = 0 Then 
    TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
    AudioTracks = AudioTracks & " " & Replace(Track(2),":","")
    End If
    Case "subtitles"
    If Instr(Track(4),"language:eng") Then 
    TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
    SubTracks = SubTracks & " " & Replace(Track(2),":","")
    ElseIf Instr(Track(4),"language") = 0 Then 
    TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
    SubTracks = SubTracks & " " & Replace(Track(2),":","")
    End If
    Case Else
    'msgbox(Track(3))
    'Not Processing other values at this time
    End Select
    Case Else
    'Not Processing other values at this time
    End Select
    Next
    If Len(SubTracks) > 0 Then
    TrackSelection = "-s " & Replace(Trim(SubTracks)," ",",") & " " & TrackSelection
    TrackOrder = Replace(RTrim(SubTracks)," "," 0:")
    Else
    TrackSelection = "-S " & TrackSelection
    End If
    If Len(AudioTracks) > 0 Then
    TrackSelection = "-a " & Replace(Trim(AudioTracks)," ",",") & " " & TrackSelection
    TrackOrder = Replace(RTrim(AudioTracks)," "," 0:") & TrackOrder
    End If
    If Len(VideoTracks) > 0 Then
    TrackSelection = "-d " & Replace(Trim(VideoTracks)," ",",") & " " & TrackSelection
    TrackOrder = Replace(RTrim(VideoTracks)," "," 0:") & TrackOrder
    End If
    TrackOrder = "--track-order " & Replace(Trim(TrackOrder)," ",",")
    TrackSelection = TrackSelection & TrackOrder & " "
    End Sub 'GetTrackInfo
    
    Sub RemuxFile
    Dim CommandLine
    CommandLine = """" & GetMKVExecutable & """ "
    CommandLine = CommandLine & "--title """ & strTitle & """ --no-global-tags --no-track-tags "
    CommandLine = CommandLine & TrackSelection
    CommandLine = CommandLine & "-o """ & strOutputFileName & """ "
    CommandLine = CommandLine & """" & strTempFileName & """ "
    
    If Instr(TrackSelection,"-d ") = 0 Then Exit Sub 'Video Track Not Identified
    If Instr(TrackSelection,"-a ") = 0 Then Exit Sub 'Audio Track Not Identified
    objShell.Run CommandLine,7,True
    End Sub 'RemuxFile
    
    Sub DeleteSource
    If ValidFile(strOutputFileName) Then objFSO.DeleteFile strTempFileName
    End Sub 'DeleteSource
    
    Function GetMKVExecutable
    If ValidFile("C:\Program Files\MKVToolNix\mkvmerge.exe") Then
    GetMKVExecutable = "C:\Program Files\MKVToolNix\mkvmerge.exe"
    ElseIf ValidFile("C:\Program Files (x86)\MKVToolNix\mkvmerge.exe") Then
    GetMKVExecutable = "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
    Else
    GetMKVExecutable = NULL
    msgbox("*** MKV Tools NOT Detected ***")
    End If
    End Function 'GetMKVExecutable
    
    Function ValidFile(FileName)
    Dim Outfile
    ValidFile = False
    If objFSO.FileExists(FileName) Then
    Set Outfile = objFSO.GetFile(FileName)
    If Outfile.size > 100 Then
    ValidFile = True
    End If
    End If
    End Function 'ValidFile
    Quote Quote  
  2. Member
    Join Date
    Apr 2007
    Location
    Australia
    Search Comp PM
    Hi.
    This post was edited. BIG TIME.
    Edited again. (Bedtime for me.)
    Left out the '-acodec copy' parameter.
    Please read it again. The batch file has changed.

    I've got no videos to test with. I tested it on MKVs with only English subtitles.
    Save the following script - test1.cmd
    Put it in a folder with a bunch of MKV videos.
    You also need ffmpeg.exe
    Run the batch file.

    Code:
    @echo off
    if not exist NEW\*.* md NEW
    if exist temp\*.* (del /q temp\*.*) else md temp
    
    for %%a in ("*.mkv") do call :Process "%%a"
    goto :end
    
    :Process
    :: Set the first stream, normally the video, to English. (In case it's not English.)
    ffmpeg -i "%~1" -vcodec copy -acodec copy -metadata:s:0 language=eng -y "temp\%~1"
    :: Copy the English streams (video+audio) to a new video.
    ffmpeg -i "temp\%~1" -vcodec copy -acodec copy -map 0:m:language:eng -y "NEW\%~1"
    goto :eof
    
    :end
    rd /s /q temp
    Should catch most videos. If the first stream is NOT the video there may be problems.
    If a stream, video or audio, has no language defined, well.....
    Cheers.


    Edit:
    A slightly different version is posted here.
    https://forum.videohelp.com/threads/377677-Video-batch-files/page3
    Also a second batch file to find MKVs with NO English tag defined in the METADATA.

    It's a thread I started some time ago. Didn't want to be accused of duplicate posting.
    Last edited by pcspeak; 15th Feb 2018 at 16:11.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!