Simple Batch Encoding GUI For HB CLI

Discussion of the cross-platform HandBrake command line interface
Forum rules
Activity Log is required for support requests. Posts without this will be locked! See Must Read: How To Get Questions Answered on These Forums for details

Forum Rules can be found here

Simple Batch Encoding GUI For HB CLI

Postby XGEOX » Sun May 03, 2009 7:49 pm

Hello folks,

I haven't posted on the HB forums before, but today I thought I'd pop in and share a small app I've been working on, in the hope that some of you will find it useful. Wasn't quite sure whether this should go into 'General' or 'CLI' discussion - apologies if this is the wrong place.

A few months ago I needed to batch-process a large number of films which I'd previously ripped to an external e-sata drive. As I was experimenting with the AutoIt3 language at the time, I decided to write a simplified GUI for the Windows Handbrake CLI which would allow me to set up an automated encode (and subsequently re-encode for various other devices with ease).

It worked very well, and I took some time this weekend to add some functionality and configuration options so that it could be used by others.

I've put it online in the hope that some of you will find it useful. Please note that this has not been extensively tested, and may not work well (or at all) on your system. Use at your own risk.

If you do decide to use it and come across a bug or a feature you think would be useful, please let me know. :)

Screenshot
Image

Download (Updated To Include Source - December 2009)
http://www.dbgw.co.uk/downloads/Batch%20Encoder%20v1-1.zip

Functionality
- Displays list of VOB folders within a specified directory (using folder names as film titles)
- Allows selection of multiple titles
- Provides list of encoding presets (based on latest HB set) which may also be adjusted or added to
- Allows automatic or manual cropping for the entire batch, or title-specific cropping values to be specified
- Sends each title to Handbrake CLI in sequence, encoding each one to the specified output directory
- Displays progress during the encode process

Requirements
Works on Windows XP - Should work on earlier versions and Vista as well
Requires Handbrake 0.9.3 CLI

Instructions
- Unzip/open the program (Won't work inside the zip)
- Select the location of your Handbrake CLI executable
- Select source directory (should contain various film folders with VOBs inside)
- Select destination/target directory (Note: existing files of the same name will be overwritten!!!)
(You should now see a list of titles, with 'cropping' and 'state' values shown for each)
- Select a preset to encode with
- Click 'Preview' to generate a single chapter preview of the selected films, or 'Encode' for entire films
- Allow the Handbrake to do its thing


Notes On Cropping
You can choose automatic, manual or title-specific cropping.

If the cropping fields are dimmed/disabled, cropping will be done automatically. Click 'Manual' to switch to manual mode and set the cropping values. These will be applied to all films in your batch. Click 'Automatic' to switch back to automatic cropping.

To specify cropping values for a particular title, create a file called 'VIDEO_CROP.TXT' in the VOB folder of the title you wish to crop.
Type your cropping values into this file in the format: T,B,L,R
These values will be shown in the films list (restart the app if it was open when you created the cropping file) if you've done it correctly. Note that the program will not check for the validity of cropping values - if they're out of range or otherwise invalid for the preset you've chosen, Handbrake may well crash; breaking the encoding process.

Using / Editing / Creating Presets
When you first run the app, it will generate a file called 'presets.cfg' within its parent directory. The format of this file is fairly self-explanatory. You can add, remove or tweak as many presets as you like inside this file.

I haven't tested all of the presets, so I'd suggest you run a preview encode of the films you wish to encode to determine that the quality and cropping are correct.



Thanks to the Handbrake Devs for a brilliant encoder!





Edit - (December 09):
I've posted the AutoIT source code for this application below, in the hope that it will be useful to other Handbrake users looking to make similar apps, or to change the functionality to meet their needs.

Please feel free to edit, re-post and otherwise use this code in any (non-commercial) manner. If you make improvements or new versions, please post back here and share them with other Handbrake users. I also welcome suggestions on improvements to the code - however I have no immediate plans to further develop this app (ie. to add new functionality).

If you already have the AutoIT package installed, simply open SciTE, create a blank file and paste in the code below. Save the file and press F5 to see the app run. You can then immediately start making changes.

I've updated the download link further up the page to contain the latest version and the source .au3 file (contents below), so you can alternatively download that instead.

Code: Select all
; Written by George Wilkins (george@dbgw.co.uk)
; Version 1.1 - April 2009
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <ListViewConstants.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <File.au3>
#include <Array.au3>

   ; Get Settings
   If FileExists("settings.cfg") Then
      
      ; Read Existing Settings File
      $File_Settings = FileOpen("settings.cfg", 0)
      
      $String_HandbrakePath = StringTrimLeft(FileReadLine($File_Settings), 16)
      $String_SourceDirectory = StringTrimLeft(FileReadLine($File_Settings), 18)
      $String_TargetDirectory = StringTrimLeft(FileReadLine($File_Settings), 19)
      
      FileClose($File_Settings)
      
   Else
      
      ; Create And Open Settings File For Writing
      $File_Settings = FileOpen("settings.cfg", 2)
      
      $String_HandbrakePath = "Not Set"
      $String_SourceDirectory = "Not Set"
      $String_TargetDirectory = "Not Set"
      
      FileWriteLine($File_Settings, "Handbrake CLI > " & $String_HandbrakePath)
      FileWriteLine($File_Settings, "Input Directory > " & $String_SourceDirectory)
      FileWriteLine($File_Settings, "Output Directory > " & $String_TargetDirectory)
      
      FileClose($File_Settings)
      
   EndIf
   
   ; Get Presets
   Dim $Array_PresetNames[1]
   Dim $Array_PresetExtensions[1]
   Dim $Array_PresetCommands[1]
   
   If FileExists("presets.cfg") Then
      
      ; Read Existing Presets File
      $File_Presets = FileOpen("presets.cfg", 0)
      
      While 1
         
         ; Read Line
         $String_Preset = FileReadLine($File_Presets)
         If @error = -1 Then ExitLoop
         
         ; Parse Line
         $String_Preset = StringReplace($String_Preset, " > ", ">")
         $Array_Preset = StringSplit($String_Preset, ">")
         _ArrayAdd($Array_PresetNames, $Array_Preset[1])
         _ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
         _ArrayAdd($Array_PresetCommands, $Array_Preset[3])
         
      Wend
      
      FileClose($File_Presets)
      
   Else
      
      ; Create And Open Presets File For Writing
      $File_Presets = FileOpen("presets.cfg", 2)
      
      FileWriteLine($File_Presets, "Normal > .mp4 > -e x264 -b 1500 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=2:bframes=2:me=umh")
      FileWriteLine($File_Presets, "Classic > .mp4 > -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4")
      FileWriteLine($File_Presets, "Animation > .mkv > -e x264 -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=5:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2:psy-rd=1,1:subme=9")
      FileWriteLine($File_Presets, "Constant Quality Rate > .mkv > -e x264 -q 0.600000023841858 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -x ref=3:mixed-refs:bframes=3:b-pyramid:weightb:filter=-2,-1:trellis=1:analyse=all:8x8dct:me=umh:subme=9:psy-rd=1,1")
      FileWriteLine($File_Presets, "Film > .mkv > -e x264 -b 1800 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:no-fast-pskip:psy-rd=1,1")
      FileWriteLine($File_Presets, "Television > .mkv > -e x264 -b 1300 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip=1:psy-rd=1,1")
      FileWriteLine($File_Presets, "Sony - PSP > .mp4 > -b 1024 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 368 -Y 208 -m")
      FileWriteLine($File_Presets, "Sony - PS3 > .mp4 > -e x264 -b 2500 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 --crop 0:0:0:0 -p -x level=41:me=umh")
      FileWriteLine($File_Presets, "Microsoft - XBox 360 > .mp4 > -e x264 -b 2000 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -p -x level=40:ref=2:mixed-refs:bframes=3:weightb:subme=9:direct=auto:b-pyramid:me=umh:analyse=all:no-fast-pskip:filter=-2,-1")
      FileWriteLine($File_Presets, "Apple - iPod > .mp4 > -e x264 -b 700 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -I -X 320 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1")
      FileWriteLine($File_Presets, "Apple - iPhone & iPod Touch > .mp4 > -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1")
      FileWriteLine($File_Presets, "Apple - TV > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -4 -X 960 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all")
      FileWriteLine($File_Presets, "Apple - Mac (QuickTime) > .mp4 > -e x264 -b 1800 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=3:mixed-refs:bframes=3:weightb:direct=auto:me=umh:subme=7:analyse=all:8x8dct:trellis=1:no-fast-pskip=1:psy-rd=1,1")
      FileWriteLine($File_Presets, "Apple - Universal > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -X 720 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:analyse=all:me=umh:no-fast-pskip=1")

      FileClose($File_Presets)
      
      ; Read New Presets File
      $File_Presets = FileOpen("presets.cfg", 0)
      
      While 1
         
         ; Read Line
         $String_Preset = FileReadLine($File_Presets)
         If @error = -1 Then ExitLoop
         
         ; Parse Line
         $String_Preset = StringReplace($String_Preset, " > ", ">")
         $Array_Preset = StringSplit($String_Preset, ">")
         _ArrayAdd($Array_PresetNames, $Array_Preset[1])
         _ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
         _ArrayAdd($Array_PresetCommands, $Array_Preset[3])
         
      Wend
      
      FileClose($File_Presets)
      
   EndIf
   
   
   
   
   
   ; Create Window
   GUICreate("Batch Film Encoder (Handbrake CLI Interface)", 480, 605)
   
   
   
   
   ; Settings Panel
   GUICtrlCreateGroup("Application Settings", 10, 10, 460, 115)
   
   ; Handbrake Path Button
    $Control_HandbrakePathButton = GUICtrlCreateButton("Locate Handbrake CLI", 20, 30, 140, 25)
   GUICtrlSetTip($Control_HandbrakePathButton, "Select the location of you Handbrake CLI executable", "Handbrake CLI Exectuable", 1, 1)
   
   $Label_HandbrakePath = GUICtrlCreateLabel($String_HandbrakePath, 170, 35, 290, 15)
   
   ; Source Directory Button
    $Control_SourceDirectoryButton = GUICtrlCreateButton("Select Source Directory", 20, 60, 140, 25)
   GUICtrlSetTip($Control_SourceDirectoryButton, "Select the directory in which your ripped VOBs folders are located.", "Source Directory", 1, 1)
   
   $Label_SourceDirectory = GUICtrlCreateLabel($String_SourceDirectory, 170, 65, 290, 15)

   ; Target Directory Button
    $Control_TargetDirectoryButton = GUICtrlCreateButton("Select Target Directory", 20, 90, 140, 25)
   GUICtrlSetTip($Control_TargetDirectoryButton, "Select the directory to which your encoded videos should be saved." & @CRLF & "Note that existing files with the same names will be overwritten.", "Target Directory", 1, 1)
   
   $Label_TargetDirectory = GUICtrlCreateLabel($String_TargetDirectory, 170, 95, 290, 15)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)




   
   ; Film Picker
   GUICtrlCreateGroup("Film Selection", 10, 135, 460, 300)
   
   $Control_FilmList = GUICtrlCreateListView("Film Title|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
   _GUICtrlListView_SetColumnWidth($Control_FilmList,0,260)
   _GUICtrlListView_SetColumnWidth($Control_FilmList,1,60)
   _GUICtrlListView_SetColumnWidth($Control_FilmList,2,60)

   ; Get And Add Films
   Func GetFilms($String_SourceDirectory)
      
      If $String_SourceDirectory <> "Not Set" Then
         
         $Array_Folders = _FileListToArray($String_SourceDirectory, "*", 2)
         For $Count = 1 To $Array_Folders[0]
            
            ; Check For Cropping File
            If FileExists($String_SourceDirectory & $Array_Folders[$Count] & "\VIDEO_CROP.TXT") Then
               
               ; Get Crop Data
               $String_CropValues = FileReadLine($String_SourceDirectory & $Array_Folders[$Count] & "\VIDEO_CROP.TXT")
               $Array_CropValues = StringSplit($String_CropValues, ",")
               $String_CropValues = $Array_CropValues[1] & ":" & $Array_CropValues[2] & ":" & $Array_CropValues[3] & ":" & $Array_CropValues[4]
               
            Else   
               
               $String_CropValues = "Auto"
            
            EndIf
            
            ; Check For Encoded File
            If $String_TargetDirectory <> "Not Set" Then
               
               If FileExists($String_TargetDirectory & $Array_Folders[$Count] & ".m4v") OR FileExists($String_TargetDirectory & $Array_Folders[$Count] & ".mkv") OR FileExists($String_TargetDirectory & $Array_Folders[$Count] & ".mp4") OR FileExists($String_TargetDirectory & $Array_Folders[$Count] & ".avi") OR FileExists($String_TargetDirectory & $Array_Folders[$Count] & ".ogm") Then
                  
                  $String_Status = "Encoded"
                  
               Else   
                  
                  If FileExists($String_TargetDirectory &  "Preview - " & $Array_Folders[$Count] & ".m4v") OR FileExists($String_TargetDirectory &  "Preview - " & $Array_Folders[$Count] & ".mkv") OR FileExists($String_TargetDirectory &  "Preview - " & $Array_Folders[$Count] & ".mp4") OR FileExists($String_TargetDirectory &  "Preview - " & $Array_Folders[$Count] & ".avi") OR FileExists($String_TargetDirectory &  "Preview - " & $Array_Folders[$Count] & ".ogm") Then
                     
                     $String_Status = "Previewed"
                  
                  Else
                  
                     $String_Status = "Not Encoded"
                  
                  EndIf
               
               EndIf
            
            Else
            
               $String_Status = ""
               $String_CropValues = ""
            
            EndIf
         
         
            ; Add To List
            GUICtrlCreateListViewItem($Array_Folders[$Count] & "|" & $String_CropValues & "|" & $String_Status, $Control_FilmList)
            
         Next
      
      EndIf
   
   EndFunc

   GetFilms($String_SourceDirectory)

   GUICtrlCreateGroup("", -99, -99, 1, 1)


   ; Presets Panel
   GUICtrlCreateGroup("Encoding Presets", 10, 445, 225, 50)
   
   $Control_PresetField = GUICtrlCreateCombo($Array_PresetNames[0], 20, 465, 205, 20)
   
   For $String_Preset In $Array_PresetNames
      
      GUICtrlSetData($Control_PresetField, $String_Preset, $String_Preset)
   
   Next
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)

   
   
   ; Cropping Panel
   GUICtrlCreateGroup("Cropping Settings", 245, 445, 225, 50)

   ; AutoCrop Override
   $Control_ManualCropButton = GUICtrlCreateButton("Manual", 255, 465, 90, 20)
   GUICtrlSetTip($Control_ManualCropButton, "Switch from automatic to manual cropping (for all selected titles)", "Adjust Cropping", 1, 1)
   
   ; Cropping Fields
   GUICtrlCreateLabel("T", 370, 452)
   GUICtrlCreateLabel("B", 395, 452)
   GUICtrlCreateLabel("L", 420, 452)
   GUICtrlCreateLabel("R", 445, 452)
   $Control_CropTopCheckbox = GUICtrlCreateInput("-", 365, 465, 18, 20) ; L T W H
   $Control_CropBottomCheckbox = GUICtrlCreateInput("-", 390, 465, 18, 20) ; L T W H
   $Control_CropLeftCheckbox = GUICtrlCreateInput("-", 415, 465, 18, 20) ; L T W H
   $Control_CropRightCheckbox = GUICtrlCreateInput("-", 440, 465, 18, 20) ; L T W H
   GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)
   
   
   
   
   ; Encoding Panel
   GUICtrlCreateGroup("Preview / Encode", 10, 505, 460, 90)
   
   ; Preview Button
    $Control_PreviewButton = GUICtrlCreateButton("Preview Selection", 20, 525, 160, 25)
   GUICtrlSetTip($Control_PreviewButton, "Encodes a single chapter for each film, allowing you to preview cropping and quality settings", "Preview Selection", 1, 1)
   
   ; Encode Button
    $Control_EncodeButton = GUICtrlCreateButton("Encode Selection", 190, 525, 270, 25)
   GUICtrlSetTip($Control_EncodeButton, "Encodes all of the selected films in full", "Encode Selection", 1, 1)

   ; Progress Bar
   $Output_ProgressLabel = GUICtrlCreateLabel("", 20, 555, 440, 15, 0x01)
   $Output_ProgressBar = GUICtrlCreateProgress(20, 575, 440, 10)
   
   ; Disable Progress Bar
   GUICtrlSetState($Output_ProgressBar, $GUI_DISABLE)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)
   
   
   

   ; Initialise Window
    GUISetState()

   $State_Looping = true
    While $State_Looping = true
      
      ; Handle User Action
        $State_GUI = GUIGetMsg()
        Select
      Case $State_GUI = $GUI_EVENT_CLOSE
         
            ; Close Program
            ProcessClose("HandBrakeCLI.exe")
                Exit
      
      
      
      Case $State_GUI = $Control_HandbrakePathButton Or $State_GUI = $Control_SourceDirectoryButton Or $State_GUI = $Control_TargetDirectoryButton
         
         
         If $State_GUI = $Control_HandbrakePathButton Then

            ; Temporarily Store Working Directory - God knows why it changes this. Took me hours to work out what was breaking the file write below!
            $String_WorkingDir = @WorkingDir
            
            ; Prompt For Executable
            $String_NewHandbrakePath = FileOpenDialog("Please locate your Handbrake CLI executable", @ProgramFilesDir, "All Files (*.*)")
            
            FileChangeDir($String_WorkingDir)
            
            If $String_NewHandbrakePath <> "" Then
               
               $String_HandbrakePath = String($String_NewHandbrakePath)

               GUICtrlSetData($Label_HandbrakePath, $String_HandbrakePath)
               
            EndIf

         EndIf
         
         
         If $State_GUI = $Control_SourceDirectoryButton Then

            ; Prompt For Directory
            $String_NewSourceDirectory = FileSelectFolder("Please locate your source directory", "")
            
            If $String_NewSourceDirectory <> "" Then
               
               $String_SourceDirectory   = $String_NewSourceDirectory

               If StringRight($String_SourceDirectory, 1) <> "\" Then
                  
                  $String_SourceDirectory = $String_SourceDirectory & "\"
                  
               EndIf
               
               GUICtrlSetData($Label_SourceDirectory, $String_SourceDirectory)
               
               ; Destroy And Recreate Film List
               GUICtrlDelete($Control_FilmList)
               $Control_FilmList = GUICtrlCreateListView("Film Title|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
               _GUICtrlListView_SetColumnWidth($Control_FilmList,0,260)
               _GUICtrlListView_SetColumnWidth($Control_FilmList,1,60)
               _GUICtrlListView_SetColumnWidth($Control_FilmList,2,60)

               GetFilms($String_SourceDirectory)
               
            EndIf
            
         EndIf


         If $State_GUI = $Control_TargetDirectoryButton Then

            ; Prompt For Directory
            $String_NewTargetDirectory = FileSelectFolder("Please locate your target directory", "")
            
            If $String_NewTargetDirectory <> "" Then
               
               $String_TargetDirectory = $String_NewTargetDirectory
               
               If StringRight($String_TargetDirectory, 1) <> "\" Then
                  
                  $String_TargetDirectory = $String_TargetDirectory & "\"
                  
               EndIf

               GUICtrlSetData($Label_TargetDirectory, $String_TargetDirectory)
               
               ; Destroy And Recreate Film List
               GUICtrlDelete($Control_FilmList)
               $Control_FilmList = GUICtrlCreateListView("Film Title|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
               _GUICtrlListView_SetColumnWidth($Control_FilmList,0,260)
               _GUICtrlListView_SetColumnWidth($Control_FilmList,1,60)
               _GUICtrlListView_SetColumnWidth($Control_FilmList,2,60)

               GetFilms($String_SourceDirectory)
            
            EndIf
         
         EndIf         
         
         ; Create And Open Settings File For Writing
         $File_Settings = FileOpen("settings.cfg", 2)
         
         FileWriteLine($File_Settings, "Handbrake CLI > " & GUICtrlRead($Label_HandbrakePath))
         FileWriteLine($File_Settings, "Input Directory > " & GUICtrlRead($Label_SourceDirectory))
         FileWriteLine($File_Settings, "Output Directory > " & GUICtrlRead($Label_TargetDirectory))
         
         FileClose($File_Settings)
      
         
         
      Case $State_GUI = $Control_EncodeButton OR $State_GUI = $Control_PreviewButton

         ; Get Selected Films
         $Integer_SelectedFilms = _GUICtrlListView_GetSelectedCount($Control_FilmList)
         $Array_SelectedFilms = _GUICtrlListView_GetSelectedIndices($Control_FilmList, True)
         
         ; Check Selection
         If $Integer_SelectedFilms < 1 Then

            MsgBox(64, "No Films Selected", "Please select at least one film to encode")
            
         ElseIf $String_HandbrakePath == "Not Set" Or $String_SourceDirectory == "Not Set" Or $String_TargetDirectory == "Not Set" Then
            
            MsgBox(64, "Settings Incomplete", "Please ensure you have correctly set your Handbrake CLI path, as well as your source and target directories")

         Else
               
            ; Disable Buttons
            GUICtrlSetState($Control_HandbrakePathButton, $GUI_DISABLE)
            GUICtrlSetState($Control_SourceDirectoryButton, $GUI_DISABLE)
            GUICtrlSetState($Control_TargetDirectoryButton, $GUI_DISABLE)
            
            GUICtrlSetState($Control_EncodeButton, $GUI_DISABLE)
            GUICtrlSetState($Control_PreviewButton, $GUI_DISABLE)
            GUICtrlSetState($Control_FilmList, $GUI_DISABLE)
            
            GUICtrlSetState($Control_PresetField, $GUI_DISABLE)
            
            GUICtrlSetState($Control_ManualCropButton, $GUI_DISABLE)
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)
            

            ; Set Test Status
            If $State_GUI = $Control_PreviewButton Then
               
               $String_PreviewSettings = " -c 1 "
               $String_PreviewName = "Preview - "
               
            Else
               
               $String_PreviewSettings = " "
               $String_PreviewName = ""
               
            EndIf

            
            ; Configure Selection Array
            For $Count = 1 To $Array_SelectedFilms[0]
            
               ; Replace Array Indicies With Titles
               $Array_SelectedFilms[$Count] = _GUICtrlListView_GetItemText($Control_FilmList, $Array_SelectedFilms[$Count], 0)
               
            Next
   
            
            
            ; Generate Display List
            $Count = 1
            Do
               
               ; Set Cropping Mode (Per Film)
               $String_CropMode = GUICtrlRead($Control_ManualCropButton)
               
               If $String_CropMode = "Automatic" Then
               
                  ; Cropping Is Manually Set (Yes, this is ass-backwards)
                  $Integer_CropTop = GUICtrlRead($Control_CropTopCheckbox)
                  $Integer_CropBottom = GUICtrlRead($Control_CropBottomCheckbox)
                  $Integer_CropLeft = GUICtrlRead($Control_CropLeftCheckbox)
                  $Integer_CropRight = GUICtrlRead($Control_CropRightCheckbox)
                  
                  $String_CropSettings = "--crop " & $Integer_CropTop & ":" & $Integer_CropBottom & ":" & $Integer_CropLeft & ":" & $Integer_CropRight
                  
               Else
                  
                  If FileExists($String_SourceDirectory & $Array_SelectedFilms[$Count] & "\VIDEO_CROP.TXT") Then
                     
                     ; Get Crop Data
                     $String_CropValues = FileReadLine($String_SourceDirectory & $Array_SelectedFilms[$Count] & "\VIDEO_CROP.TXT")
                     $Array_CropValues = StringSplit($String_CropValues, ",")
                     
                     ; Override With Crop.txt Values
                     $String_CropSettings = "--crop " & $Array_CropValues[1] & ":" & $Array_CropValues[2] & ":" & $Array_CropValues[3] & ":" & $Array_CropValues[4]
                     
                  Else
                     
                     ; Just Let The Encoder Work It Out
                     $String_CropSettings = ""
                  
                  EndIf
                  
               EndIf

               
               ; Determine Preset Selection
               $String_SelectedPreset = GUICtrlRead($Control_PresetField)
               $Index = 0
               For $String_Preset In $Array_PresetNames
                  
                  If $String_SelectedPreset = $String_Preset Then
                     
                     $Integer_Command = $Index
                     ExitLoop
                  
                  EndIf
                     
                  $Index = $Index + 1
                  
               Next
               
               $String_Command = $Array_PresetCommands[$Integer_Command]
               $String_Extension = $Array_PresetExtensions[$Integer_Command]
               
               
               
               ; Check For VIDEO_TS File
               If FileExists($String_SourceDirectory & $Array_SelectedFilms[$Count] & "\VIDEO_TS.IFO") Then
                  
                  $String_SourceFile = ""
               
               Else
                  
                  $String_SourceFile = ""
                  
                  ; Map Directory Contents
                  $Array_SourceFiles = _FileListToArray($String_SourceDirectory & $Array_SelectedFilms[$Count], "*.*", 1)
                  For $FileCount = 1 To $Array_SourceFiles[0]
                  
                     ; Find File Type
                     $String_PotentialFile = $Array_SourceFiles[$FileCount]
                     $Array_PotentialFile = StringSplit($String_PotentialFile, '.', 1)
                     $String_PotentialFileExtension = StringUpper($Array_PotentialFile[$Array_PotentialFile[0]])
                     
                     ; Compare With Known Types
                     If $String_PotentialFileExtension == "VOB" Or $String_PotentialFileExtension == "MOV" Or $String_PotentialFileExtension == "MP4" Or $String_PotentialFileExtension == "M4A" Or $String_PotentialFileExtension == "3GP" Or $String_PotentialFileExtension == "3G2" Or $String_PotentialFileExtension == "MJ2" Or $String_PotentialFileExtension == "MP2" Or $String_PotentialFileExtension == "MPEG" Or $String_PotentialFileExtension == "MPG" Or $String_PotentialFileExtension == "AVI" Then
                        
                        ; Assign To Encoder
                        $String_SourceFile = $String_PotentialFile
                        
                        ExitLoop
                        
                     EndIf
                     
                  Next

                  If $String_SourceFile == "" Then
                     
                     MsgBox(64, "Error", "Could not locate a VOB or video file to encode in this directory")
                     
                  EndIf

                  ; Append Directory Slash
                  $String_SourceFile = "\" & $String_SourceFile
                  
               EndIf

               
            

               ;MsgBox(64, "Command", $String_HandbrakePath & " -i """& $String_SourceDirectory & $Array_SelectedFilms[$Count] & $String_SourceFile & """ -o """ & $String_TargetDirectory & $String_PreviewName & $Array_SelectedFilms[$Count] & $String_Extension & """ -L " & $String_PreviewSettings & "" & $String_Command & " " & $String_CropSettings)

                  
               ; Encode Entry
               $State_HandBrakeCLI = Run($String_HandbrakePath & " -i """& $String_SourceDirectory & $Array_SelectedFilms[$Count] & $String_SourceFile & """ -o """ & $String_TargetDirectory & $String_PreviewName & $Array_SelectedFilms[$Count] & $String_Extension & """ -L " & $String_PreviewSettings & "" & $String_Command & " " & $String_CropSettings, "", @SW_HIDE, 2)
               
               ; Wait For Current Processes To Complete
               While ProcessExists("HandBrakeCLI.exe") <> 0
                  
                  ; Get Output
                  $String_HandbrakeOutput = StdoutRead($State_HandBrakeCLI)
                  $Array_HandbrakeOutput = StringSplit($String_HandbrakeOutput, @CR, 1)
                  $String_HandbrakeOutput = $Array_HandbrakeOutput[$Array_HandbrakeOutput[0]]
                  
                  ; Format Handbrake Output
                  ; Encoding: task 2 of 3, 62.71 % (130.18 fps, avg 121.24 fps, ETA 00h00m15s)
                  $Array_HandbrakeOutput = StringSplit($String_HandbrakeOutput, " % ", 1)
                  
                  $Float_Progress = $Array_HandbrakeOutput[1]
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, " %", "")
                  $Float_Progress = StringReplace($Float_Progress, "%", "")
                  
                  If StringIsFloat($Float_Progress) Then
                     
                     $String_Step = $Array_HandbrakeOutput[1]
                     $String_Step = StringReplace($String_Step, "Encoding: task", "Step")
                     $String_Step = StringLeft($String_Step, 11)
                     
                     if $Array_HandbrakeOutput[0] > 1 Then
                        
                        $String_Time = $Array_HandbrakeOutput[2]
                        $String_Time = StringRight($String_Time, 10)
                        $String_Time = StringReplace($String_Time, ")", "")
                        $String_Time = StringReplace($String_Time, "s", " Seconds")
                        $String_Time = StringReplace($String_Time, "h", " Hours ")
                        $String_Time = StringReplace($String_Time, "m", " Minutes ")
                        
                        $String_Time = StringReplace($String_Time, "00", "0")
                        
                        $String_Time = StringReplace($String_Time, "0 Hours 0 Minutes ", "")
                        $String_Time = StringReplace($String_Time, "0 Hours", " ")
                        $String_Time = StringReplace($String_Time, " 0 Minutes ", " ")
                     
                     Else
                     
                        $String_Time = "Estimating Time..."
                        
                     EndIf
                     
                     $String_Notice = $Array_SelectedFilms[$Count] & " - " & $String_Step & " - " & $String_Time
                     
                  Else
                  
                     $String_Notice = $Array_SelectedFilms[$Count] & " - (" & $Float_Progress & ")"
                  
                  EndIf
                     
                  ; Display Status
                  GUICtrlSetData($Output_ProgressLabel, $String_Notice)
                  GUICtrlSetData($Output_ProgressBar, $Float_Progress)
                  
                  Sleep(1000)
                  
               WEnd
               
               ; Reset Output
               GUICtrlSetData($Output_ProgressLabel, "")
               GUICtrlSetData($Output_ProgressBar, "")

               ; Move On
               $Count = $Count + 1
               
            Until $Count = $Integer_SelectedFilms + 1
         
         
            ; Plural Check
            If $Integer_SelectedFilms == 1 Then
               
               $Plural = "";
            
            Else
            
               $Plural = "s";
            
            EndIf
         
            
            ; Notify User Of Completion
            If $State_GUI = $Control_PreviewButton Then
               
               MsgBox(64, "Encoding Complete", $Integer_SelectedFilms & " Preview" & $Plural & " Encoded")
               
            Else
               
               MsgBox(64, "Encoding Complete", $Integer_SelectedFilms & " Film" & $Plural & " Encoded")
               
            EndIf
            
            
            
            ; Destroy And Recreate Film List
            GUICtrlDelete($Control_FilmList)
            $Control_FilmList = GUICtrlCreateListView("Film Title|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
            _GUICtrlListView_SetColumnWidth($Control_FilmList,0,260)
            _GUICtrlListView_SetColumnWidth($Control_FilmList,1,60)
            _GUICtrlListView_SetColumnWidth($Control_FilmList,2,60)

            GetFilms($String_SourceDirectory)
            
            
            ; Enable Buttons
            GUICtrlSetState($Control_HandbrakePathButton, $GUI_ENABLE)
            GUICtrlSetState($Control_SourceDirectoryButton, $GUI_ENABLE)
            GUICtrlSetState($Control_TargetDirectoryButton, $GUI_ENABLE)
            
            GUICtrlSetState($Control_EncodeButton, $GUI_ENABLE)
            GUICtrlSetState($Control_PreviewButton, $GUI_ENABLE)
            
            GUICtrlSetState($Control_PresetField, $GUI_ENABLE)
            
            GUICtrlSetState($Control_ManualCropButton, $GUI_ENABLE)
            
            If GUICtrlRead($Control_ManualCropButton) == "Automatic" Then
               
               GUICtrlSetState($Control_CropTopCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropBottomCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropLeftCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropRightCheckbox, $GUI_ENABLE)
               
            EndIf
         
         EndIf
      
      

      Case $State_GUI = $Control_ManualCropButton
         
         $String_CropMode = GUICtrlRead($Control_ManualCropButton)
         
         ; Get Cropping Settings
         If $String_CropMode = "Manual" Then
            
            GUICtrlSetData($Control_ManualCropButton, "Automatic")
            GUICtrlSetTip($Control_ManualCropButton, "Allow Handbrake to choose suitable cropping automatically", "Set Automatically", 1, 1)
            
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_ENABLE)
            
            GUICtrlSetData($Control_CropTopCheckbox, "0")
            GUICtrlSetData($Control_CropBottomCheckbox, "0")
            GUICtrlSetData($Control_CropLeftCheckbox, "0")
            GUICtrlSetData($Control_CropRightCheckbox, "0")
            
         Else
            
            GUICtrlSetData($Control_ManualCropButton, "Manual")
            GUICtrlSetTip($Control_ManualCropButton, "Switch from automatic to manual cropping", "Adjust Cropping", 1, 1)
            
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)

            GUICtrlSetData($Control_CropTopCheckbox, "-")
            GUICtrlSetData($Control_CropBottomCheckbox, "-")
            GUICtrlSetData($Control_CropLeftCheckbox, "-")
            GUICtrlSetData($Control_CropRightCheckbox, "-")
         
         EndIf

            
        EndSelect
    WEnd

Exit
Last edited by XGEOX on Sat Dec 05, 2009 9:32 pm, edited 1 time in total.
XGEOX
 
Posts: 5
Joined: Sun May 03, 2009 6:03 pm

 

Re: Simple Batch Encoding GUI For HB CLI

Postby brendo234 » Wed May 13, 2009 7:08 am

I just sent you a private message, but I thought I'd also add a feature request on this thread...

I love the idea for the program, however, when I downloaded it and tried to use it, I realized that it only supports DVD rips and VOB files.

I was so excited when I found a program that would automate the batching of video files, however, I was really hoping that it would support the batching of MPG or AVI files.

Our video camera creates very large MPG files, so I use handbrake to encode/compress them... it usually takes it down to 20-30% of the original size with no noticable loss in audio/video quality.

If you could add support to your software for the batch conversion of any type of video file inside the source folder, that would be great!!!

Bug report:
Trying to cancel out of the folder selection doesn't work, the selection screen kept popping back up on me. I'm using Windows 7 RC1.
brendo234
 
Posts: 1
Joined: Wed May 13, 2009 7:00 am

Re: Simple Batch Encoding GUI For HB CLI

Postby alexn16 » Wed Nov 04, 2009 7:21 pm

Greetings,

How are you returning the progress values from the cli to your gui?

I'm writing my own specific app that uses handbrakecli.

Thanks.
alexn16
 
Posts: 2
Joined: Wed Nov 04, 2009 7:16 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby s55 » Wed Nov 04, 2009 8:32 pm

He'll be redirecting the standard output into his app.

You should note, using the 0.9.3 cygwin handbrakecli and piping standard output into .NET will likely cause video corruption problems.
The MinGW handbrakecli from the snapshots does not appear to exhibit this issue.
s55
Developer
 
Posts: 4353
Joined: Sun Dec 24, 2006 2:05 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby alexn16 » Fri Nov 06, 2009 7:04 pm

I guess I'm more interested in seeing some code that demonstrate how to do this. Pretty sure it uses Regex, but not clear how...
alexn16
 
Posts: 2
Joined: Wed Nov 04, 2009 7:16 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby kiwijunglist » Sat Nov 14, 2009 5:55 am

I would also love for this to support other video files.
I have a directory full of .ts files recorded by mediaportal that i want to batch encode.

Regards
Kiwi
kiwijunglist
 
Posts: 9
Joined: Fri Nov 13, 2009 12:10 am

Re: Simple Batch Encoding GUI For HB CLI

Postby norjms » Tue Dec 01, 2009 12:12 pm

Sent you a PM btw awesome work on this app. This really what batch encoding should be.
norjms
 
Posts: 5
Joined: Wed Nov 25, 2009 11:24 am

Re: Simple Batch Encoding GUI For HB CLI

Postby XGEOX » Tue Dec 01, 2009 9:14 pm

Hello All,
Thank you for your comments and feedback. My apologies for not responding sooner.

I've had a number of requests for all or part of the source code for this application, so I'll be posting it here in the next few days (after a little tidying up).
The AutoIT code is very simple to understand and easy to compile; so making tweaks shouldn't be a problem for most users. The code is commented.

I did create version of this application with support for more source formats. I didn't however use it a great deal. If I can find the source for this on one of my backup drives, I will post it as well.

Please note that the source I will be posting has not been updated for 0.9.4. It may or may not work with the new CLI.
XGEOX
 
Posts: 5
Joined: Sun May 03, 2009 6:03 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby norjms » Thu Dec 03, 2009 1:14 am

Waiting for this like Christmas been trying to do what your program does for sometime now. I already have another app I want to tie it into. I would be intrested in the additional sources as well. Re-encoding files incompatible file for my iphone sucks lol
norjms
 
Posts: 5
Joined: Wed Nov 25, 2009 11:24 am

Re: Simple Batch Encoding GUI For HB CLI

Postby XGEOX » Sat Dec 05, 2009 9:35 pm

I've just updated the first post to include the source code. I hope to also post code from the alternate version of the app (which allows non-vob input) fairly soon.

Hope this is helpful,
George
XGEOX
 
Posts: 5
Joined: Sun May 03, 2009 6:03 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby jkbc » Mon Dec 07, 2009 6:06 am

XGEOX wrote:I've just updated the first post to include the source code. I hope to also post code from the alternate version of the app (which allows non-vob input) fairly soon.

Hope this is helpful,
George



Appreciate all your work on this!
jkbc
 
Posts: 64
Joined: Tue Dec 01, 2009 12:04 am

Re: Simple Batch Encoding GUI For HB CLI

Postby DickyP » Thu Dec 17, 2009 10:05 am

Love the idea of this but having upgraded to 0.9.4 and having seen the rider that it may or may not work with 0.9.4 I gave it a whirl.

Running the .exe I got.

"Line -1:

Error: Array variable has incorrect number of subscripts or dimension range exceeded."

Running the script I got:

"Line 103(File: C:\Program Files\HandBrake\BatchEncoder\Video Encode - Presets - Batch - v1-1.au3):

_ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
_ArrayAdd($Array_PresetExtensions, ^ERROR

Error: Array variable has incorrect number of subscripts or dimension range exceeded."
DickyP
 
Posts: 3
Joined: Wed Dec 02, 2009 9:29 am

Re: Simple Batch Encoding GUI For HB CLI

Postby XGEOX » Sat Jan 09, 2010 12:38 am

[Censored] wrote:Running the script I got:

"Line 103(File: C:\Program Files\HandBrake\BatchEncoder\Video Encode - Presets - Batch - v1-1.au3):

_ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
_ArrayAdd($Array_PresetExtensions, ^ERROR

Error: Array variable has incorrect number of subscripts or dimension range exceeded."


Hi [Censored],

Lines 41 > 110 handle the loading (and creation) of a presets file called presets.cfg, which resides in the same directory as the batch executable.

When the app loads, it checks for the presence of this file. If it exists, the app loads each line (representing a single preset) into a presets array. If it doesn't exist, it creates the file first (from a list of default presets hard-coded into the app).

For some reason the presets.cfg file is not being created correctly on your computer.

You could try creating the file manually using notepad:
Simply create a new text file with the following contents, and save it as presets.cfg under C:\Program Files\HandBrake\BatchEncoder\

Code: Select all
Normal > .mp4 > -e x264 -b 1500 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=2:bframes=2:me=umh
Classic > .mp4 > -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4
Animation > .mkv > -e x264 -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=5:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2:psy-rd=1,1:subme=9
Constant Quality Rate > .mkv > -e x264 -q 0.600000023841858 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -x ref=3:mixed-refs:bframes=3:b-pyramid:weightb:filter=-2,-1:trellis=1:analyse=all:8x8dct:me=umh:subme=9:psy-rd=1,1
Film > .mkv > -e x264 -b 1800 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:no-fast-pskip:psy-rd=1,1
Television > .mkv > -e x264 -b 1300 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip=1:psy-rd=1,1
Sony - PSP > .mp4 > -b 1024 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 368 -Y 208 -m
Sony - PS3 > .mp4 > -e x264 -b 2500 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 --crop 0:0:0:0 -p -x level=41:me=umh
Microsoft - XBox 360 > .mp4 > -e x264 -b 2000 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -p -x level=40:ref=2:mixed-refs:bframes=3:weightb:subme=9:direct=auto:b-pyramid:me=umh:analyse=all:no-fast-pskip:filter=-2,-1
Apple - iPod > .mp4 > -e x264 -b 700 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -I -X 320 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1
Apple - iPhone & iPod Touch > .mp4 > -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1
Apple - TV > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -4 -X 960 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all
Apple - Mac (QuickTime) > .mp4 > -e x264 -b 1800 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=3:mixed-refs:bframes=3:weightb:direct=auto:me=umh:subme=7:analyse=all:8x8dct:trellis=1:no-fast-pskip=1:psy-rd=1,1
Apple - Universal > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -X 720 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:analyse=all:me=umh:no-fast-pskip=1


The app should load these presets into a drop-down menu, from which you can select the one you want to use.

Please note that you'll need to update these presets to match the new default presets for 0.9.4 (or create your own).

Hope this helps,
George
XGEOX
 
Posts: 5
Joined: Sun May 03, 2009 6:03 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby XGEOX » Sat Jan 09, 2010 1:06 am

Whilst I'm here, please find the promised 'alternate' version of the app below.

This one transcodes various video files into another format, rather than encoding folders of VOBs.

This is pretty experimental, as it was created for a forum member (I have no use for it myself, as I always encode from my original VOB rips).

I can't offer any support on this version. It has not been tested at all with 0.9.4

Code: Select all

; Written by George Wilkins (george@dbgw.co.uk)
; Version 1.2 - May 2009
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <ListViewConstants.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <File.au3>
#include <Array.au3>

   ; Get Settings
   If FileExists("settings.cfg") Then
      
      ; Read Existing Settings File
      $File_Settings = FileOpen("settings.cfg", 0)
      
      $String_HandbrakePath = StringTrimLeft(FileReadLine($File_Settings), 16)
      $String_SourceDirectory = StringTrimLeft(FileReadLine($File_Settings), 18)
      $String_TargetDirectory = StringTrimLeft(FileReadLine($File_Settings), 19)
      
      FileClose($File_Settings)
      
   Else
      
      ; Create And Open Settings File For Writing
      $File_Settings = FileOpen("settings.cfg", 2)
      
      $String_HandbrakePath = "Not Set"
      $String_SourceDirectory = "Not Set"
      $String_TargetDirectory = "Not Set"
      
      FileWriteLine($File_Settings, "Handbrake CLI > " & $String_HandbrakePath)
      FileWriteLine($File_Settings, "Input Directory > " & $String_SourceDirectory)
      FileWriteLine($File_Settings, "Output Directory > " & $String_TargetDirectory)
      
      FileClose($File_Settings)
      
   EndIf
   
   ; Get Presets
   Dim $Array_PresetNames[1]
   Dim $Array_PresetExtensions[1]
   Dim $Array_PresetCommands[1]
   
   If FileExists("presets.cfg") Then
      
      ; Read Existing Presets File
      $File_Presets = FileOpen("presets.cfg", 0)
      
      While 1
         
         ; Read Line
         $String_Preset = FileReadLine($File_Presets)
         If @error = -1 Then ExitLoop
         
         ; Parse Line
         $String_Preset = StringReplace($String_Preset, " > ", ">")
         $Array_Preset = StringSplit($String_Preset, ">")
         _ArrayAdd($Array_PresetNames, $Array_Preset[1])
         _ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
         _ArrayAdd($Array_PresetCommands, $Array_Preset[3])
         
      Wend
      
      FileClose($File_Presets)
      
   Else
      
      ; Create And Open Presets File For Writing
      $File_Presets = FileOpen("presets.cfg", 2)
      
      FileWriteLine($File_Presets, "Normal > .mp4 > -e x264 -b 1500 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=2:bframes=2:me=umh")
      FileWriteLine($File_Presets, "Classic > .mp4 > -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4")
      FileWriteLine($File_Presets, "Animation > .mkv > -e x264 -b 1000 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=5:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2:psy-rd=1,1:subme=9")
      FileWriteLine($File_Presets, "Constant Quality Rate > .mkv > -e x264 -q 0.600000023841858 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -x ref=3:mixed-refs:bframes=3:b-pyramid:weightb:filter=-2,-1:trellis=1:analyse=all:8x8dct:me=umh:subme=9:psy-rd=1,1")
      FileWriteLine($File_Presets, "Film > .mkv > -e x264 -b 1800 -a 1 -E ac3 -B 160 -R Auto -6 auto -f mkv -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:no-fast-pskip:psy-rd=1,1")
      FileWriteLine($File_Presets, "Television > .mkv > -e x264 -b 1300 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mkv --detelecine --decomb -p -m -2 -T -x ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip=1:psy-rd=1,1")
      FileWriteLine($File_Presets, "Sony - PSP > .mp4 > -b 1024 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 368 -Y 208 -m")
      FileWriteLine($File_Presets, "Sony - PS3 > .mp4 > -e x264 -b 2500 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 --crop 0:0:0:0 -p -x level=41:me=umh")
      FileWriteLine($File_Presets, "Microsoft - XBox 360 > .mp4 > -e x264 -b 2000 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -p -x level=40:ref=2:mixed-refs:bframes=3:weightb:subme=9:direct=auto:b-pyramid:me=umh:analyse=all:no-fast-pskip:filter=-2,-1")
      FileWriteLine($File_Presets, "Apple - iPod > .mp4 > -e x264 -b 700 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 -I -X 320 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1")
      FileWriteLine($File_Presets, "Apple - iPhone & iPod Touch > .mp4 > -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1")
      FileWriteLine($File_Presets, "Apple - TV > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -4 -X 960 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all")
      FileWriteLine($File_Presets, "Apple - Mac (QuickTime) > .mp4 > -e x264 -b 1800 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -p -m -2 -T -x ref=3:mixed-refs:bframes=3:weightb:direct=auto:me=umh:subme=7:analyse=all:8x8dct:trellis=1:no-fast-pskip=1:psy-rd=1,1")
      FileWriteLine($File_Presets, "Apple - Universal > .mp4 > -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -X 720 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:analyse=all:me=umh:no-fast-pskip=1")

      FileClose($File_Presets)
      
      ; Read New Presets File
      $File_Presets = FileOpen("presets.cfg", 0)
      
      While 1
         
         ; Read Line
         $String_Preset = FileReadLine($File_Presets)
         If @error = -1 Then ExitLoop
         
         ; Parse Line
         $String_Preset = StringReplace($String_Preset, " > ", ">")
         $Array_Preset = StringSplit($String_Preset, ">")
         _ArrayAdd($Array_PresetNames, $Array_Preset[1])
         _ArrayAdd($Array_PresetExtensions, $Array_Preset[2])
         _ArrayAdd($Array_PresetCommands, $Array_Preset[3])
         
      Wend
      
      FileClose($File_Presets)
      
   EndIf
   
   
   
   
   
   ; Create Window
   GUICreate("Batch Video Encoder (Handbrake CLI Interface)", 480, 605)
   
   
   
   
   ; Settings Panel
   GUICtrlCreateGroup("Application Settings", 10, 10, 460, 115)
   
   ; Handbrake Path Button
    $Control_HandbrakePathButton = GUICtrlCreateButton("Locate Handbrake CLI", 20, 30, 140, 25)
   GUICtrlSetTip($Control_HandbrakePathButton, "Select the location of you Handbrake CLI executable", "Handbrake CLI Exectuable", 1, 1)
   
   $Label_HandbrakePath = GUICtrlCreateLabel($String_HandbrakePath, 170, 35, 290, 15)
   
   ; Source Directory Button
    $Control_SourceDirectoryButton = GUICtrlCreateButton("Select Source Directory", 20, 60, 140, 25)
   GUICtrlSetTip($Control_SourceDirectoryButton, "Select the directory in which your ripped VOBs folders are located.", "Source Directory", 1, 1)
   
   $Label_SourceDirectory = GUICtrlCreateLabel($String_SourceDirectory, 170, 65, 290, 15)

   ; Target Directory Button
    $Control_TargetDirectoryButton = GUICtrlCreateButton("Select Target Directory", 20, 90, 140, 25)
   GUICtrlSetTip($Control_TargetDirectoryButton, "Select the directory to which your encoded videos should be saved." & @CRLF & "Note that existing files with the same names will be overwritten.", "Target Directory", 1, 1)
   
   $Label_TargetDirectory = GUICtrlCreateLabel($String_TargetDirectory, 170, 95, 290, 15)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)




   
   ; Film Picker
   GUICtrlCreateGroup("Video Selection", 10, 135, 460, 300)

   $Control_VideoList = GUICtrlCreateListView("Video File|Extension|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
   _GUICtrlListView_SetColumnWidth($Control_VideoList,0,190)
   _GUICtrlListView_SetColumnWidth($Control_VideoList,1,70)
   _GUICtrlListView_SetColumnWidth($Control_VideoList,2,70)
   _GUICtrlListView_SetColumnWidth($Control_VideoList,3,60)
      
   ; Get And Add Videos
   Func GetVideos($String_SourceDirectory)
      
      If $String_SourceDirectory <> "Not Set" Then

         ; Map Directory Contents
         $Array_Files = _FileListToArray($String_SourceDirectory, "*.*", 1)
         
         If $Array_Files = "" Then
            
            ; No Files Found
            MsgBox(64, "Directory Is Empty", "Please select another directory")
            $State_GUI = $Control_SourceDirectoryButton
            
         Else
            
            For $Count = 1 To $Array_Files[0]
            
               ; Find File Type
               $Array_File = StringSplit($Array_Files[$Count], '.', 1)
               $String_FileName = $Array_Files[$Count]
               $String_FileTitle = $Array_File[1]
               $String_FileExtension = $Array_File[$Array_File[0]]
               
               ; Compare With Known Types
               If StringUpper($String_FileExtension) == "VOB" Or StringUpper($String_FileExtension) == "MOV" Or StringUpper($String_FileExtension) == "MP4" Or StringUpper($String_FileExtension) == "M4A" Or StringUpper($String_FileExtension) == "3GP" Or StringUpper($String_FileExtension) == "3G2" Or StringUpper($String_FileExtension) == "MJ2" Or StringUpper($String_FileExtension) == "MP2" Or StringUpper($String_FileExtension) == "MPEG" Or StringUpper($String_FileExtension) == "MPG" Or StringUpper($String_FileExtension) == "AVI" Then
                  
                  ; Check For Cropping File
                  If FileExists($String_SourceDirectory & $Array_Files[$Count] & "\VIDEO_CROP.TXT") Then
                     
                     ; Get Crop Data
                     $String_CropValues = FileReadLine($String_SourceDirectory & $Array_Files[$Count] & "\VIDEO_CROP.TXT")
                     $Array_CropValues = StringSplit($String_CropValues, ",")
                     $String_CropValues = $Array_CropValues[1] & ":" & $Array_CropValues[2] & ":" & $Array_CropValues[3] & ":" & $Array_CropValues[4]
                     
                  Else   
                     
                     $String_CropValues = "Auto"
                  
                  EndIf
                           
                  ; Check For Encoded File
                  If $String_TargetDirectory <> "Not Set" Then
                     
                     If FileExists($String_FileTitle & ".m4v") OR FileExists($String_FileTitle & ".mkv") OR FileExists($String_FileTitle & ".mp4") OR FileExists($String_FileTitle & ".avi") OR FileExists($String_FileTitle & ".ogm") Then
                        
                        $String_Status = "Encoded"
                        
                     Else   
                        
                        $String_Status = "Not Encoded"
                     
                     EndIf
                  
                  Else
                  
                     $String_Status = ""
                     $String_CropValues = ""
                  
                  EndIf
                  
                  ; Add To List
                  GUICtrlCreateListViewItem($String_FileTitle & "|" & $String_FileExtension & "|" & $String_CropValues & "|" & $String_Status, $Control_VideoList)
                  
               EndIf
               
            Next
         
         EndIf
      
      EndIf
   
   EndFunc

   GetVideos($String_SourceDirectory)

   GUICtrlCreateGroup("", -99, -99, 1, 1)


   ; Presets Panel
   GUICtrlCreateGroup("Encoding Presets", 10, 445, 225, 50)
   
   $Control_PresetField = GUICtrlCreateCombo($Array_PresetNames[0], 20, 465, 205, 20)
   
   For $String_Preset In $Array_PresetNames
      
      GUICtrlSetData($Control_PresetField, $String_Preset, $String_Preset)
   
   Next
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)

   
   
   ; Cropping Panel
   GUICtrlCreateGroup("Cropping Settings", 245, 445, 225, 50)

   ; AutoCrop Override
   $Control_ManualCropButton = GUICtrlCreateButton("Manual", 255, 465, 90, 20)
   GUICtrlSetTip($Control_ManualCropButton, "Switch from automatic to manual cropping (for all selected titles)", "Adjust Cropping", 1, 1)
   
   ; Cropping Fields
   GUICtrlCreateLabel("T", 370, 452)
   GUICtrlCreateLabel("B", 395, 452)
   GUICtrlCreateLabel("L", 420, 452)
   GUICtrlCreateLabel("R", 445, 452)
   $Control_CropTopCheckbox = GUICtrlCreateInput("-", 365, 465, 18, 20) ; L T W H
   $Control_CropBottomCheckbox = GUICtrlCreateInput("-", 390, 465, 18, 20) ; L T W H
   $Control_CropLeftCheckbox = GUICtrlCreateInput("-", 415, 465, 18, 20) ; L T W H
   $Control_CropRightCheckbox = GUICtrlCreateInput("-", 440, 465, 18, 20) ; L T W H
   GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
   GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)
   
   
   
   
   ; Encoding Panel
   GUICtrlCreateGroup("Start Encode", 10, 505, 460, 90)

   ; Encode Button
    $Control_EncodeButton = GUICtrlCreateButton("Encode Selection", 20, 525, 440, 25)
   GUICtrlSetTip($Control_EncodeButton, "Encodes all of the selected videos", "Encode Selection", 1, 1)

   ; Progress Bar
   $Output_ProgressLabel = GUICtrlCreateLabel("", 20, 555, 440, 15, 0x01)
   $Output_ProgressBar = GUICtrlCreateProgress(20, 575, 440, 10)
   
   ; Disable Progress Bar
   GUICtrlSetState($Output_ProgressBar, $GUI_DISABLE)
   
   GUICtrlCreateGroup("", -99, -99, 1, 1)
   
   
   

   ; Initialise Window
    GUISetState()

   $State_Looping = true
    While $State_Looping = true
      
      ; Handle User Action
        $State_GUI = GUIGetMsg()
        Select
      Case $State_GUI = $GUI_EVENT_CLOSE
         
            ; Close Program
            ProcessClose("HandBrakeCLI.exe")
                Exit
      
      
      
      Case $State_GUI = $Control_HandbrakePathButton Or $State_GUI = $Control_SourceDirectoryButton Or $State_GUI = $Control_TargetDirectoryButton
         
         
         If $State_GUI = $Control_HandbrakePathButton Then

            ; Store Current Working Directory
            $String_WorkingDir = @WorkingDir
            
            ; Prompt For Executable
            $String_NewHandbrakePath = FileOpenDialog("Please locate your Handbrake CLI executable", @ProgramFilesDir, "All Files (*.*)")
            
            FileChangeDir($String_WorkingDir)
            
            If $String_NewHandbrakePath <> "" Then
               
               $String_HandbrakePath = String($String_NewHandbrakePath)

               GUICtrlSetData($Label_HandbrakePath, $String_HandbrakePath)
               
            EndIf

         EndIf
         
         
         If $State_GUI = $Control_SourceDirectoryButton Then

            ; Prompt For Directory
            $String_NewSourceDirectory = FileSelectFolder("Please locate your source directory", "")
            
            If $String_NewSourceDirectory <> "" Then
               
               $String_SourceDirectory   = $String_NewSourceDirectory

               If StringRight($String_SourceDirectory, 1) <> "\" Then
                  
                  $String_SourceDirectory = $String_SourceDirectory & "\"
                  
               EndIf
               
               GUICtrlSetData($Label_SourceDirectory, $String_SourceDirectory)
               
               ; Destroy And Recreate Film List
               GUICtrlDelete($Control_VideoList)
               
               $Control_VideoList = GUICtrlCreateListView("Video File|Extension|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
               _GUICtrlListView_SetColumnWidth($Control_VideoList,0,190)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,1,70)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,2,70)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,3,60)

               GetVideos($String_SourceDirectory)
               
            EndIf
            
         EndIf


         If $State_GUI = $Control_TargetDirectoryButton Then

            ; Prompt For Directory
            $String_NewTargetDirectory = FileSelectFolder("Please locate your target directory", "")
            
            If $String_NewTargetDirectory <> "" Then
               
               $String_TargetDirectory = $String_NewTargetDirectory
               
               If StringRight($String_TargetDirectory, 1) <> "\" Then
                  
                  $String_TargetDirectory = $String_TargetDirectory & "\"
                  
               EndIf

               GUICtrlSetData($Label_TargetDirectory, $String_TargetDirectory)
               
               ; Destroy And Recreate Film List
               GUICtrlDelete($Control_VideoList)
               
               $Control_VideoList = GUICtrlCreateListView("Video File|Extension|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
               _GUICtrlListView_SetColumnWidth($Control_VideoList,0,190)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,1,70)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,2,70)
               _GUICtrlListView_SetColumnWidth($Control_VideoList,3,60)

               GetVideos($String_SourceDirectory)
            
            EndIf
         
         EndIf         
         
         ; Create And Open Settings File For Writing
         $File_Settings = FileOpen("settings.cfg", 2)
         
         FileWriteLine($File_Settings, "Handbrake CLI > " & GUICtrlRead($Label_HandbrakePath))
         FileWriteLine($File_Settings, "Input Directory > " & GUICtrlRead($Label_SourceDirectory))
         FileWriteLine($File_Settings, "Output Directory > " & GUICtrlRead($Label_TargetDirectory))
         
         FileClose($File_Settings)
      
         
         
      Case $State_GUI = $Control_EncodeButton

         ; Get Selected Videos
         $Integer_SelectedVideos = _GUICtrlListView_GetSelectedCount($Control_VideoList)
         $Array_SelectedVideos = _GUICtrlListView_GetSelectedIndices($Control_VideoList, True)
         
         ; Check Selection
         If $Integer_SelectedVideos < 1 Then

            MsgBox(64, "No Videos Selected", "Please select at least one video to encode")
            
         ElseIf $String_HandbrakePath == "Not Set" Or $String_SourceDirectory == "Not Set" Or $String_TargetDirectory == "Not Set" Then
            
            MsgBox(64, "Settings Incomplete", "Please ensure you have correctly set your Handbrake CLI path, as well as your source and target directories")

         Else
               
            ; Disable Buttons
            GUICtrlSetState($Control_HandbrakePathButton, $GUI_DISABLE)
            GUICtrlSetState($Control_SourceDirectoryButton, $GUI_DISABLE)
            GUICtrlSetState($Control_TargetDirectoryButton, $GUI_DISABLE)
            
            GUICtrlSetState($Control_EncodeButton, $GUI_DISABLE)
            GUICtrlSetState($Control_VideoList, $GUI_DISABLE)
            
            GUICtrlSetState($Control_PresetField, $GUI_DISABLE)
            
            GUICtrlSetState($Control_ManualCropButton, $GUI_DISABLE)
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)


            
            ; Configure Selection Array
            For $Count = 1 To $Array_SelectedVideos[0]
            
               ; Replace Array Indicies With File Name
               $String_FileTitle = _GUICtrlListView_GetItemText($Control_VideoList, $Array_SelectedVideos[$Count], 0)
               $String_FileExtension = _GUICtrlListView_GetItemText($Control_VideoList, $Array_SelectedVideos[$Count], 1)
               $Array_SelectedVideos[$Count] = $String_FileTitle & "." & $String_FileExtension
               
            Next
   
            
            
            ; Generate Display List
            $Count = 1
            Do
               
               ; Set Cropping Mode (Per Film)
               $String_CropMode = GUICtrlRead($Control_ManualCropButton)
               
               If $String_CropMode = "Automatic" Then
               
                  ; Cropping Is Manually Set (Yes, this is ass-backwards)
                  $Integer_CropTop = GUICtrlRead($Control_CropTopCheckbox)
                  $Integer_CropBottom = GUICtrlRead($Control_CropBottomCheckbox)
                  $Integer_CropLeft = GUICtrlRead($Control_CropLeftCheckbox)
                  $Integer_CropRight = GUICtrlRead($Control_CropRightCheckbox)
                  
                  $String_CropSettings = "--crop " & $Integer_CropTop & ":" & $Integer_CropBottom & ":" & $Integer_CropLeft & ":" & $Integer_CropRight
                  
               Else
                  
                  If FileExists($String_SourceDirectory & $Array_SelectedVideos[$Count] & "\VIDEO_CROP.TXT") Then
                     
                     ; Get Crop Data
                     $String_CropValues = FileReadLine($String_SourceDirectory & $Array_SelectedVideos[$Count] & "\VIDEO_CROP.TXT")
                     $Array_CropValues = StringSplit($String_CropValues, ",")
                     
                     ; Override With Crop.txt Values
                     $String_CropSettings = "--crop " & $Array_CropValues[1] & ":" & $Array_CropValues[2] & ":" & $Array_CropValues[3] & ":" & $Array_CropValues[4]
                     
                  Else
                     
                     ; Just Let The Encoder Work It Out
                     $String_CropSettings = ""
                  
                  EndIf
                  
               EndIf

               
               ; Determine Preset Selection
               $String_SelectedPreset = GUICtrlRead($Control_PresetField)
               $Index = 0
               For $String_Preset In $Array_PresetNames
                  
                  If $String_SelectedPreset = $String_Preset Then
                     
                     $Integer_Command = $Index
                     ExitLoop
                  
                  EndIf
                     
                  $Index = $Index + 1
                  
               Next
               
               $String_Command = $Array_PresetCommands[$Integer_Command]
               $String_TargetExtension = $Array_PresetExtensions[$Integer_Command]
               
               ; Re-Determine File Name / Extension
               $Array_File = StringSplit($Array_SelectedVideos[$Count], '.', 1)
               $String_SourceName = $Array_SelectedVideos[$Count]
               $String_SourceTitle = $Array_File[1]
               $String_SourceExtension = $Array_File[$Array_File[0]]
               
               
               ;MsgBox(64, "Debug", $String_HandbrakePath & " -i """& $String_SourceDirectory & $String_SourceName & """ -o """ & $String_TargetDirectory & $String_SourceTitle & $String_TargetExtension & """ " & $String_Command & " " & $String_CropSettings)
   
               ; Encode Entry
               $State_HandBrakeCLI = Run($String_HandbrakePath & " -i """& $String_SourceDirectory & $String_SourceName & """ -o """ & $String_TargetDirectory & $String_SourceTitle & $String_TargetExtension & """ " & $String_Command & " " & $String_CropSettings, "", @SW_HIDE, 2)
               
               ; Wait For Current Processes To Complete
               While ProcessExists("HandBrakeCLI.exe") <> 0
                  
                  ; Get Output
                  $String_HandbrakeOutput = StdoutRead($State_HandBrakeCLI)
                  $Array_HandbrakeOutput = StringSplit($String_HandbrakeOutput, @CR, 1)
                  $String_HandbrakeOutput = $Array_HandbrakeOutput[$Array_HandbrakeOutput[0]]
                  
                  ; Format Handbrake Output
                  ; Encoding: task 2 of 3, 62.71 % (130.18 fps, avg 121.24 fps, ETA 00h00m15s)
                  $Array_HandbrakeOutput = StringSplit($String_HandbrakeOutput, " % ", 1)
                  
                  $Float_Progress = $Array_HandbrakeOutput[1]
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 1, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 2, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 1 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 2 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, "Encoding: task 3 of 3, ", "")
                  $Float_Progress = StringReplace($Float_Progress, " %", "")
                  $Float_Progress = StringReplace($Float_Progress, "%", "")
                  
                  If StringIsFloat($Float_Progress) Then
                     
                     $String_Step = $Array_HandbrakeOutput[1]
                     $String_Step = StringReplace($String_Step, "Encoding: task", "Step")
                     $String_Step = StringLeft($String_Step, 11)
                     
                     if $Array_HandbrakeOutput[0] > 1 Then
                        
                        $String_Time = $Array_HandbrakeOutput[2]
                        $String_Time = StringRight($String_Time, 10)
                        $String_Time = StringReplace($String_Time, ")", "")
                        $String_Time = StringReplace($String_Time, "s", " Seconds")
                        $String_Time = StringReplace($String_Time, "h", " Hours ")
                        $String_Time = StringReplace($String_Time, "m", " Minutes ")
                        
                        $String_Time = StringReplace($String_Time, "00", "0")
                        
                        $String_Time = StringReplace($String_Time, "0 Hours 0 Minutes ", "")
                        $String_Time = StringReplace($String_Time, "0 Hours", " ")
                        $String_Time = StringReplace($String_Time, " 0 Minutes ", " ")
                     
                     Else
                     
                        $String_Time = "Estimating Time..."
                        
                     EndIf
                     
                     $String_Notice = $Array_SelectedVideos[$Count] & " - " & $String_Step & " - " & $String_Time
                     
                  Else
                  
                     $String_Notice = $Array_SelectedVideos[$Count] & " - (" & $Float_Progress & ")"
                  
                  EndIf
                     
                  ; Display Status
                  GUICtrlSetData($Output_ProgressLabel, $String_Notice)
                  GUICtrlSetData($Output_ProgressBar, $Float_Progress)
                  
                  Sleep(1000)
                  
               WEnd
               
               ; Reset Output
               GUICtrlSetData($Output_ProgressLabel, "")
               GUICtrlSetData($Output_ProgressBar, "")

               ; Move On
               $Count = $Count + 1
               
            Until $Count = $Integer_SelectedVideos + 1
         
         
            ; Plural Check
            If $Integer_SelectedVideos == 1 Then
               
               $Plural = "";
            
            Else
            
               $Plural = "s";
            
            EndIf
         
            
            ; Notify User Of Completion
            MsgBox(64, "Encoding Complete", $Integer_SelectedVideos & " Film" & $Plural & " Encoded")
            
            
            
            ; Destroy And Recreate Film List
            GUICtrlDelete($Control_VideoList)
            
            $Control_VideoList = GUICtrlCreateListView("Video File|Extension|Cropping|State", 20, 155, 440, 270, BitOR($LBS_MULTIPLESEL, $LVS_SORTASCENDING))
            _GUICtrlListView_SetColumnWidth($Control_VideoList,0,190)
            _GUICtrlListView_SetColumnWidth($Control_VideoList,1,70)
            _GUICtrlListView_SetColumnWidth($Control_VideoList,2,70)
            _GUICtrlListView_SetColumnWidth($Control_VideoList,3,60)

            GetVideos($String_SourceDirectory)
            
            
            ; Enable Buttons
            GUICtrlSetState($Control_HandbrakePathButton, $GUI_ENABLE)
            GUICtrlSetState($Control_SourceDirectoryButton, $GUI_ENABLE)
            GUICtrlSetState($Control_TargetDirectoryButton, $GUI_ENABLE)
            
            GUICtrlSetState($Control_EncodeButton, $GUI_ENABLE)
            
            GUICtrlSetState($Control_PresetField, $GUI_ENABLE)
            
            GUICtrlSetState($Control_ManualCropButton, $GUI_ENABLE)
            
            If GUICtrlRead($Control_ManualCropButton) == "Automatic" Then
               
               GUICtrlSetState($Control_CropTopCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropBottomCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropLeftCheckbox, $GUI_ENABLE)
               GUICtrlSetState($Control_CropRightCheckbox, $GUI_ENABLE)
               
            EndIf
         
         EndIf
      
      

      Case $State_GUI = $Control_ManualCropButton
         
         $String_CropMode = GUICtrlRead($Control_ManualCropButton)
         
         ; Get Cropping Settings
         If $String_CropMode = "Manual" Then
            
            GUICtrlSetData($Control_ManualCropButton, "Automatic")
            GUICtrlSetTip($Control_ManualCropButton, "Allow Handbrake to choose suitable cropping automatically", "Set Automatically", 1, 1)
            
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_ENABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_ENABLE)
            
            GUICtrlSetData($Control_CropTopCheckbox, "0")
            GUICtrlSetData($Control_CropBottomCheckbox, "0")
            GUICtrlSetData($Control_CropLeftCheckbox, "0")
            GUICtrlSetData($Control_CropRightCheckbox, "0")
            
         Else
            
            GUICtrlSetData($Control_ManualCropButton, "Manual")
            GUICtrlSetTip($Control_ManualCropButton, "Switch from automatic to manual cropping", "Adjust Cropping", 1, 1)
            
            GUICtrlSetState($Control_CropTopCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropBottomCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropLeftCheckbox, $GUI_DISABLE)
            GUICtrlSetState($Control_CropRightCheckbox, $GUI_DISABLE)

            GUICtrlSetData($Control_CropTopCheckbox, "-")
            GUICtrlSetData($Control_CropBottomCheckbox, "-")
            GUICtrlSetData($Control_CropLeftCheckbox, "-")
            GUICtrlSetData($Control_CropRightCheckbox, "-")
         
         EndIf

            
        EndSelect
    WEnd

Exit

XGEOX
 
Posts: 5
Joined: Sun May 03, 2009 6:03 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby Zoltan » Mon Mar 15, 2010 1:59 pm

This is great. I've been looking for something exactly like this.

I finally got around to ripping my 389 DVD's to Hard Drive using DVDFab, and I boxed up all the disks for the Attic. It took me about two weeks of free time using two DVD drives, and filled up about 2-3 TB of hard drive space. I ripped the main movie only, but since I have international relatives, I ripped subtitles and audio tracks in English, French, & Spanish.

I'd now like to transcode them to MKV preserving all the audio streams and subtitles that I ripped (using DTS or AC3 passthrough where appropriate).

Is there anyway that I can set it to automatically select all the tracks and use the appropriate passthrough?
Zoltan
 
Posts: 1
Joined: Mon Mar 15, 2010 1:31 pm

Re: Simple Batch Encoding GUI For HB CLI

Postby adoucette » Tue Aug 31, 2010 12:33 pm

Thanks for the great GUI for batch encoding.
When I use it, it does not appear to look inside the DVD rip folders for the VIDEO_TS subfolder. Consequently it does not find the VOB files. If I set the input directory on my folder of DVD rips, I get an error for each one that "Could not locate a VOB or video file to encode in this directory".
adoucette
 
Posts: 3
Joined: Mon Aug 30, 2010 5:09 pm


Return to CLI