Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Outfile=MKVtoTS.exe
- #AutoIt3Wrapper_Res_Fileversion=1.1.0.0
- #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <ProgressConstants.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <Array.au3>
- #Include <File.au3>
- #include <Constants.au3>
- #Include <GuiEdit.au3>
- $BatchMode = False
- $TempPath = RegRead("HKCU\Software\MKVtoTS", "TempPath")
- If $TempPath = "" Then
- While 1
- $TempPath = InputBox("Need Temp Path", "Please enter the directory to store temp files (demuxed video and audio)", @TempDir)
- If $TempPath <> "" Then
- If FileExists($TempPath) Then
- RegWrite("HKCU\Software\MKVtoTS", "TempPath", "REG_SZ", $TempPath)
- ExitLoop
- Else
- MsgBox(262160,"Error","Path " & $TempPath & " does not exist")
- EndIf
- Else
- If @error = 1 Then
- Exit
- Else
- MsgBox(262160,"Error","Nothing entered")
- EndIf
- EndIf
- WEnd
- EndIf
- $LogPath = $TempPath & "\MKVtoTS.log"
- $eac3to = RegRead("HKCU\Software\MKVtoTS", "eac3toPath")
- If $eac3to = "" Then
- While 1
- ;$eac3to = InputBox("Need eac3to path", "Please enter the full path to eac3to.exe", @ProgramFilesDir)
- $eac3to = FileOpenDialog ( "Need eac3to path", @ProgramFilesDir, "exe files (*.exe)" , 1, "eac3to.exe")
- If $eac3to <> "" Then
- If FileExists($eac3to) and StringRight($eac3to,10) = "eac3to.exe" Then
- _Log("eac3to path looks valid, commiting to registry...")
- _Log("Setting eac3to path to: " & $eac3to)
- RegWrite("HKCU\Software\MKVtoTS", "eac3toPath", "REG_SZ", $eac3to)
- ExitLoop
- Else
- If Not FileExists($eac3to) Then
- MsgBox(262160,"Error","Path " & $eac3to & " does not exist")
- EndIf
- If Not StringRight($eac3to,10) = "eac3to.exe" Then
- MsgBox(262160,"Error","Path to " & $eac3to & " does not end in 'eac3to.exe'")
- EndIf
- EndIf
- Else
- If @error Then
- Exit
- Else
- MsgBox(262160,"Error","Nothing entered")
- EndIf
- EndIf
- WEnd
- EndIf
- $TSMuxer = RegRead("HKCU\Software\MKVtoTS", "TSMuxerPath")
- If $TSMuxer = "" or Not FileExists($TSMuxer) Then
- While 1
- $TSMuxer = FileOpenDialog ( "Need TSMuxer path", @ProgramFilesDir, "exe files (*.exe)" , 1, "tsMuxeR.exe")
- If $TSMuxer <> "" Then
- If FileExists($TSMuxer) and StringRight($TSMuxer,11) = "tsMuxeR.exe" Then
- _Log("TSMuxer path looks valid, commiting to registry...")
- _Log("Setting TSMuxer path to: " & $TSMuxer)
- RegWrite("HKCU\Software\MKVtoTS", "TSMuxerPath", "REG_SZ", $TSMuxer)
- ExitLoop
- Else
- If Not FileExists($TSMuxer) Then
- MsgBox(262160,"Error","Path " & $TSMuxer & " does not exist")
- EndIf
- If Not StringRight($eac3to,11) = "tsMuxeR.exe" Then
- MsgBox(262160,"Error","Path to " & $TSMuxer & " does not end in 'tsMuxeR.exe'")
- EndIf
- EndIf
- Else
- If @error Then
- Exit
- Else
- MsgBox(262160,"Error","Nothing entered")
- EndIf
- EndIf
- WEnd
- EndIf
- Dim $szDrive, $szDir, $szFName, $szExt
- If $CmdLine[0] <> 1 then
- $BatchMode = True
- $TotalJobs = 0
- $CurrJobNo = 0
- Else
- $SourceFile = $CmdLine[1]
- $TotalJobs = 1
- $CurrJobNo = 1
- EndIf
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("MKVtoTS", 629, 471, -1, -1, -1, $WS_EX_ACCEPTFILES)
- GUICtrlCreateLabel("Input Path:", 16, 16, 66, 17)
- GUICtrlCreateLabel("Output Path:", 16, 48, 66, 17)
- $Input_SourceFile = GUICtrlCreateInput("", 88, 14, 441, 21)
- If $BatchMode Then
- GUICtrlSetState ($Input_SourceFile, $GUI_DROPACCEPTED )
- EndIf
- $Input_TargetFile = GUICtrlCreateInput("", 88, 44, 441, 21)
- GUICtrlSetState(-1, $GUI_DISABLE)
- $Button_Browse = GUICtrlCreateButton("Browse...", 536, 12, 75, 25, $WS_GROUP)
- GUICtrlCreateLabel("Current File:", 16, 88, 60, 17)
- $Label_CurrentFile = GUICtrlCreateLabel("...", 96, 88, 381, 17)
- GUICtrlCreateLabel("Current Status:", 16, 112, 74, 17)
- $Label_Status = GUICtrlCreateLabel("Idle...", 96, 112, 374, 17)
- $Group_eac3to = GUICtrlCreateGroup("eac3to output", 16, 144, 593, 249)
- $Edit_log = GUICtrlCreateEdit("", 25, 165, 574, 217)
- $Group_TSMuxerOutput = GUICtrlCreateGroup("TSMuxer Output", 16, 400, 593, 57)
- $Progress1 = GUICtrlCreateProgress(24, 424, 518, 17)
- $Label_TSMuxerPct = GUICtrlCreateLabel("00 %", 552, 424, 35, 17, $SS_CENTER)
- $Label_Framerate = GUICtrlCreateLabel("Framerate:", 496, 112, 54, 17)
- $Input_Framerate = GUICtrlCreateInput("N/A", 560, 110, 49, 21)
- GUISetState(@sw_show)
- If Not $BatchMode Then
- $arrSourceFile = _PathSplit($SourceFile, $szDrive, $szDir, $szFName, $szExt)
- GUICtrlSetData($Input_SourceFile, $SourceFile)
- GUICtrlSetData($Label_CurrentFile, $SourceFile)
- GUICtrlSetData($Input_TargetFile, $szDrive & $szDir & $szFName & ".ts")
- GUICtrlSetState($Input_SourceFile, $GUI_DISABLE)
- GUICtrlSetState($Input_TargetFile, $GUI_DISABLE)
- _Remux($SourceFile, $szDrive & $szDir & $szFName & ".ts")
- Exit
- EndIf
- #EndRegion ### END Koda GUI section ###
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $GUI_EVENT_DROPPED
- $SelDir = @GUI_DragFile
- GUICtrlSetData ($Input_SourceFile, "")
- GUICtrlSetData ($Input_SourceFile, $SelDir)
- If $SelDir <> "" Then
- GUICtrlSetData($Input_SourceFile,$SelDir)
- GUICtrlSetData($Input_TargetFile,$SelDir)
- $arrInputFiles = _FileListToArray($SelDir, "*.mkv", 1)
- If @error = 4 Then
- MsgBox(262160,"TSMuxer","No MKV files found in selected directory")
- Else
- $TotalJobs = $arrInputFiles[0]
- For $x = 1 to $arrInputFiles[0]
- $CurrJobNo = $x
- $arrMovieName = StringSplit($arrInputFiles[$x], ".mkv", 1)
- $MovieName = $arrMovieName[1]
- $OutputPath = $SelDir & "\" & $MovieName & ".ts"
- GUICtrlSetData($Label_CurrentFile, $SelDir & "\" & $arrInputFiles[$x])
- _Remux($SelDir & "\" & $arrInputFiles[$x], $OutputPath)
- GUICtrlSetData($Progress1, 0)
- GUICtrlSetData($Label_TSMuxerPct, "00 %")
- GUICtrlSetData($Edit_log, "")
- GUICtrlSetData($Input_Framerate, "")
- Next
- GUICtrlSetData($Label_Status, "Completed " & $TotalJobs & " jobs.")
- EndIf
- EndIf
- Case $Button_Browse
- $SelDir = FileSelectFolder ( "TSMuxer", "", 2, @DesktopDir )
- If $SelDir <> "" Then
- GUICtrlSetData($Input_SourceFile,$SelDir)
- GUICtrlSetData($Input_TargetFile,$SelDir)
- $arrInputFiles = _FileListToArray($SelDir, "*.mkv", 1)
- If @error = 4 Then
- MsgBox(262160,"TSMuxer","No MKV files found in selected directory")
- Else
- $TotalJobs = $arrInputFiles[0]
- For $x = 1 to $arrInputFiles[0]
- $CurrJobNo = $x
- $arrMovieName = StringSplit($arrInputFiles[$x], ".mkv", 1)
- $MovieName = $arrMovieName[1]
- $OutputPath = $SelDir & "\" & $MovieName & ".ts"
- _Remux($SelDir & "\" & $arrInputFiles[$x], $OutputPath)
- GUICtrlSetData($Progress1, 0)
- GUICtrlSetData($Label_TSMuxerPct, "00 %")
- GUICtrlSetData($Edit_log, "")
- GUICtrlSetData($Input_Framerate, "")
- Next
- GUICtrlSetData($Label_Status, "Completed " & $TotalJobs & " jobs.")
- EndIf
- EndIf
- EndSwitch
- WEnd
- Func _Remux($SourceFile, $OutputFile)
- _Log("Starting remux job. Input file: " & $SourceFile)
- GUICtrlSetData($Label_Status, "(Job " & $CurrJobNo & "/" & $TotalJobs & ") Parsing file with eac3to...")
- $nbtstat = Run('"' & $eac3to & '" ' & '"' & $SourceFile & '"', $TempPath, @sw_hide,$STDERR_CHILD + $STDOUT_CHILD)
- $out = ''
- While 1
- $line = StdoutRead($nbtstat)
- If @error Then ExitLoop
- If $line <> '' Then
- $line = StringReplace($line, Chr(0x08), "")
- $line = StringReplace( $line, "-------------------------------------------------------------------------------", "")
- $line = StringReplace($line, " ", "")
- $out &= $line
- _GUICtrlEdit_AppendText($Edit_log, $line)
- Sleep(100)
- EndIf
- Wend
- _GUICtrlEdit_AppendText($Edit_log, "---------------------------------------------------------------------------------------------------")
- _GUICtrlEdit_AppendText($Edit_log, @CRLF & " ")
- $FinalString = StringReplace($out, Chr(0x08), "")
- _Log("eac3to analysis output:")
- _Log($FinalString)
- $AudioType = "AC3"
- $FixFrameRate = False
- $eac3toVidCmd = "1:vid.h264"
- If StringInStr($FinalString, "The video bitstream is encoded in a non-standard framerate.") Then
- _Log("The video bitstream is encoded in a non-standard framerate.")
- $FixFrameRate = True
- EndIf
- If StringInStr($FinalString, "2: AC3") Then
- $eac3toAudCmd = '2:aud.ac3 -KeepDialNorm'
- Else
- $eac3toAudCmd = '2:aud.ac3'
- EndIf
- If StringInStr($FinalString, "3: AC3") Then
- $eac3toAudCmd = '3:aud.ac3 -KeepDialNorm'
- EndIf
- If StringInStr($FinalString, "2: AC3") and StringInStr($FinalString, "3: AC3") Then
- Select
- Case StringInStr($FinalString, "2: AC3, English, 5.1 channels")
- $eac3toAudCmd = '2:aud.ac3 -KeepDialNorm'
- Case StringInStr($FinalString, "3: AC3, English, 5.1 channels")
- $eac3toAudCmd = '3:aud.ac3 -KeepDialNorm'
- Case StringInStr($FinalString, "2: AC3, German") and StringInStr($FinalString, "3: AC3, 2.0 channels")
- $eac3toAudCmd = '3:aud.ac3 -KeepDialNorm'
- Case StringInStr($FinalString, "2: AC3, German") and StringInStr($FinalString, "3: AC3, 5.1 channels")
- $eac3toAudCmd = '3:aud.ac3 -KeepDialNorm'
- Case Else
- $eac3toAudCmd = '2:aud.ac3 -KeepDialNorm'
- EndSelect
- EndIf
- If StringInStr($FinalString, "2: DTS") Then
- $eac3toAudCmd = '2:aud.dts'
- $AudioType = "DTS"
- EndIf
- $MetaLine1 = "MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbr --vbv-len=500"
- $MetaLine2 = ""
- $MetaLine3 = ""
- Select
- Case StringInStr($FinalString, ", 24p /1.001")
- $VideoFPS = "24"
- GUICtrlSetData($Input_Framerate, "23.976")
- $MetaLine2 = 'V_MPEG4/ISO/AVC, "' & $TempPath & '\vid.h264"' & ', fps=23.976, insertSEI, contSPS '
- If $AudioType = "AC3" Then
- $MetaLine3 = 'A_AC3, "' & $TempPath & '\aud.ac3"'
- Else
- $MetaLine3 = 'A_DTS, "' & $TempPath & '\aud.dts"'
- EndIf
- If $FixFrameRate Then
- _Log("Will change video framerate to 23.976")
- $eac3toVidCmd = $eac3toVidCmd & " -changeTo23.976"
- EndIf
- Case StringInStr($FinalString, ", 25p") or StringInStr($FinalString, ", 50i") or StringInStr($FinalString, ", 50p")
- $VideoFPS = "25"
- GUICtrlSetData($Input_Framerate, "25.00")
- $MetaLine2 = 'V_MPEG4/ISO/AVC, "' & $TempPath & '\vid.h264"' & ', fps=25, insertSEI, contSPS '
- If $AudioType = "AC3" Then
- $MetaLine3 = 'A_AC3, "' & $TempPath & '\aud.ac3"'
- Else
- $MetaLine3 = 'A_DTS, "' & $TempPath & '\aud.dts"'
- EndIf
- If $FixFrameRate Then
- _Log("Will change video framerate to 23.976")
- $eac3toVidCmd = $eac3toVidCmd & " -changeTo25.000"
- EndIf
- Case StringInStr($FinalString, ", 30p /1.001")
- GUICtrlSetData($Input_Framerate, "29.97")
- $MetaLine2 = 'V_MPEG4/ISO/AVC, "' & $TempPath & '\vid.h264"' & ', fps=29.970, insertSEI, contSPS '
- If $AudioType = "AC3" Then
- $MetaLine3 = 'A_AC3, "' & $TempPath & '\aud.ac3"'
- Else
- $MetaLine3 = 'A_DTS, "' & $TempPath & '\aud.dts"'
- EndIf
- Case Else
- MsgBox(262160,"TSMuxer Error","Unrecognised video framerate")
- Exit
- EndSelect
- $TSMuxerMetaFile = $TempPath & "\TSM.META"
- $MetFile = FileOpen($TSMuxerMetaFile, 2)
- If $MetFile = -1 Then
- MsgBox(262160,"Error","Error opening TSMuxer meta file for writing. Path: " & $TSMuxerMetaFile)
- Exit
- EndIf
- $WriteMetaFile = FileWriteLine($MetFile, $MetaLine1)
- FileWriteLine($MetFile, $MetaLine2)
- FileWriteLine($MetFile, $MetaLine3)
- FileClose($MetFile)
- $DemuxCmdLine = '"' & $eac3to & '" ' & '"' & $SourceFile & '" ' & $eac3toVidCmd & " " & $eac3toAudCmd
- _Log("eac3to command line: " & $DemuxCmdLine)
- _GUICtrlEdit_AppendText($Edit_log, "eac3to command line: " & $DemuxCmdLine)
- ;~ If Not StringInStr($FinalString,"1 video track, 1 audio track") Then
- ;~ MsgBox(0,"Debug", "More than 1 vid or aud stream")
- ;~ Exit
- ;~ EndIf
- GUICtrlSetData($Label_Status, "(Job " & $CurrJobNo & "/" & $TotalJobs & ") Demuxing video and audio streams...")
- $nbtstat = Run($DemuxCmdLine, $TempPath, @sw_hide,$STDERR_CHILD + $STDOUT_CHILD)
- $out = ''
- While 1
- $line = StdoutRead($nbtstat)
- If @error Then ExitLoop
- If $line <> '' Then
- $line = StringReplace($line, Chr(0x08), "")
- $line = StringReplace( $line, "-------------------------------------------------------------------------------", "")
- $line = StringReplace($line, " ", "")
- $out &= $line
- _GUICtrlEdit_AppendText($Edit_log, $line)
- Sleep(100)
- EndIf
- Wend
- ;$FinalString = StringReplace($out, Chr(0x08), "")
- ;GUICtrlSetData($Edit_log, $FinalString)
- GUICtrlSetData($Label_Status, "(Job " & $CurrJobNo & "/" & $TotalJobs & ") Muxing with TSMuxer...")
- _Log("TSMuxer command line: " & '"' & $TSMuxer & '" ' & '"' & $TSMuxerMetaFile & '" "' & $OutputFile & '"')
- ConsoleWrite(@ComSpec & " /c tsmuxer " & '"' & $TSMuxerMetaFile & '" "' & $OutputFile & '"' & @crlf)
- $TSMuxerMux = Run('"' & $TSMuxer & '" ' & '"' & $TSMuxerMetaFile & '" "' & $OutputFile & '"', @TempDir, @sw_hide, $STDERR_CHILD + $STDOUT_CHILD)
- $out = ''
- While 1
- $line = StdoutRead($TSMuxerMux)
- If @error Then ExitLoop
- If $line <> '' Then
- If StringInStr($line, "% complete") Then
- $arrSplit = StringSplit($line, "% complete", 1)
- $CurrPer = $arrSplit[1]
- If Not StringInStr($CurrPer, "Processed") then
- GUICtrlSetData($Progress1, $CurrPer)
- GUICtrlSetData($Label_TSMuxerPct, $CurrPer & "%")
- EndIf
- EndIf
- $out &= $line
- EndIf
- Sleep(100)
- Wend
- FileDelete($TempPath & "\aud.dts")
- FileDelete($TempPath & "\aud.ac3")
- FileDelete($TempPath & "\vid.h264")
- EndFunc
- Func _Log($LogString)
- FileWriteLine($LogPath, $LogString)
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement