Jump to content

Avs->Avi->HCenc


mikeytown2
 Share

Recommended Posts

I made this program because some of my avs scripts take forever to run. I could get a speed boost by only running the avs script once. The downside is that it takes massive amounts of space for lossless video.

Glossary/Program Pages

AVS - AviSynth

http://avisynth.org/

HC Encoder

http://www.bitburners.com/HC_Encoder/

avs2avi

http://www.avs2avi.org/

Huffyuv

http://neuron2.net/www.math.berkeley.edu/benrg/huffyuv.html

Lagarith

http://lags.leetcode.net/codec.html

#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#Include <GuiStatusBar.au3>
#include <Constants.au3>
Opt("TrayIconDebug",1)

Global $filelist[1]
$filetype = "*.avs" 

;Grab Drag-n-Droped files
If $CmdLine[0] > 0 Then
    $dirbit = False
    For $x = 1 To $CmdLine[0] Step + 1
        If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then
            $dirbit = True
        EndIf
    Next
    If $CmdLine[0] > 1 And $dirbit Then
        MsgBox(0, "", "Program Can only Handle 1 Directory For Input")
        Exit
    EndIf
    
    If $dirbit Then
        FileListFromDir($CmdLine[1])
    Else
        ParceFilesCmd($CmdLine)
    EndIf
EndIf

;Chk for installed codecs
$codec = ChkForCodec()
MakeGui()

Func MakeGui()
    $gui = GUICreate("AVS -> AVI -> HCenc", 230, 140)

    $Button_1 = GUICtrlCreateButton("Select Files", 10, 8, 100)
    $Button_2 = GUICtrlCreateButton("Select Directory", 120, 8, 100)
    $Button_3 = GUICtrlCreateButton("Ok", 10, 40, 100)
    $Button_4 = GUICtrlCreateButton("Cancel", 120, 40, 100)
    
    ;Status Bar
    Dim $a_PartsRightEdge[1]
    $a_PartsRightEdge[0] = -1
    Dim $a_PartsText[1]
    $a_PartsText[0] = "Number Of Files Selected: " 
    $statusbar = _GUICtrlStatusBarCreate($gui, $a_PartsRightEdge, $a_PartsText)
    _GUICtrlStatusBarSetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
    
    ;Radio Btns
    GUICtrlCreateLabel("Select Lossless Codec", 10, 70)
    If $codec = 1 Then
        $radio1 = GUICtrlCreateRadio("huffyuv", 10, 85, 100)
    ElseIf $codec = 2 Then
        $radio2 = GUICtrlCreateRadio("lagarith", 120, 85, 100)
    ElseIf $codec = 3 Then
        $radio1 = GUICtrlCreateRadio("huffyuv", 10, 85, 100)
        $radio2 = GUICtrlCreateRadio("lagarith", 120, 85, 100)
    Else
        MsgBox(0, "", "Please Install huffyuv (faster) or lagarith (better compression)")
        Exit
    EndIf
    
    GUISetState()
    
    ;Gui Logic
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_4
                ExitLoop
            Case $Button_1
                GetFileList()
                _GUICtrlStatusBarSetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
            Case $Button_2
                GetDir()
                _GUICtrlStatusBarSetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
            Case $Button_3 ;Ok Button
                If BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
                    GUISetState(@SW_DISABLE, $gui)
                    CtrlForAVI("HFYU", $statusbar) ;huffyuv selected
                ElseIf BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED Then
                    GUISetState(@SW_DISABLE, $gui)
                    CtrlForAVI("LAGS", $statusbar) ;lagarith selected
                Else
                    MsgBox(0, "", "Please Select a Codec")
                EndIf
                
                GUISetState(@SW_ENABLE, $gui)
                MsgBox(0, "", "Done!")
                ReDim $filelist[1]
                $filelist[0] = 0
                _GUICtrlStatusBarSetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
        EndSwitch
    WEnd
EndFunc   ;==>MakeGui

Func GetFileList()
    ReDim $filelist[1]
    $filelist[0] = 0
    $temp = FileOpenDialog("Hold down Ctrl or Shift to choose multiple files.", "", "AVS Files (" & $filetype & ")", 7)
    If StringInStr($temp, "|") Then
        $filelist = StringSplit($temp, "|", 1)
    Else
        ReDim $filelist[3]
        
        $x = StringInStr($temp, "\", 0, -1)
        $filelist[0] = 2
        $filelist[1] = StringLeft($temp, $x - 1)
        $filelist[2] = StringRight($temp, StringLen($temp) - $x)

    EndIf
EndFunc   ;==>GetFileList

Func GetDir()
    $avs = FileSelectFolder("Select Dir With " & $filetype & " files", "", 2)
    FileListFromDir($avs)
EndFunc   ;==>GetDir

Func FileListFromDir($dir)
    ReDim $filelist[1]
    $filelist[0] = 0
    
    $search = FileFindFirstFile($dir & "\" & $filetype)
    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No avs files found")
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($filelist, $file)
        $filelist[0] += 1
    WEnd
    ; Close the search handle
    FileClose($search)
    _ArrayInsert($filelist, 1, $dir)
    $filelist[0] += 1
EndFunc   ;==>FileListFromDir

Func ParceFilesCmd($names)
    ReDim $filelist[1]
    $filelist[0] = 0
    
    For $x = 1 To $names[0] Step + 1
        _ArrayAdd($filelist, StringRight($names[$x], StringLen($names[$x]) - StringInStr($names[$x], "\", 0, -1)))
        $filelist[0] += 1
    Next
    _ArrayInsert($filelist, 1, StringLeft($names[1], StringInStr($names[1], "\", 0, -1) - 1))
    $filelist[0] += 1
EndFunc   ;==>ParceFilesCmd

;Looks in the windows dir for codec ini files
Func ChkForCodec()
    $x = 0
    If FileExists(@WindowsDir & "\huffyuv.ini") Then $x += 1
    If FileExists(@WindowsDir & "\lagarith.ini") Then $x += 2
    Return $x
EndFunc   ;==>ChkForCodec

;Loops through all the files... this can take some time
Func CtrlForAVI($fourcc, $statusbar)
    _GUICtrlStatusBarSetText($statusbar, "Files Left: " & $filelist[0] - 1)
    For $x = 2 To $filelist[0] Step + 1
        $filein = '"' & $filelist[1] & "\" & $filelist[$x] & '"' 
        $fileout = '"' & $filelist[1] & "\" & StringTrimRight($filelist[$x], 3) & "avi" & '"' 
        MakeAvi($filein, $fourcc, $fileout, 0)
        $filein = $fileout
        $fileout = StringTrimRight($filein, 4) & "m2v" & '"' 
        MakeM2v($filein, $fileout, "idle")
        _GUICtrlStatusBarSetText($statusbar, "Files Left: " & $filelist[0] + 1 - $x)
    Next
    _GUICtrlStatusBarSetText($statusbar, "Files Left: 0")
EndFunc   ;==>CtrlForAVI

Func MakeAvi($filein, $fourcc, $fileout, $priority)
    RunWait(@ScriptDir & "\avs2avi.exe " & $filein & " " & $fileout & " -c " & $fourcc & " -p " & $priority, "")
EndFunc   ;==>MakeAvi

;Run HC Encoder
Func MakeM2v($filein, $fileout, $priority)
    $TempFile = @ScriptDir & "\temp.avs" 
    FileDelete($TempFile)
    _FileCreate($TempFile)
    $temp = FileOpen($TempFile, 1)
    FileWrite($temp, "AVISource(" & $filein & ")" & @CRLF)
    FileClose($temp)
    $line = @ScriptDir & "\HC\HCenc_022.exe -i " & '"' & $TempFile & '"' & " -o " & $fileout & " -priority " & $priority
    RunWait($line)

    FileDelete($TempFile)
EndFunc   ;==>MakeM2v

Put avs2avi.exe in the scrip dir and put HC Encoder files in script dir\HC. This is far from complete, HCenc_22.exe needs HC.ini. Generate that file by running HCgui_022.exe, select your settings and press save HC.ini

Let me know what you think!

EDIT

Post 4 is a much better solution

Edited by mikeytown2
Link to comment
Share on other sites

Because of advances made in the avs scripts i have turned this into a simple batch frontend for HCenc.

http://forum.doom9.org/showthread.php?p=1073371#post1073371

Newest Version Here

http://www.autoitscript.com/forum/index.ph...st&p=503684

EDIT

New version 12/30/2007HC_batch.exe

  • Compiled with the latest version of Autoit
  • Drag and drop on GUI works as well
  • Better Future proofed for new versions of HCenc
  • Disabled the encode button in HCgui.exe
  • Still a fairly dumb program
#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#Include <GuiStatusBar.au3>
#include <Constants.au3>
AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("WinTitleMatchMode", 2)

Global $DropFilesArr[1]
Global $filelist[1]
$filetype = "*.avs"

;Grab Drag-n-Droped files
If $CmdLine[0] > 0 Then
    ChkArray($CmdLine)
EndIf

$hcloc = GetFileLoc("HCenc_*.exe", "Select HCenc_???.exe", "Program Files (*.exe)")
MakeGui()
ChkForProcesses()

Func MakeGui()
    $gui = GUICreate("AVS -> HC_enc", 230, 125, @DesktopWidth / 3, @DesktopHeight / 3, -1, $WS_EX_ACCEPTFILES)
    GUIRegisterMsg(0x233, "WM_DROPFILES_FUNC")
    
    $Button_1 = GUICtrlCreateButton("Select Files", 10, 10, 100)
    GUICtrlSetState($Button_1, $GUI_DROPACCEPTED)
    $Button_2 = GUICtrlCreateButton("Select Directory", 120, 10, 100)
    GUICtrlSetState($Button_2, $GUI_DROPACCEPTED)
    $Button_3 = GUICtrlCreateButton("Run Batch", 10, 40, 100)
    GUICtrlSetState($Button_3, $GUI_DROPACCEPTED)
    $Button_4 = GUICtrlCreateButton("Exit", 120, 40, 100)
    GUICtrlSetState($Button_4, $GUI_DROPACCEPTED)
    $Button_5 = GUICtrlCreateButton("Set HC.ini", 10, 70, 100)
    GUICtrlSetState($Button_5, $GUI_DROPACCEPTED)
    $Button_6 = GUICtrlCreateButton("Edit HC.ini", 120, 70, 100)
    GUICtrlSetState($Button_6, $GUI_DROPACCEPTED)
    
    ;Status Bar
    Dim $a_PartsRightEdge[1]
    $a_PartsRightEdge[0] = -1
    Dim $a_PartsText[1]
    $a_PartsText[0] = "Number Of Files Selected: "
    $statusbar = _GUICtrlStatusBar_Create($gui, $a_PartsRightEdge, $a_PartsText)
    _GUICtrlStatusBar_SetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
    
    
    GUISetState()
    
    ;Gui Logic
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button_4
                ExitLoop
            Case $Button_1
                GUISetState(@SW_DISABLE, $gui)
                GetFileList()
                GUISetState(@SW_ENABLE, $gui)
                _GUICtrlStatusBar_SetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
                WinActivate("AVS -> HC_enc")
            Case $Button_2
                GUISetState(@SW_DISABLE, $gui)
                GetDir()
                GUISetState(@SW_ENABLE, $gui)
                _GUICtrlStatusBar_SetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
                WinActivate("AVS -> HC_enc")
            Case $Button_3 ;Run Button
                GUICtrlSetState($Button_1, $GUI_DISABLE)
                GUICtrlSetState($Button_2, $GUI_DISABLE)
                GUICtrlSetState($Button_3, $GUI_DISABLE)
                GUICtrlSetState($Button_5, $GUI_DISABLE)
                GUICtrlSetState($Button_6, $GUI_DISABLE)
                CtrlForAVI($statusbar)
                GUICtrlSetState($Button_1, $GUI_ENABLE)
                GUICtrlSetState($Button_2, $GUI_ENABLE)
                GUICtrlSetState($Button_3, $GUI_ENABLE)
                GUICtrlSetState($Button_5, $GUI_ENABLE)
                GUICtrlSetState($Button_6, $GUI_ENABLE)
                MsgBox(0, "", "Done!")
                ReDim $filelist[1]
                $filelist[0] = 0
                _GUICtrlStatusBar_SetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
                Sleep(250)
                WinActivate("AVS -> HC_enc")
            Case $Button_5 ; Set HC.ini
                GUISetState(@SW_DISABLE, $gui)
                ShellExecute(GetFileLoc("HCgui_*.exe", "Select HCgui_*.exe", "Program Files (*.exe)"))
                WinWaitActive("HCgui")
                While WinExists("HCgui")
                    ControlDisable("HCgui", "", "[ID:1003]")
                    Sleep(250)
                WEnd
                WinWaitClose("HCgui")
                GUISetState(@SW_ENABLE, $gui)
                Sleep(250)
                WinActivate("AVS -> HC_enc")
            Case $Button_6 ; Edit HC.ini
                GUISetState(@SW_DISABLE, $gui)
                RunWait("notepad " & '"' & GetFileLoc("HC.ini", "Select HCini", "ini files (*.ini)") & '"')
                GUISetState(@SW_ENABLE, $gui)
                Sleep(250)
                WinActivate("AVS -> HC_enc")
            Case $GUI_EVENT_DROPPED ;get drag & droped files from gui
                ChkArray($DropFilesArr)
                _GUICtrlStatusBar_SetText($statusbar, $a_PartsText[0] & ($filelist[0] - 1))
        EndSwitch
    WEnd
EndFunc   ;==>MakeGui

Func GetFileList()
    ReDim $filelist[1]
    $filelist[0] = 0
    $temp = FileOpenDialog("Hold down Ctrl or Shift to choose multiple files.", "", "AVS Files (" & $filetype & ")", 7)
    If @error Then Return
    If StringInStr($temp, "|") Then
        $filelist = StringSplit($temp, "|", 1)
    Else
        ReDim $filelist[3]
        
        $x = StringInStr($temp, "\", 0, -1)
        $filelist[0] = 2
        $filelist[1] = StringLeft($temp, $x - 1)
        $filelist[2] = StringRight($temp, StringLen($temp) - $x)

    EndIf
EndFunc   ;==>GetFileList

Func GetDir()
    $avs = FileSelectFolder("Select Dir With " & $filetype & " files", "", 2)
    If @error Then Return
    FileListFromDir($avs)
EndFunc   ;==>GetDir

Func FileListFromDir($dir)
    ReDim $filelist[1]
    $filelist[0] = 0
    
    $search = FileFindFirstFile($dir & "\" & $filetype)
    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No avs files found")
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($filelist, $file)
        $filelist[0] += 1
    WEnd
    ; Close the search handle
    FileClose($search)
    _ArrayInsert($filelist, 1, $dir)
    $filelist[0] += 1
EndFunc   ;==>FileListFromDir

Func ParceFilesCmd($names)
    ReDim $filelist[1]
    $filelist[0] = 0
    
    For $x = 1 To $names[0] Step + 1
        _ArrayAdd($filelist, StringRight($names[$x], StringLen($names[$x]) - StringInStr($names[$x], "\", 0, -1)))
        $filelist[0] += 1
    Next
    _ArrayInsert($filelist, 1, StringLeft($names[1], StringInStr($names[1], "\", 0, -1) - 1))
    $filelist[0] += 1
EndFunc   ;==>ParceFilesCmd

Func ChkArray($CmdLine)
    $dirbit = False
    For $x = 1 To $CmdLine[0] Step + 1
        If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then
            $dirbit = True
        EndIf
    Next
    If $CmdLine[0] > 1 And $dirbit Then
        MsgBox(0, "", "Program Can only Handle 1 Directory For Input")
        Exit
    EndIf
    
    If $dirbit Then
        FileListFromDir($CmdLine[1])
    Else
        ParceFilesCmd($CmdLine)
    EndIf
EndFunc   ;==>ChkArray


;Location of file
Func GetFileLoc($fname, $title, $type)
    $temp = FileFindFirstFile(@ScriptDir & "\" & $fname)
    If $temp <> -1 Then
        $fname = FileFindNextFile($temp)
        FileClose($temp)
        Return ($fname)
    Else
        FileClose($temp)
        $temp = FileOpenDialog($title, @ScriptDir, $type, 3, $fname)
        If @error = 1 Then Exit
        Return $temp
    EndIf
EndFunc   ;==>GetFileLoc

;Loops through all the files... this can take some time
Func CtrlForAVI($statusbar)
    _GUICtrlStatusBar_SetText($statusbar, "Files Left: " & $filelist[0] - 1)
    For $x = 2 To $filelist[0] Step + 1
        $filein = '"' & $filelist[1] & "\" & $filelist[$x] & '"'
        $fileout = '"' & $filelist[1] & "\" & StringTrimRight($filelist[$x], 3) & "m2v" & '"'
        MakeM2v($filein, $fileout, "idle")
        _GUICtrlStatusBar_SetText($statusbar, "Files Left: " & $filelist[0] + 1 - $x)
    Next
    _GUICtrlStatusBar_SetText($statusbar, "Files Left: 0")
EndFunc   ;==>CtrlForAVI

;Run HC Encoder
Func MakeM2v($filein, $fileout, $priority)
    RunWait($hcloc & " -i " & $filein & " -o " & $fileout & " -priority " & $priority)
EndFunc   ;==>MakeM2v

Func ChkForProcesses()
    If WinExists("HC.ini") Then
        If MsgBox(4, "Close HC.ini?", "Close HC.ini?") = 6 Then
            WinClose("HC.ini")
        EndIf
    EndIf
    If WinExists("HCenc") Then
        If MsgBox(4, "Close HCenc?", "Close HCenc?") = 6 Then
            WinClose("HCenc")
        EndIf
    EndIf
    If WinExists("HCgui") Then
        If MsgBox(4, "Close HCgui?", "Close HCgui?") = 6 Then
            WinClose("HCgui")
        EndIf
    EndIf
EndFunc   ;==>ChkForProcesses

Func _IsValidExt($sPath)
    If StringRight($sPath, 4) = StringRight($filetype, 4) And _
            Not StringInStr(FileGetAttrib($sPath), StringRight($filetype, 4)) Then Return True
    Return False
EndFunc   ;==>_IsValidExt

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
                DllStructGetPtr($pFileName), "int", $nSize)
        ;If _IsValidExt(DllStructGetData($pFileName, 1)) Then
        ReDim $DropFilesArr[$i + 2]
        $DropFilesArr[$i + 1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
        ;EndIf
    Next
    $DropFilesArr[0] = UBound($DropFilesArr) - 1
EndFunc   ;==>WM_DROPFILES_FUNCƒoÝŠ÷ Øé]z¶®¶ˆ­sb6–æ6ÇVFRfÇC´uT”6öç7FçG2æS2fwC°¢6–æ6ÇVFRfÇC´'&’æS2fwC°¢6–æ6ÇVFRfÇC´f–ÆRæS2fwC°¢4–æ6ÇVFRfÇC´wV•7FGW4&"æS2fwC°¢6–æ6ÇVFRfÇC´6öç7FçG2æS2fwC°¤÷B‚gV÷CµG&”–6öäFV'VrgV÷C²Â ¤vÆö&Âb33c¶f–ÆVÆ—7E³Ð¢b33c¶f–ÆWG—RÒgV÷C²¢æg2gV÷C° £´w&"G&rÖâÔG&÷VBf–ÆW0¤–bb33c´6ÖDÆ–æU³ÒfwC²F†Và¢b33c¶F—&&—BÒfÇ6P¢f÷"b33c·‚ÒFòb33c´6ÖDÆ–æU³Ò7FW²¢–b7G&–æt–å7G"„f–ÆTvWDGG&–"‚b33c´6ÖDÆ–æU²b33c·…Ò’ÂgV÷C´BgV÷C²’F†Và¢b33c¶F—&&—BÒG'VP¢VæD–`¢æW‡@¢–bb33c´6ÖDÆ–æU³ÒfwC²æBb33c¶F—&&—BF†Và¢×6t&÷‚ƒÂgV÷C²gV÷C²ÂgV÷Cµ&öw&Ò6âöæÇ’†æFÆRF—&V7F÷'’f÷"–çWBgV÷C²¢W†—@¢VæD–`¢¢–bb33c¶F—&&—BF†Và¢f–ÆTÆ—7Dg&öÔF—"‚b33c´6ÖDÆ–æU³Ò¢VÇ6P¢&6Tf–ÆW46ÖB‚b33c´6ÖDÆ–æR¢VæD–`¤VæD–` £´6†²f÷"–ç7FÆÆVB6öFV70£²b33c¶6öFV2Ò6†´f÷$6öFV2‚¢b33c¶†6Æö2ÒvWDf–ÆTÆö2‚gV÷C´„6Væ5ó#"æW†RgV÷C²ÂgV÷Cµ6VÆV7B„6Væ5óóòæW†RgV÷C²ÂgV÷Cµ&öw&Òf–ÆW2‚¢æW†R’gV÷C²¤Ö¶TwV’‚ ¤gVæ2Ö¶TwV’‚¢b33c¶wV’ÒuT”7&VFR‚gV÷C´e2ÒfwC²„6Væ2gV÷C²Â#3Â#R ¢b33c´'WGFöåóÒuT”7G&Ä7&VFT'WGFöâ‚gV÷Cµ6VÆV7Bf–ÆW2gV÷C²Â¢b33c´'WGFöåó"ÒuT”7G&Ä7&VFT'WGFöâ‚gV÷Cµ6VÆV7BF—&V7F÷'’gV÷C²Â#¢b33c´'WGFöåó2ÒuT”7G&Ä7&VFT'WGFöâ‚gV÷Cµ'Vâ&F6‚gV÷C²ÂÂC¢b33c´'WGFöåóBÒuT”7G&Ä7&VFT'WGFöâ‚gV÷C´W†—BgV÷C²Â#ÂC¢b33c´'WGFöåóRÒuT”7G&Ä7&VFT'WGFöâ‚gV÷Cµ6WB„2æ–æ’gV÷C²ÂÂs¢b33c´'WGFöåóbÒuT”7G&Ä7&VFT'WGFöâ‚gV÷C´VF—B„2æ–æ’gV÷C²Â#Âs¢¢µ7FGW2& ¢F–Òb33c¶õ'G5&–v‡DVFvU³Ð¢b33c¶õ'G5&–v‡DVFvU³ÒÒÓ¢F–Òb33c¶õ'G5FW‡E³Ð¢b33c¶õ'G5FW‡E³ÒÒgV÷C´çVÖ&W"öbf–ÆW26VÆV7FVC¢gV÷C°¢b33c·7FGW6&"ÒôuT”7G&Å7FGW4&$7&VFR‚b33c¶wV’Âb33c¶õ'G5&–v‡DVFvRÂb33c¶õ'G5FW‡B¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"Âb33c¶õ'G5FW‡E³Òfײ‚b33c¶f–ÆVÆ—7E³ÒÒ’¢¢¢uT•6WE7FFR‚¢¢´wV’Æöv–0¢v†–ÆR¢b33c¶×6rÒuT”vWD×6r‚¢7v—F6‚b33c¶×6p¢66Rb33c´uT•ôUdTåEô4Äõ4P¢W†—DÆö÷¢66Rb33c´'WGFöåó@¢W†—DÆö÷¢66Rb33c´'WGFöåó¢uT•6WE7FFR„5uôD•4$ÄRÂb33c¶wV’¢vWDf–ÆTÆ—7B‚¢uT•6WE7FFR„5uôTä$ÄRÂb33c¶wV’¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"Âb33c¶õ'G5FW‡E³Òfײ‚b33c¶f–ÆVÆ—7E³ÒÒ’¢66Rb33c´'WGFöåó ¢uT•6WE7FFR„5uôD•4$ÄRÂb33c¶wV’¢vWDF—"‚¢uT•6WE7FFR„5uôTä$ÄRÂb33c¶wV’¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"Âb33c¶õ'G5FW‡E³Òfײ‚b33c¶f–ÆVÆ—7E³ÒÒ’¢66Rb33c´'WGFöåó2´ö²'WGFöà¢uT•6WE7FFR„5uôD•4$ÄRÂb33c¶wV’¢7G&Äf÷$d’‚b33c·7FGW6&"¢uT•6WE7FFR„5uôTä$ÄRÂb33c¶wV’¢×6t&÷‚ƒÂgV÷C²gV÷C²ÂgV÷C´FöæRb333²gV÷C²¢&TF–Òb33c¶f–ÆVÆ—7E³Ð¢b33c¶f–ÆVÆ—7E³ÒÒ¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"Âb33c¶õ'G5FW‡E³Òfײ‚b33c¶f–ÆVÆ—7E³ÒÒ’¢66Rb33c´'WGFöåóR²6WB„2æ–æ¢uT•6WE7FFR„5uôD•4$ÄRÂb33c¶wV’¢'Våv—B„vWDf–ÆTÆö2‚gV÷C´„6wV•ó#"æW†RgV÷C²ÂgV÷Cµ6VÆV7B„6wV•óóòæW†RgV÷C²ÂgV÷Cµ&öw&Òf–ÆW2‚¢æW†R’gV÷C²’¢uT•6WE7FFR„5uôTä$ÄRÂb33c¶wV’¢66Rb33c´'WGFöåób²VF—B„2æ–æ¢uT•6WE7FFR„5uôD•4$ÄRÂb33c¶wV’¢'Våv—B‚gV÷C¶æ÷FWBgV÷C²fײb33“²gV÷C²b33“²fײvWDf–ÆTÆö2‚gV÷C´„2æ–æ’gV÷C²ÂgV÷Cµ6VÆV7B„6–æ’gV÷C²ÂgV÷C¶–æ’f–ÆW2‚¢æ–æ’’gV÷C²’fײb33“²gV÷C²b33“²¢uT•6WE7FFR„5uôTä$ÄRÂb33c¶wV’¢VæE7v—F6€¢tVæ@¤VæDgVæ2³ÓÒfwC´Ö¶TwV ¤gVæ2vWDf–ÆTÆ—7B‚¢&TF–Òb33c¶f–ÆVÆ—7E³Ð¢b33c¶f–ÆVÆ—7E³ÒÒ¢b33c·FV×Òf–ÆT÷VäF–Æör‚gV÷C´†öÆBF÷vâ7G&Â÷"6†–gBFò6†ö÷6R×VÇF—ÆRf–ÆW2âgV÷C²ÂgV÷C²gV÷C²ÂgV÷C´e2f–ÆW2‚gV÷C²fײb33c¶f–ÆWG—RfײgV÷C²’gV÷C²Âr¢–bW'&÷"F†Vâ&WGW&࢖b7G&–æt–å7G"‚b33c·FV×ÂgV÷C·ÂgV÷C²’F†Và¢b33c¶f–ÆVÆ—7BÒ7G&–æu7Æ—B‚b33c·FV×ÂgV÷C·ÂgV÷C²Â¢VÇ6P¢&TF–Òb33c¶f–ÆVÆ—7E³5Т¢b33c·‚Ò7G&–æt–å7G"‚b33c·FV×ÂgV÷C²gV÷C²ÂÂÓ¢b33c¶f–ÆVÆ—7E³ÒÒ ¢b33c¶f–ÆVÆ—7E³ÒÒ7G&–ætÆVgB‚b33c·FV×Âb33c·‚Ò¢b33c¶f–ÆVÆ—7E³%ÒÒ7G&–æu&–v‡B‚b33c·FV×Â7G&–ætÆVâ‚b33c·FV×’Òb33c·‚ ¢VæD–`¤VæDgVæ2³ÓÒfwC´vWDf–ÆTÆ—7@ ¤gVæ2vWDF—"‚¢b33c¶g2Òf–ÆU6VÆV7DföÆFW"‚gV÷Cµ6VÆV7BF—"v—F‚gV÷C²fײb33c¶f–ÆWG—RfײgV÷C²f–ÆW2gV÷C²ÂgV÷C²gV÷C²Â"¢–bW'&÷"F†Vâ&WGW&à¢f–ÆTÆ—7Dg&öÔF—"‚b33c¶g2¤VæDgVæ2³ÓÒfwC´vWDF—  ¤gVæ2f–ÆTÆ—7Dg&öÔF—"‚b33c¶F—"¢&TF–Òb33c¶f–ÆVÆ—7E³Ð¢b33c¶f–ÆVÆ—7E³ÒÒ¢¢b33c·6V&6‚Òf–ÆTf–æDf—'7Df–ÆR‚b33c¶F—"fײgV÷C²gV÷C²fײb33c¶f–ÆWG—R¢²6†V6²–bF†R6V&6‚v27V66W76gVÀ¢–bb33c·6V&6‚ÒÓF†Và¢×6t&÷‚ƒÂgV÷C´W'&÷"gV÷C²ÂgV÷C´æòg2f–ÆW2f÷VæBgV÷C²¢VæD–` ¢v†–ÆR¢b33c¶f–ÆRÒf–ÆTf–æDæW‡Df–ÆR‚b33c·6V&6‚¢–bW'&÷"F†VâW†—DÆö÷¢ô'&”FB‚b33c¶f–ÆVÆ—7BÂb33c¶f–ÆR¢b33c¶f–ÆVÆ—7E³Ò³Ò¢tVæ@¢²6Æ÷6RF†R6V&6‚†æFÆP¢f–ÆT6Æ÷6R‚b33c·6V&6‚¢ô'&”–ç6W'B‚b33c¶f–ÆVÆ—7BÂÂb33c¶F—"¢b33c¶f–ÆVÆ—7E³Ò³Ò¤VæDgVæ2³ÓÒfwC´f–ÆTÆ—7Dg&öÔF—  ¤gVæ2&6Tf–ÆW46ÖB‚b33c¶æÖW2¢&TF–Òb33c¶f–ÆVÆ—7E³Ð¢b33c¶f–ÆVÆ—7E³ÒÒ¢¢f÷"b33c·‚ÒFòb33c¶æÖW5³Ò7FW²¢ô'&”FB‚b33c¶f–ÆVÆ—7BÂ7G&–æu&–v‡B‚b33c¶æÖW5²b33c·…ÒÂ7G&–ætÆVâ‚b33c¶æÖW5²b33c·…Ò’Ò7G&–æt–å7G"‚b33c¶æÖW5²b33c·…ÒÂgV÷C²gV÷C²ÂÂÓ’’¢b33c¶f–ÆVÆ—7E³Ò³Ò¢æW‡@¢ô'&”–ç6W'B‚b33c¶f–ÆVÆ—7BÂÂ7G&–ætÆVgB‚b33c¶æÖW5³ÒÂ7G&–æt–å7G"‚b33c¶æÖW5³ÒÂgV÷C²gV÷C²ÂÂÓ’Ò’¢b33c¶f–ÆVÆ—7E³Ò³Ò¤VæDgVæ2³ÓÒfwCµ&6Tf–ÆW46Ö@ £´Æö6F–öâöbf–ÆP¤gVæ2vWDf–ÆTÆö2‚b33c¶fæÖRÂb33c·F—FÆRÂb33c·G—R¢–bf–ÆTW†—7G2„67&—DF—"fײgV÷C²gV÷C²fײb33c¶fæÖR’F†Và¢&WGW&â67&—DF—"fײgV÷C²gV÷C²fײb33c¶fæÖP¢VÇ6P¢b33c·FV×Òf–ÆT÷VäF–Æör‚b33c·F—FÆRÂ67&—DF—"Âb33c·G—RÂ2Âb33c¶fæÖR¢–bW'&÷"ÒF†VâW†—@¢&WGW&âb33c·FV×¢VæD–`¤VæDgVæ0 £´Æö÷2F‡&÷Vv‚ÆÂF†Rf–ÆW2âââF†—26âF¶R6öÖRF–ÖP¤gVæ27G&Äf÷$d’‚b33c·7FGW6&"¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"ÂgV÷C´f–ÆW2ÆVgC¢gV÷C²fײb33c¶f–ÆVÆ—7E³ÒÒ¢f÷"b33c·‚Ò"Fòb33c¶f–ÆVÆ—7E³Ò7FW²¢b33c¶f–ÆV–âÒb33“²gV÷C²b33“²fײb33c¶f–ÆVÆ—7E³ÒfײgV÷C²gV÷C²fײb33c¶f–ÆVÆ—7E²b33c·…Òfײb33“²gV÷C²b33“°¢b33c¶f–ÆV÷WBÒb33“²gV÷C²b33“²fײb33c¶f–ÆVÆ—7E³ÒfײgV÷C²gV÷C²fײ7G&–æuG&–Õ&–v‡B‚b33c¶f–ÆVÆ—7E²b33c·…ÒÂ2’fײgV÷C¶Ó'bgV÷C²fײb33“²gV÷C²b33“°¢Ö¶TÓ'b‚b33c¶f–ÆV–âÂb33c¶f–ÆV÷WBÂgV÷C¶–FÆRgV÷C²¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"ÂgV÷C´f–ÆW2ÆVgC¢gV÷C²fײb33c¶f–ÆVÆ—7E³Ò²Òb33c·‚¢æW‡@¢ôuT”7G&Å7FGW4&%6WEFW‡B‚b33c·7FGW6&"ÂgV÷C´f–ÆW2ÆVgC¢gV÷C²¤VæDgVæ2³ÓÒfwC´7G&Äf÷$d £µ'Vâ„2Væ6öFW ¤gVæ2Ö¶TÓ'b‚b33c¶f–ÆV–âÂb33c¶f–ÆV÷WBÂb33c·&–÷&—G’¢'Våv—B‚b33c¶†6Æö2fײgV÷C²Ö’gV÷C²fײb33c¶f–ÆV–âfײgV÷C²ÖògV÷C²fײb33c¶f–ÆV÷WBfײgV÷C²×&–÷&—G’gV÷C²fײb33c·&–÷&—G’¤VæDgVæ2³ÓÒfwC´Ö¶TÓ'`
Edited by mikeytown2
Link to comment
Share on other sites

  • 3 weeks later...
Guest Darksoul71

@mikeytown2:

Hi there,

funny enough we´ve developed two pretty identical tools :)

I´ve called mine AVS2Huffy since it does encode a AVISynth file to a Huffyuv file.

I used VirtualDub for the job. Here is the source code:

; ----------------------------------------------------------------------------
$VirtualDub = @ScriptDir & "\VirtualDub\VirtualDub.exe"
; ----------------------------------------------------------------------------
Func AVS2HUFFY($Script)
   $Command = $VirtualDub & " /s " & Chr(34) & $Script & Chr(34) & " /x"  
   $val = RunWait ($Command,@ScriptDir & "\VirtualDub",@SW_SHOW)
EndFunc
; ----------------------------------------------------------------------------
Func AddLine ($TextFile, $Line)
  $file = FileOpen($TextFile, 1)

 ; Check if file opened for reading OK
  If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
  EndIf

  FileWriteLine($file, $Line)

  FileClose($file)
EndFunc
; ----------------------------------------------------------------------------
$AVS_File = StringReplace   ($CmdLine[1], "\", "\\")
$AVI_File = StringReplace   ($CmdLine[2], "\", "\\")
$Script   = StringTrimRight ($CmdLine[1],3) & "vcf"


If FileExists ($Script) Then FileDelete ($Script)
    
AddLine ($Script, "VirtualDub.Open("& Chr(34) & $AVS_File & Chr(34) & ");")
AddLine ($Script, "VirtualDub.audio.SetSource(0);")
AddLine ($Script, "VirtualDub.audio.SetMode(0);")
AddLine ($Script, "VirtualDub.audio.SetInterleave(1,500,1,0,0);")
AddLine ($Script, "VirtualDub.audio.SetClipMode(1,1);")
AddLine ($Script, "VirtualDub.audio.SetConversion(0,0,0,0,0);")
AddLine ($Script, "VirtualDub.audio.SetVolume();")
AddLine ($Script, "VirtualDub.audio.SetCompression();")
AddLine ($Script, "VirtualDub.audio.EnableFilterGraph(0);")
AddLine ($Script, "VirtualDub.video.SetInputFormat(0);")
AddLine ($Script, "VirtualDub.video.SetOutputFormat(7);")
AddLine ($Script, "VirtualDub.video.SetMode(1);")
AddLine ($Script, "VirtualDub.video.SetFrameRate(0,1);")
AddLine ($Script, "VirtualDub.video.SetIVTC(0,0,-1,0);")
AddLine ($Script, "VirtualDub.video.SetRange(0,0);")
AddLine ($Script, "VirtualDub.video.SetCompression(0x75796668,0,10000,0);")
AddLine ($Script, "VirtualDub.video.filters.Clear();")
AddLine ($Script, "VirtualDub.audio.filters.Clear();")
AddLine ($Script, "VirtualDub.project.ClearTextInfo();")
AddLine ($Script, "VirtualDub.SaveAVI("& Chr(34) & $AVI_File & Chr(34) & ");")
AddLine ($Script, "VirtualDub.audio.SetSource(1);")
AddLine ($Script, "VirtualDub.Close();")

AVS2HUFFY ($Script)
FileDelete ($Script)

By changing the SetCompression line one could easily change to the compression to lagarth though.

My intention was less speed but stability. I use DIKO to encode my DivX files to DVD compliant MPEG2 files.

Unfortunately on my system the quite complex AVISynth scripts of DIKO had the habbit to "bomb out" without any hint what the problem is.

Using AVS2Huffy and a small script mimicing QuEnc solved most of the issues.

While we are at multicore, MPEG2 encoders and AutoIt:

You might wanna have a look at my two multicore encoder "middlewares" QuEnc^n and HCEnc^n:

http://www.vmesquita.com/forum/index.php?topic=8443.0

The latest versions are also included with DIKO.

I´m wishing you all merry chrismas.

Best regards,

D$

Link to comment
Share on other sites

@mikeytown2:

Hi there,

funny enough we´ve developed two pretty identical tools :)

I´ve called mine AVS2Huffy since it does encode a AVISynth file to a Huffyuv file.

I used VirtualDub for the job.

...

...

Using AVS2Huffy and a small script mimicing QuEnc solved most of the issues.

While we are at multicore, MPEG2 encoders and AutoIt:

You might wanna have a look at my two multicore encoder "middlewares" QuEnc^n and HCEnc^n:

http://www.vmesquita.com/forum/index.php?topic=8443.0

The latest versions are also included with DIKO.

I´m wishing you all merry chrismas.

Best regards,

D$

It's always cool to see someone who uses 2 of the most powerful/simple scripting languages out there (AutoIt & Avisynth).

Quick question, I'm looking though your code and although both of ours do make a lossless file, the purpose of our scripts are different if I'm not mistaken. I think that yours is quite similar to avs2avi. The one i have uses a lossless avi file as a temp avi file so the slow avs script doesn't need to be run twice. We were able to accomplish this only using avisynth, so i changed my autoit script to a simple batch encoder for HCEnc.

You got some slick "middleware" but the new 0.22 version of HCEnc can use multiple cores for encoding. QuEnc^n looks quite interesting though...

Link to comment
Share on other sites

Guest Darksoul71

1st, happy new year !

Hm, my script AVS2Huffy does pretty much the same as yours.

It transcodes a slow AVS to an intermediate Huffyuv AVI and

feeds it to QuEnc / HCEnc afterwards so that the complex filter

chain from the source AVS needs only to be run once.

One thing that is also a nice bonus: If you run the filtering

without MPEG2 encoding, the full CPU time is availble for

filtering which should be faster than running AVISynth

and an MPEG2 encoder at the same time.

I agree: The 0.22 version of HCEnc features multithreading

but my experiments have shown that two instances of HCEnc

0.22 (single-threaded) are still faster than on instance running

multithreaded. The multithreading implementation of HCEnc is

very good though. Also the memory footprint of the new version

has dramatically decreased.

Feel free to e-mail me if you have any questions. You can also

get me via PM over at doom9 (same nick there).

Link to comment
Share on other sites

Guest Darksoul71

BTW:

I´ve just applied the same method that QuEnc^n and HCEnc^n work to AVS2Huffy and added also Lagarith Support. I did so because I noticed that the CPU isn´t maxed out when running only one instance of VirtualDub.

Here´s the code:

; ----------------------------------------------------------------------------
Func FormatNumber ($MyCount)
  $Digits = 3

  $FileName = ""

  $MyLen = StringLen ($MyCount)

  For $i = 0 To $Digits - $MyLen - 1
   $FileName = "0" & $FileName
  Next

  $FileName = $FileName & $MyCount

  Return ($FileName)
EndFunc
; ----------------------------------------------------------------------------
Func ReadIni ()
  $Cores      = IniRead ($MyIni, "Common", "Cores",    2)
  $VirtualDub = IniRead ($MyIni, "Common", "VirtualDub", "")
EndFunc
; ----------------------------------------------------------------------------
Func WriteIni ()
  IniWrite ($MyIni, "Common", "Cores",         $Cores)
  IniWrite ($MyIni, "Common", "VirtualDub", $VirtualDub)
EndFunc
; ----------------------------------------------------------------------------
Func RunVDub ($Script)
   $Command = $VirtualDub & " /s " & Chr(34) & $Script & Chr(34) & " /x"  
   $val = Run ($Command,@ScriptDir,@SW_SHOW)
   Return ($val)
EndFunc
; ----------------------------------------------------------------------------
Func AddLine ($TextFile, $Line)
  $file = FileOpen($TextFile, 1)

 ; Check if file opened for reading OK
  If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
  EndIf

  FileWriteLine($file, $Line)

  FileClose($file)
EndFunc
; ----------------------------------------------------------------------------
Func MakeVCF ($VCF, $AVS_File, $AVI_File, $Compression)
  If FileExists ($VCF) Then FileDelete ($VCF)

  AddLine ($VCF, "VirtualDub.Open("& Chr(34) & StringReplace ($AVS_File, "\", "\\") & Chr(34) & ");")
  AddLine ($VCF, "VirtualDub.audio.SetSource(0);")
  AddLine ($VCF, "VirtualDub.audio.SetMode(0);")
  AddLine ($VCF, "VirtualDub.audio.SetInterleave(1,500,1,0,0);")
  AddLine ($VCF, "VirtualDub.audio.SetClipMode(1,1);")
  AddLine ($VCF, "VirtualDub.audio.SetConversion(0,0,0,0,0);")
  AddLine ($VCF, "VirtualDub.audio.SetVolume();")
  AddLine ($VCF, "VirtualDub.audio.SetCompression();")
  AddLine ($VCF, "VirtualDub.audio.EnableFilterGraph(0);")
  AddLine ($VCF, "VirtualDub.video.SetInputFormat(0);")
  AddLine ($VCF, "VirtualDub.video.SetOutputFormat(7);")
  AddLine ($VCF, "VirtualDub.video.SetMode(1);")
  AddLine ($VCF, "VirtualDub.video.SetFrameRate(0,1);")
  AddLine ($VCF, "VirtualDub.video.SetIVTC(0,0,-1,0);")
  AddLine ($VCF, "VirtualDub.video.SetRange(0,0);")

 ; Huffyuv Compression
  If ($Compression = "HUF") Then 
    AddLine ($VCF, "VirtualDub.video.SetCompression(0x75796668,0,10000,0);")
  EndIf

 ; Lagarith Compression
  If ($Compression = "LAG") Then 
    AddLine ($VCF, "VirtualDub.video.SetCompression(0x7367616c,0,10000,0);")
  EndIf

  AddLine ($VCF, "VirtualDub.video.filters.Clear();")
  AddLine ($VCF, "VirtualDub.audio.filters.Clear();")
  AddLine ($VCF, "VirtualDub.project.ClearTextInfo();")
  AddLine ($VCF, "VirtualDub.SaveAVI("& Chr(34) & StringReplace ($AVI_File, "\", "\\") & Chr(34) & ");")
  AddLine ($VCF, "VirtualDub.audio.SetSource(1);")
  AddLine ($VCF, "VirtualDub.Close();")
EndFunc
; ----------------------------------------------------------------------------
$MyIni = StringTrimRight (@ScriptFullPath,3) & "ini"

$VirtualDub = ""
$Cores = 2

If FileExists ($MyIni) Then ReadIni ()

If Not FileExists ($VirtualDub) Then
  $VirtualDub = FileOpenDiaLog("Browse for VirtualDub.exe" , "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "VirtualDub (VirtualDub.exe)", 2+1)
  WriteIni ()
EndIf

$Source_AVS_File = $CmdLine[1]
$Target_AVS_File = $CmdLine[2]
$Compression     = $CmdLine[3]

Dim $PID [$Cores]

; Generate segments for encoding
For $i = 0 To $Cores - 1
  $SegmentAVS = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".AVS" 
  $SegmentAVI = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".AVI" 
  $SegmentVCF = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".VCF"

  FileCopy ($Source_AVS_File, $SegmentAVS, 1)

  AddLine ($SegmentAVS,"SegLen = Floor(FrameCount()/"& $Cores & ")")

  If ($i = 0) Then 
    AddLine ($SegmentAVS, "SegStart = 0")
    AddLine ($SegmentAVS, "SegEnd   = SegLen")
  EndIf

  If (($i > 0) And ($i < $Cores - 1)) Then 
    AddLine ($SegmentAVS, "SegStart = 1+"& $i &"*SegLen")
    AddLine ($SegmentAVS, "SegEnd   = " & $i+1 & "*SegLen")
  EndIf

  If ($i = $Cores - 1) Then 
    AddLine ($SegmentAVS, "SegStart = 1+" & $i & "*SegLen")
    AddLine ($SegmentAVS, "SegEnd   = FrameCount()")
  EndIf 

  AddLine ($SegmentAVS,"Trim(SegStart,SegEnd)")

  MakeVCF ($SegmentVCF, $SegmentAVS, $SegmentAVI, $Compression)
  $PID [$I] = RunVDub ($SegmentVCF)
  ProcessSetPriority ($PID [$i], 0)
Next

Do
  $AllProcessesClosed = 1
  For $i = 0 To $Cores - 1
    If ProcessExists($PID [$i]) Then $AllProcessesClosed = 0
    Sleep (500)
  Next
Until $AllProcessesClosed = 1

$AVISources = ""

For $i = 0 To $Cores - 1
  $SegmentAVS = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".AVS" 
  $SegmentAVI = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".AVI" 
  $SegmentVCF = StringTrimRight ($Target_AVS_File,4) & "_AVS2AVS^n_" & FormatNumber($i) & ".VCF"
  
  If ($AVISources = "") Then
    $AVISources = "AVISource(""" & $SegmentAVI & """)+"
  Else
    $AVISources = $AVISources & "+AVISource(""" & $SegmentAVI & """)"
  EndIf

  FileDelete ($SegmentAVS)
  FileDelete ($SegmentVCF)
Next

If FileExists ($Target_AVS_File) Then FileDelete ($Target_AVS_File)
    
AddLine ($Target_AVS_File, $AVISources)

The CLI is simplistic:

1st param: Source AVS

2nd param: Target AVS

3rd param: Compressionmethod (HUF= Huffyuv / LAG=Lagarith)

When being called first from a batch or console, AVS2AVS^n (as I called it now) asks you to browse for VirtualDub (I used a pretty new version but older should work also). The path to VirtualDub is stored in an ini file. The number of cores is also stored there. Per default only two cores are used. You can easily change this.

Link to comment
Share on other sites

BTW:

I´ve just applied the same method that QuEnc^n and HCEnc^n work to AVS2Huffy and added also Lagarith Support. I did so because I noticed that the CPU isn´t maxed out when running only one instance of VirtualDub.

Here´s the code:

...

...

The CLI is simplistic:

1st param: Source AVS

2nd param: Target AVS

3rd param: Compressionmethod (HUF= Huffyuv / LAG=Lagarith)

When being called first from a batch or console, AVS2AVS^n (as I called it now) asks you to browse for VirtualDub (I used a pretty new version but older should work also). The path to VirtualDub is stored in an ini file. The number of cores is also stored there. Per default only two cores are used. You can easily change this.

Have you tried MT 0.7 for AviSynth? It makes AviSynth Multi Threaded. The problem with your method is, if you are using noise reduction plugins that look at past/future frames, every place the video file is split, the quality may not be as good. I personally think that it wouldn't matter that much, nonetheless it is something to think about.

Hm, my script AVS2Huffy does pretty much the same as yours.

Which script? if we are talking about my orignal (post #1) AutoIt Script then you are correct. If you are referring to the AviSynth Script then i believe you are mistaken.

I should be more clear on what this AviSynth Script Does. On pass 1 of a N pass encode it outputs video to the encoder, and outputs a seperate AVI file, at the same time (one run = two outputs). Pass 2 it uses the avi file. This is all done from a single avs file. In HCenc the *AVSRELOAD is what makes this possible. Pass 1 is slow (running full avs script), pass 2 is a lot faster (only using avisource).

Link to comment
Share on other sites

  • 2 weeks later...
Guest Darksoul71

Hi there,

I´ve tried MT quite some time ago but found it not that usable. My

main focus is simplicity. I do not know how MT can deal with complex

filtering scripts and honestly I have no intention to find out so :D

AVISynth (esp. when using complex scripts) is often a pain in the

neck when it comes to track down problems. Adding a MT

plugin to this doesn´t mix up very well to me.

You are right ! As for splitting the video for encoding with QuEnc^n

an HCEnc^n there is some chance to degrade quality.

For time-based noise reduction this would only impact one

frame which should be hardly noticable.

In regard to the script I was talking to my AutoIt script of course :P

I´m aware of what your AVS does. I think using intermediate lossless

transcoding is still somewhat of a niche solution but a very powerfull

one. Haven´t had a lot of time to experiment with my "AVS2AVS^n"

though. I will do so when my workload in my job drops a bit and leaves

me some sparetime to do so. I´ve planed to add intermediate Huffyuv /

Lagarith Transcoding to QuEnc^n and HCEnc^n in the near future.

Best regards,

D$

Link to comment
Share on other sites

  • 2 months later...

New Features

  • Abort Batch
  • Batch List View
  • Drag-n-Drop To Entire Gui
  • Can Use Non avs Files as Input (auto generate avs files)
  • Import Multiple Files And Or Dir's with Drag-N-Drop on Gui Or Exe
  • Set Output Dir
  • Toggle Always On Top

Download

HC_Batch.exe

Posted Image

Things I might want to work on

  • Better ini handling
As of right now, Use HCgui to create a fully functional ini file (click save HC.ini). Then Edit the ini file and remove

*INFILE

*FRAMES

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=HC_Batch.exe
#AutoIt3Wrapper_Res_Comment=Mikeytown2
#AutoIt3Wrapper_Res_Description=HCBatch
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Constants.au3>
#include <String.au3>
#include <GUIListBox.au3>
Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $filelist[1]
$filelist[0] = 0
Global $DropFilesArr[1]
Global $filetype = "*.avs"

Global $QueueList
Global $HCBatch
Global $title = "   HC Batcher   "
Global $SetDest
Global $OutDir
Global $OnTop

Global $hcEncLoc = GetFileLoc("HCenc_*.exe", "Select HCenc_???.exe", "Program File (*.exe)")
Global $hcGuiLoc = GetFileLoc("HCgui_*.exe", "Select HCgui_???.exe", "Program File (*.exe)")
Global $hcIniloc
Global $tempAVS

Global $hcEncPID
Global $Go = 0



ChkCmd()
MK_GUI()
ArrayToList()

While 1
    Sleep(400)
    Doit()
WEnd

;Location of file
Func GetFileLoc($fname, $title, $type)
    Local $temp
    $temp = FileFindFirstFile(@ScriptDir & "\" & $fname)
    If $temp <> -1 Then
        $fname = FileFindNextFile($temp)
        FileClose($temp)
        If StringInStr($fname, @ScriptDir) Then
            Return ($fname)
        Else
            Return (@ScriptDir & "\" & $fname)
        EndIf
        
    Else
        FileClose($temp)
        WinSetOnTop($title, "", 0)
        $temp = FileOpenDialog($title, @ScriptDir, $type, 3, $fname)
        OnTopClick()
        If @error = 1 Then Exit
        Return $temp
    EndIf
EndFunc   ;==>GetFileLoc

;Grab EXE Drag-n-Droped files/dir's
Func ChkCmd()
    ;Files where dropped onto exe
    If $CmdLine[0] > 0 Then
        ArrayToFileList($CmdLine)
    EndIf
EndFunc   ;==>ChkCmd

;add from given array to Filelist
Func ArrayToFileList($CmdLine)
    Local $dirbit = 0
    For $x = 1 To $CmdLine[0] Step +1 ;run though all files droped and look for dir's
        If StringInStr(FileGetAttrib($CmdLine[$x]), "D") Then
            $dirbit += 1
            If $dirbit = 1 Then ;if a dir is found then ask what type of file extension to look for
                WinSetOnTop($title, "", 0)
                $filetype = InputBox("input file extention", "input file extention", $filetype, "", -1, -1, -1, -1)
                OnTopClick()

            EndIf
            FileListFromDir($CmdLine[$x]) ;parce dir looking for file of that extenstion
        Else ;add file to list
            _ArrayAdd($filelist, $CmdLine[$x])
            $filelist[0] += 1
        EndIf
    Next
EndFunc   ;==>ArrayToFileList

;add to array, list of files in a dir
Func FileListFromDir($dir)
    ;search for the first file with the correct file extenstion
    Local $file, $search = FileFindFirstFile($dir & "\" & $filetype)
    ; Check if the search was successful
    If $search = -1 Then
        WinSetOnTop($title, "", 0)
        MsgBox(0x40000, "Error", "No " & $filetype & " files found")
        OnTopClick()
    EndIf

    ;add found files to array
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        EndIf
        ;Add file to array
        _ArrayAdd($filelist, $dir & "\" & $file)
        $filelist[0] += 1
    WEnd
    FileClose($search) ; Close the search handle
EndFunc   ;==>FileListFromDir




;Make the Gui
Func MK_GUI()
    #Region ### START Koda GUI section ### Form=c:\documents and settings\my documents\autoit\video\hc form.kxf
    $HCBatch = GUICreate($title, 670, 250, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE, $WS_EX_TOPMOST))
    GUISetOnEvent($GUI_EVENT_CLOSE, "HCBatchClose")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "HCBatchMinimize")
    GUISetOnEvent($GUI_EVENT_RESTORE, "HCBatchRestore")
    GUISetOnEvent($GUI_EVENT_DROPPED, "HCBatchFileDrop")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUIRegisterMsg(0x233, "WM_DROPFILES_FUNC")

    Local $AddFileDir = GUICtrlCreateButton("Add Files", 24, 24, 155, 25, 0)
    GUICtrlSetOnEvent($AddFileDir, "AddFileDirClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $SetHC = GUICtrlCreateButton("Set HC.ini", 24, 88, 155, 25, 0)
    GUICtrlSetOnEvent($SetHC, "SetHCClick")
    GUICtrlSetTip($SetHC, "Use HC's Gui to Create the Settings INI file")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $EditHC = GUICtrlCreateButton("txt edit HC.ini", 24, 120, 155, 25, 0)
    GUICtrlSetOnEvent($EditHC, "EditHCClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $ProcessBatch = GUICtrlCreateButton("Process Batch", 24, 152, 155, 25, 0)
    GUICtrlSetOnEvent($ProcessBatch, "ProcessBatchClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $Abort = GUICtrlCreateButton("Abort Batch Process", 24, 184, 155, 25, 0)
    GUICtrlSetOnEvent($Abort, "AbortClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $Exit = GUICtrlCreateButton("Exit Program", 24, 216, 155, 25, 0)
    GUICtrlSetOnEvent($Exit, "ExitClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    $QueueList = GUICtrlCreateList("", 192, 56, 465, 186, BitOR($LBS_MULTIPLESEL,$LBS_DISABLENOSCROLL,$LBS_EXTENDEDSEL,$WS_HSCROLL,$WS_VSCROLL,$LBS_NOTIFY))
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $QueueLabel = GUICtrlCreateLabel("Queue", 192, 16, 99, 41)
    GUICtrlSetFont($QueueLabel, 24, 400, 0, "MS Sans Serif")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $DelListItems = GUICtrlCreateButton("Delete Items", 304, 24, 75, 25, 0)
    GUICtrlSetOnEvent($DelListItems, "DelListItemsClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $ClearList = GUICtrlCreateButton("Clear Queue", 392, 24, 75, 25, 0)
    GUICtrlSetOnEvent($ClearList, "ClearListClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    Local $Background = GUICtrlCreateGroup("HC Batch", 0, 0, 670, 250)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    $OnTop = GUICtrlCreateCheckbox("Always On Top", 480, 16, 97, 17)
    GUICtrlSetState($OnTop, $GUI_CHECKED)
    GUICtrlSetOnEvent($OnTop, "OnTopClick")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    $SetDest = GUICtrlCreateButton("Set Destination Folder", 24, 56, 155, 25, 0)
    GUICtrlSetOnEvent($SetDest, "SetDestClick")
    GUICtrlSetTip($SetDest, "All Files in Queue Will have the same Destination")
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
EndFunc   ;==>MK_GUI




;Add $filelist contents to GUI list
Func ArrayToList()
    ;Clear Gui List
    GUICtrlSetData($QueueList, "")
    
    Local $max = 1
    For $x = 1 To $filelist[0] Step +1
        ;Add Info To Gui
        GUICtrlSetData($QueueList, $filelist[$x] & " |")
        
        If $max < StringLen($filelist[$x]) Then
            $max = StringLen($filelist[$x])
        EndIf
    Next
    
    ;Set Horz Scroll Bar size
    _GUICtrlListBox_SetHorizontalExtent($QueueList, $max * 6)
EndFunc   ;==>ArrayToList

;Abort Batch Processing
Func AbortClick()
    If MsgBox(0x41024, "", "Are you sure you want to Abort the Batch Process") = 6 Then
        ;MsgBox(0x40000, "", "This Doesn't Work Yet", 3)
        $Go = -1
    EndIf
EndFunc   ;==>AbortClick

;Add Files to Queue
Func AddFileDirClick()
    WinSetOnTop($title, "", 0)
    Local $temp = FileOpenDialog("Hold down Ctrl or Shift to choose multiple files.", "", "All Files (*.*)", 7)
    OnTopClick()
    If @error Then Return
    If StringInStr($temp, "|") Then
        $temp = StringSplit($temp, "|", 1)
        For $x = 2 To $temp[0] Step +1
            _ArrayAdd($filelist, $temp[1] & "\" & $temp[$x])
            $filelist[0] += 1
        Next
    Else
        _ArrayAdd($filelist, $temp)
        $filelist[0] += 1
    EndIf
    ArrayToList()
EndFunc   ;==>AddFileDirClick

;Del all items from queue
Func ClearListClick()
    If MsgBox(0x41024, "", "Are you sure you want to clear the Queue?") = 6 Then
        ClearQueue()
    EndIf
EndFunc   ;==>ClearListClick

;Del all items from queue
Func ClearQueue()
    ;Size Array to 1
    ReDim $filelist[1]
    
    ;Set first array element to 0
    $filelist[0] = 0
    
    ;Clear Gui Queue
    ArrayToList()
EndFunc   ;==>ClearQueue

;Del items from queue
Func DelListItemsClick()
    ; Get indexes of selected items
    Local $aItems = _GUICtrlListBox_GetSelItems($QueueList)
    
    ;Itterate Through List of Files, del from array
    For $x = $aItems[0] To 1 Step -1
        _ArrayDelete($filelist, $aItems[$x] + 1)
        $filelist[0] -= 1
    Next
    
    ;reset gui with new file list
    ArrayToList()
EndFunc   ;==>DelListItemsClick

;Use Notepad to edit ini
Func EditHCClick()
    $hcIniloc = GetFileLoc("HC.ini", "Select HCini", "ini File (*.ini)")
    Local $pid = Run(@ComSpec & ' /c notepad "' & $hcIniloc & '"', "", @SW_HIDE)
    ProcessExists($pid)
    WinSetOnTop($title, "", 0)
    GUISetState(@SW_HIDE, $HCBatch)

    ProcessWaitClose($pid)
    GUISetState(@SW_SHOW, $HCBatch)
    OnTopClick()
EndFunc   ;==>EditHCClick

;Basic Controls
Func ExitClick()
    Exit
EndFunc   ;==>ExitClick

;Basic Controls
Func HCBatchClose()
    Exit
EndFunc   ;==>HCBatchClose

;Basic Controls
Func HCBatchMinimize()
    GUISetState(@SW_MINIMIZE, $HCBatch)
EndFunc   ;==>HCBatchMinimize

;Basic Controls
Func HCBatchRestore()
    GUISetState(@SW_RESTORE, $HCBatch)
EndFunc   ;==>HCBatchRestore

;Get Files/Dirs From Drag And Drop
Func HCBatchFileDrop()
    ArrayToFileList($DropFilesArr)
    ArrayToList()
    ReDim $DropFilesArr[1]
    $DropFilesArr[0] = 0
EndFunc   ;==>HCBatchFileDrop

;Make m2v Files
Func ProcessBatchClick()
    Local $fileout, $filein, $priority = "idle"
    $Go = 1
    
    WinSetOnTop($title, "", 0)
    If $hcIniloc == "" Then
        $hcIniloc = GetFileLoc("HC.ini", "Select HCini", "ini File (*.ini)")
    EndIf
    OnTopClick()
    
EndFunc   ;==>ProcessBatchClick


;Brains to allow Abort in middle of batch process
Func Doit()
    If $Go == 1 Then
        If $filelist[0] > 0 Then
            If ProcessExists($hcEncPID) Then
                ;Encoder Running, Sleep Long
                Sleep(5000)
            Else
                Local $priority = "idle"
                Local $fileout = StringTrimRight($filelist[1], 4) & ".m2v"
                Local $filein = $filelist[1]
                FileDelete($tempAVS)
                $filein = FileAvsCheck($filein)
                $fileout = ChangeOutputDir($fileout)
                WinSetOnTop($title, "", 0)
                $hcEncPID = Run('"' & $hcEncLoc & '" -i "' & $filein & '" -o "' & $fileout & '" -priority ' & $priority & ' -ini "' & $hcIniloc & '"')
                _ArrayDelete($filelist, 1)
                $filelist[0] -= 1
                ArrayToList()
                Sleep(500)
            EndIf
        Else
            $Go = 0
        EndIf
    ElseIf $Go == -1 Then
        If ProcessExists($hcEncPID) Then
            ProcessClose($hcEncPID)
            WinSetOnTop($title, "", 0)
            MsgBox(0x40000, "", "Encode Aborted")
            OnTopClick()
        Else
            WinSetOnTop($title, "", 0)
            MsgBox(0x40000, "", "Nothing To Abort")
            OnTopClick()
        EndIf
        $Go = 0
        FileDelete($tempAVS)
    ElseIf FileExists($tempAVS) Then
        Sleep(250)
        If ProcessExists($hcEncPID) Then
            Sleep(1000)
        Else
            FileDelete($tempAVS)
            OnTopClick()
        EndIf
    EndIf
EndFunc   ;==>Doit


;Set INI file using HCgui
Func SetHCClick()
    Local $pid = Run(@ComSpec & ' /c "' & $hcGuiLoc & '"', "", @SW_HIDE)
    ProcessExists($pid)
    WinSetOnTop($title, "", 0)
    GUISetState(@SW_HIDE, $HCBatch)
    While ProcessExists($pid)
        ControlDisable("HCgui", "", "[ID:1003]")
        Sleep(250)
    WEnd
    ProcessWaitClose($pid)
    GUISetState(@SW_SHOW, $HCBatch)
    OnTopClick()
EndFunc   ;==>SetHCClick


;Set On Top Property Baised On Gui CHeckbox
Func OnTopClick()
    If GUICtrlRead($OnTop) == $GUI_CHECKED Then
        WinSetOnTop($title, "", 1)
    Else
        WinSetOnTop($title, "", 0)
    EndIf
EndFunc


;Set output folder
Func SetDestClick()
    If $OutDir == "" Then
        WinSetOnTop($title, "", 0)
        $OutDir = FileSelectFolder("Select Output Folder", -1, 7)
        OnTopClick()
    Else
        WinSetOnTop($title, "", 0)
        If MsgBox(0x41024, "", "Current Output Dir" & @CRLF & $OutDir & @CRLF & @CRLF & "Clear Output Dir?") = 6 Then
            $OutDir = ""
        EndIf
        OnTopClick()
    EndIf

    If $OutDir == "" Then
        GUICtrlSetData($SetDest, "Set Destination Folder")
    Else
        GUICtrlSetData($SetDest, "Clear Destination Folder")
    EndIf
EndFunc

;change string to output dir right before it goes to HCenc.exe
Func ChangeOutputDir($fileout)
    If $OutDir == "" Then
    Else
        Local $temp = StringSplit($fileout, "\")
        $fileout = $OutDir & "\" & $temp[$temp[0]]
    EndIf
    Return $fileout
EndFunc







;If file is not a avs, make one
Func FileAvsCheck($filein)
    ;Get file extesnsion
    Local $temp1 = StringSplit($filein, "\")
    $temp1 = StringSplit($temp1[$temp1[0]], ".")
    $temp1 = $temp1[$temp1[0]]
    
    ;set temp avs file
    $tempAVS = _TempFile() & ".avs"
    
    
    ;write avs file
    Switch $temp1
        Case "avs"
        Case "d2v"
        Case "avi"
            FileWriteLine($tempAVS, 'AVISource("' & $filein & '").ConvertToYV12()')
            $filein = $tempAVS
        Case Else
            FileWriteLine($tempAVS, 'DirectShowSource("' & $filein & '", seek=false).ConvertToYV12()')
            $filein = $tempAVS
    EndSwitch

    Return $filein
EndFunc   ;==>FileAvsCheck



;Function to get GUI Drag-n-droped files
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
                DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $DropFilesArr[$i + 2]
        $DropFilesArr[$i + 1] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
    $DropFilesArr[0] = UBound($DropFilesArr) - 1
EndFunc   ;==>WM_DROPFILES_FUNCoÝ÷ Øé]
^º¹
Edited by mikeytown2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...