Sign in to follow this  
Followers 0
lokster

kMenc

7 posts in this topic

#1 ·  Posted (edited)

After a long period of inactivity, the kMenc project is back!

kMenc is GUI frontend for the command line video encoder MEncoder. MEncoder is very powerfull tool, but also sometimes it's pain in the ass (especially for the "normal" users), because to use it you must know a lot of command line swithes for it. This is why kMenc was born - to make me able to transcode videos easily, and to fit my personal needs.

I use it to encode movies playable on my Sony DSC Cybershot camera, and, from the next week - for the new handheld MPEG4 video player I am going to buy :D

Some of the possible uses are:

- fix broken AVI files (rebuild AVI index)

- encode video files playable on handheld devices (PDAs, Smartphones, etc...)

- embed subtitles directly in the video file (if the target device does not support loading subtitles from a text file)

- or just transcode a video from one format to another...

Here is a screenshot:

Posted Image

Download the kMenc installer (with everything included to start using it immediately) from http://kmenc.lokster.googlepages.com/

The installer contains the source code + the binaries. It also contains presets for various handheld devices. Most of the presets are not tested, because I have taken them from another similar tool (PocketDivXEncoder - it's interface is _CRAP_).

If someone can confirm that specific preset works(or doesn't work) please let me know.

Here is the source code, for those interested:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <File.au3>
#Include <GuiCombo.au3>
#Include <Misc.au3>
#Include <Date.au3>
#include <Constants.au3>
#include <Array.au3>
#Include <GuiEdit.au3>

Opt("WinSearchChildren", 1)
Opt("TrayAutoPause", 0)
Opt("GUIOnEventMode", 1)



Global $fourcc
#Region ### START Koda GUI section ### Form=kemnc.kxf
Global $AForm1 = GUICreate("kMenc by lokster 0.7 (20070725)", 406, 447, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
Global $AGroup1 = GUICtrlCreateGroup("Input", 0, 0, 404, 103, $BS_FLAT)
GUICtrlSetFont($AGroup1, 8, 800, 0, "MS Sans Serif")
Global $ALabel4 = GUICtrlCreateLabel("Movie:", 8, 16, 36, 17)
Global $ALabel5 = GUICtrlCreateLabel("Subtitle:", 8, 56, 42, 17)
Global $ALabel10 = GUICtrlCreateLabel("Codepage:", 340, 56, 56, 17)
Global $cbIDX = GUICtrlCreateCheckbox("Rebuild index", 220, 16, 82, 14)
GUICtrlSetResizing($cbIDX, $GUI_DOCKAUTO)
GUICtrlSetTip($cbIDX, "Forece AVI index rebuild. Useful for broken movies, but takes some time to rebuild the index")
Global $InMovie = GUICtrlCreateInput("", 8, 32, 297, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
GUICtrlSetTip($InMovie, "Specify input movie filename")
Global $BtnMovie = GUICtrlCreateButton("...", 312, 32, 21, 21, 0)
GUICtrlSetOnEvent($BtnMovie, "BtnMovieClick")
Global $BtnInfo = GUICtrlCreateButton("Info", 340, 32, 53, 21, 0)
GUICtrlSetOnEvent($BtnInfo, "BtnInfoClick")
GUICtrlSetTip($BtnInfo, "Info about the input file...")
Global $InSubtitle = GUICtrlCreateInput("", 8, 72, 297, 21)
GUICtrlSetTip($InSubtitle, "Specify the subtitle filename")
Global $BtnSubtitle = GUICtrlCreateButton("...", 312, 72, 21, 21, 0)
GUICtrlSetOnEvent($BtnSubtitle, "BtnSubtitleClick")
Global $InSubcp = GUICtrlCreateInput("cp1251", 340, 72, 54, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetTip($InSubcp, "Specify the subtitles text encoding")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $AGroup2 = GUICtrlCreateGroup("Output", 0, 104, 404, 185, $BS_FLAT, $WS_EX_TRANSPARENT)
GUICtrlSetFont($AGroup2, 8, 800, 0, "MS Sans Serif")
Global $ALabel6 = GUICtrlCreateLabel("Filename:", 8, 120, 49, 17)
Global $lEstimate = GUICtrlCreateLabel("(estimated size = 0 MB)", 64, 120, 264, 17)
Global $InOut = GUICtrlCreateInput("", 8, 136, 357, 21)
GUICtrlSetTip($InOut, "Specifi the output movie filename")
Global $BtnOut = GUICtrlCreateButton("...", 375, 136, 21, 21, 0)
GUICtrlSetOnEvent($BtnOut, "BtnOutClick")
Global $ATab1 = GUICtrlCreateTab(8, 160, 389, 123)
GUICtrlSetFont($ATab1, 8, 400, 0, "MS Sans Serif")
GUICtrlSetResizing($ATab1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
Global $TabSheet1 = GUICtrlCreateTabItem("Video")
Global $ALabel1 = GUICtrlCreateLabel("Width:", 220, 192, 35, 14)
Global $ALabel2 = GUICtrlCreateLabel("Height:", 276, 192, 38, 14)
Global $ALabel12 = GUICtrlCreateLabel("Bitrate:", 92, 232, 37, 14)
Global $ALabel14 = GUICtrlCreateLabel("FourCC:", 84, 192, 42, 14)
Global $lVbitrate = GUICtrlCreateLabel("800 kb/s", 132, 232, 95, 17)
GUICtrlSetTip($lVbitrate, "The output size is verry approximate if you use ABR audio mode!")
Global $ALabel3 = GUICtrlCreateLabel("FPS:", 12, 232, 27, 14)
Global $cbVideoCodec = GUICtrlCreateCheckbox("Codec:", 12, 192, 57, 16)
GUICtrlSetResizing($cbVideoCodec, $GUI_DOCKAUTO)
GUICtrlSetOnEvent($cbVideoCodec, "cbVideoCodecClick")
Global $lVcodec = GUICtrlCreateCombo("", 12, 208, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL))
GUICtrlSetOnEvent($lVcodec, "lVcodecChange")
Global $lFourcc = GUICtrlCreateCombo("", 84, 208, 65, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL))
Global $InVbitrate = GUICtrlCreateSlider(76, 248, 222, 29, 0)
GUICtrlSetLimit($InVbitrate, 4000, 10)
GUICtrlSetData($InVbitrate, 100)
GUICtrlSetOnEvent($InVbitrate, "InVbitrateChange")
Global $btnOptBr = GUICtrlCreateButton("?", 300, 248, 21, 21, 0)
GUICtrlSetOnEvent($btnOptBr, "btnOptBrClick")
GUICtrlSetTip($btnOptBr, "Calculate the optimal video bitrate for the MPEG4 codec, based on the chosen resolution and FPS")
Global $InWidth = GUICtrlCreateInput("320", 220, 208, 49, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetTip($InWidth, "target video width, in pixels")
Global $InHeight = GUICtrlCreateInput("240", 276, 208, 49, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetTip($InHeight, "target video height, in pixels")
Global $InFPS = GUICtrlCreateInput("0", 12, 248, 65, 21)
GUICtrlSetTip($InFPS, "Specify output Frames Per Second. Use 0 to keep the source fps")
Global $cbZoom = GUICtrlCreateCheckbox("Zoom", 332, 208, 47, 17)
GUICtrlSetState($cbZoom, $GUI_CHECKED)
GUICtrlSetResizing($cbZoom, $GUI_DOCKAUTO)
GUICtrlSetTip($cbZoom, "If the movie is in different aspect ratio, this option will zoom in the movie to remove the black bars")
Global $cbVhq = GUICtrlCreateCheckbox("VHQ", 332, 232, 41, 17)
GUICtrlSetState($cbVhq, $GUI_CHECKED)
GUICtrlSetResizing($cbVhq, $GUI_DOCKAUTO)
GUICtrlSetTip($cbVhq, "Encode width higher picture quality, but takes more time to endode. Bitrate remains the same.")
Global $cb2pass = GUICtrlCreateCheckbox("2 Pass", 332, 256, 53, 17)
GUICtrlSetResizing($cb2pass, $GUI_DOCKAUTO)
GUICtrlSetTip($cb2pass, "Use 2 pass encoding (takes more time, but the quality is higher)")
Global $lContainer = GUICtrlCreateCombo("", 156, 208, 57, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData($lContainer, "mpg|asf|avi|wav|swf|flv|rm|au|nut|mov|mp4|dv")
Global $ALabel13 = GUICtrlCreateLabel("Container:", 156, 192, 52, 14)
Global $TabSheet2 = GUICtrlCreateTabItem("Audio")
Global $ALabel15 = GUICtrlCreateLabel("Codec:", 12, 192, 38, 14)
Global $ALabel16 = GUICtrlCreateLabel("Channels:", 84, 192, 51, 14)
Global $ALabel17 = GUICtrlCreateLabel("Rate:", 156, 192, 30, 14)
Global $ALabel18 = GUICtrlCreateLabel("Bitrate:", 84, 232, 37, 15)
Global $ALabel19 = GUICtrlCreateLabel("VBR Q:", 12, 232, 40, 14)
Global $ALabel20 = GUICtrlCreateLabel("Mode:", 228, 192, 34, 14)
Global $lAbitrate = GUICtrlCreateLabel("128 kb/s", 124, 232, 171, 12)
GUICtrlSetTip($lAbitrate, "The output size is verry approximate if you use ABR audio mode!")
Global $lACodec = GUICtrlCreateCombo("", 12, 208, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL))
GUICtrlSetData($lACodec, "copy|lame|pcm|no audio")
GUICtrlSetOnEvent($lACodec, "lACodecChange")
GUICtrlSetTip($lACodec, "Audio codec")
Global $lNch = GUICtrlCreateCombo("", 84, 208, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL))
GUICtrlSetData($lNch, "stereo|joint-stereo|dualchannel|mono")
GUICtrlSetOnEvent($lNch, "InVbitrateChange")
GUICtrlSetTip($lNch, "Number of channels")
Global $lSrate = GUICtrlCreateCombo("", 156, 208, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL))
GUICtrlSetData($lSrate, "8000|11025|12000|16000|22050|24000|32000|44100|48000")
GUICtrlSetOnEvent($lSrate, "InVbitrateChange")
GUICtrlSetTip($lSrate, "Sample rate in Hz")
Global $lRmode = GUICtrlCreateCombo("", 228, 208, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData($lRmode, "CBR|ABR|VBR")
GUICtrlSetOnEvent($lRmode, "lRmodeChange")
Global $cbVolnorm = GUICtrlCreateCheckbox("Normalize", 300, 208, 81, 17)
GUICtrlSetState($cbVolnorm, $GUI_CHECKED)
GUICtrlSetResizing($cbVolnorm, $GUI_DOCKAUTO)
GUICtrlSetTip($cbVolnorm, "Normalize the sound output")
Global $lVbrQ = GUICtrlCreateCombo("", 12, 248, 65, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL))
GUICtrlSetData($lVbrQ, "0 (best)|1|2|3|4|5|6|7|8|9 (worst)")
GUICtrlSetTip($lVbrQ, "Variable bitrate quality")
Global $InAbitrate = GUICtrlCreateSlider(76, 248, 222, 29)
GUICtrlSetLimit($InAbitrate, 20, 1)
GUICtrlSetData($InAbitrate, 20)
GUICtrlSetOnEvent($InAbitrate, "InVbitrateChange")
Global $cbStereoEnh = GUICtrlCreateCheckbox("Extra stereo", 300, 232, 81, 17)
GUICtrlSetResizing($cbStereoEnh, $GUI_DOCKAUTO)
GUICtrlSetTip($cbStereoEnh, "Enchance stereo effects")
Global $TabSheet3 = GUICtrlCreateTabItem("Subtitles")
Global $ALabel7 = GUICtrlCreateLabel("Font:", 12, 192, 28, 14)
Global $lbFont = GUICtrlCreateLabel("The spice extends life. The spice expands consciousness", 12, 232, 382, 45, $SS_CENTERIMAGE, $WS_EX_CLIENTEDGE)
GUICtrlSetColor($lbFont, 0xFFFFFF)
GUICtrlSetBkColor($lbFont, 0x010101)
GUICtrlSetTip($lbFont, "This is a sample of the chosen subtitle font")
Global $ALabel11 = GUICtrlCreateLabel("Vert. pos., %", 260, 192, 63, 14)
Global $ALabel9 = GUICtrlCreateLabel("Max width, %", 324, 192, 66, 15)
Global $lFonts = GUICtrlCreateCombo("", 12, 208, 241, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$CBS_SORT,$WS_VSCROLL))
GUICtrlSetOnEvent($lFonts, "lFontsChange")
GUICtrlSetTip($lFonts, "Select the subtitle font")
Global $InSubpos = GUICtrlCreateInput("95", 260, 208, 57, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetTip($InSubpos, "Specify the vertical position of the subtitles, in % of movie height")
Global $inSubwidth = GUICtrlCreateInput("95", 324, 208, 65, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetTip($inSubwidth, "Specify the maximum width of subtitles on the screen. Useful for TV-out. The value is the width of the subtitle in % of the screen width.")
Global $TabSheet4 = GUICtrlCreateTabItem("Other")
Global $InStartpos = GUICtrlCreateInput("00:00:00", 324, 208, 65, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
GUICtrlSetState($InStartpos, $GUI_DISABLE)
Global $ALabel21 = GUICtrlCreateLabel("Start time:", 324, 192, 51, 14)
GUICtrlSetState($ALabel21, $GUI_DISABLE)
Global $InEndpos = GUICtrlCreateInput("00:00:00", 324, 248, 65, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
GUICtrlSetState($InEndpos, $GUI_DISABLE)
Global $ALabel22 = GUICtrlCreateLabel("End time:", 324, 232, 48, 14)
GUICtrlSetState($ALabel22, $GUI_DISABLE)
Global $sStartpos = GUICtrlCreateSlider(12, 208, 302, 29, 0)
GUICtrlSetLimit($sStartpos, 5000, 0)
GUICtrlSetOnEvent($sStartpos, "sStartposChange")
GUICtrlSetState($sStartpos, $GUI_DISABLE)
Global $sEndpos = GUICtrlCreateSlider(12, 248, 302, 29, 0)
GUICtrlSetLimit($sEndpos, 5000, 0)
GUICtrlSetOnEvent($sEndpos, "sEndposChange")
GUICtrlSetState($sEndpos, $GUI_DISABLE)
Global $cbTime = GUICtrlCreateCheckbox("Start && End time (hh:mm:ss)", 12, 192, 185, 17)
GUICtrlSetResizing($cbTime, $GUI_DOCKAUTO)
GUICtrlSetOnEvent($cbTime, "cbTimeClick")
Global $TabSheet5 = GUICtrlCreateTabItem("Info")
Global $Edit2 = GUICtrlCreateEdit("", 12, 184, 381, 95, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN))
GUICtrlSetData($Edit2, StringFormat("kMenc uses mplayer and mencoder - http://www.mplayerhq.hu/\r\nAlso, the DejaVu Sans font - http://sourceforge.net/projects/dejavu\r\n\r\nkMenc is distributed under the terms of GPL version 3 license. \r\nSee the gpl-3.0.txt file in the kMenc directory."))
GUICtrlCreateTabItem("")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $BtnGenerate = GUICtrlCreateButton(">", 0, 292, 27, 17, 0)
GUICtrlSetOnEvent($BtnGenerate, "BtnGenerateClick")
GUICtrlSetTip($BtnGenerate, "Add to batch")
Global $btnSavePreset = GUICtrlCreateButton("Save preset", 73, 292, 67, 17, 0)
GUICtrlSetOnEvent($btnSavePreset, "btnSavePresetClick")
GUICtrlSetTip($btnSavePreset, "Save che current Audio/Video settings to file")
Global $btnLoadPreset = GUICtrlCreateButton("Load preset", 145, 292, 67, 17, 0)
GUICtrlSetOnEvent($btnLoadPreset, "btnLoadPresetClick")
GUICtrlSetTip($btnLoadPreset, "Load Audio/Video settings from file")
Global $BtnPreview = GUICtrlCreateButton("Preview", 217, 292, 59, 17, 0)
GUICtrlSetOnEvent($BtnPreview, "BtnPreviewClick")
Global $btnRun = GUICtrlCreateButton("Run!", 281, 292, 59, 17, 0)
GUICtrlSetOnEvent($btnRun, "btnRunClick")
GUICtrlSetTip($btnRun, "Execute the command line")
Global $InBatch1 = GUICtrlCreateEdit("", 0, 312, 405, 113, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetFont($InBatch1, 9, 400, 0, "Terminal")
GUICtrlSetColor($InBatch1, 0xC0C0C0)
GUICtrlSetBkColor($InBatch1, 0x000000)
Global $cbDCMMS = GUICtrlCreateCheckbox("Run Digital Camera Multimedia Studio when finished", 0, 428, 273, 17)
GUICtrlSetResizing($cbDCMMS, $GUI_DOCKAUTO)
Global $btnBatchConvert = GUICtrlCreateButton("Run Batch", 345, 292, 59, 17, 0)
GUICtrlSetOnEvent($btnBatchConvert, "btnBatchConvertClick")
GUICtrlSetTip($btnBatchConvert, "Save che current Audio/Video settings to file")
Global $btnClearBatch = GUICtrlCreateButton("X", 32, 292, 27, 17, 0)
GUICtrlSetOnEvent($btnClearBatch, "btnClearBatchClick")
GUICtrlSetTip($btnClearBatch, "Clear batch")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $codecs
Global $vidinfo[11]
Global Const $TBM_SETTIPSIDE = $WM_USER + 31
Global Const $WM_HSCROLL = 0x0114
Global $gaDropFiles[1]
Global $WM_DROPFILES = 0x233

GUISetOnEvent($GUI_EVENT_CLOSE, "BtnExitClick")
GUICtrlSetData($InWidth, 320)
GUICtrlSetData($InHeight, 240)

_SendMessage(GUICtrlGetHandle($InVbitrate), $TBM_SETTICFREQ, 128, 0)
_SendMessage(GUICtrlGetHandle($InAbitrate), $TBM_SETTICFREQ, 1, 0)

GUICtrlSetState($InMovie,$GUI_DROPACCEPTED)
GUISetOnEvent($GUI_EVENT_DROPPED, "SpecialEvents")

GUIRegisterMsg($WM_HSCROLL, "trackbar_change")
GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")


listCodecs()
ListFonts()
LoadOptions(@ScriptDir & '\last.ini')

While 1
    Sleep(100)
WEnd

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_DROPPED
            OpenMovie($gaDropFiles[0])
    EndSelect
EndFunc

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 $gaDropFiles[$i+1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc

Func OnAutoItExit()
    ProcessClose("mencoder.exe")
    ProcessClose("mplayer.exe")
EndFunc

Func btnBatchConvertClick()
    $batch = GUICtrlRead($InBatch1)
    $batch = StringStripCR($batch)
    $batch = StringSplit($batch,@LF)
    
    GUISetState(@SW_HIDE)
    Opt("TrayIconHide",0)
    Opt("TrayAutoPause",0)
    
    for $i = 1 to UBound($batch)-1
        if $batch[$i]<>"" Then
            $text = "Converting file "&$i&" of "&UBound($batch)-2
            TraySetToolTip($text)
            TrayTip("Running batch convert",$text,10,1+16)
            RunWait($batch[$i], @ScriptDir, @SW_SHOW)
        EndIf
    Next
    TraySetToolTip()
    Opt("TrayIconHide",1)
    GUISetState(@SW_SHOW)
EndFunc

Func btnClearBatchClick()
    if MsgBox(32+4,"Confirm","Delete batch?")==6 then
        GUICtrlSetData($InBatch1,"")
    EndIf
EndFunc

Func sStartposChange()
    Local $Secs, $Mins, $Hour, $Time
    _TicksToTime(GUICtrlRead($sStartpos) * 1000, $Hour, $Mins, $Secs)
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    GUICtrlSetData($InStartpos, $Time)
EndFunc   ;==>sStartposChange

Func sEndposChange()
    Local $Secs, $Mins, $Hour, $Time
    _TicksToTime(GUICtrlRead($sEndpos) * 1000, $Hour, $Mins, $Secs)
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    GUICtrlSetData($InEndpos, $Time)

EndFunc   ;==>sEndposChange

Func trackbar_change($hWnd, $Msg, $wParam, $lParam)
    If $lParam = GUICtrlGetHandle($InVbitrate) Or $lParam = GUICtrlGetHandle($InAbitrate) Then
        InVbitrateChange()
    ElseIf $lParam = GUICtrlGetHandle($sStartpos) Then
        sStartposChange()
    ElseIf $lParam = GUICtrlGetHandle($sEndpos) Then
        sEndposChange()
    EndIf
EndFunc   ;==>trackbar_change

Func listCodecs()
    Global $codecs[1]
    Global $fourcc[1]
    
    _ArrayAdd($codecs, "x264")
    _ArrayAdd($fourcc, "H264|")

    _ArrayAdd($codecs, "mjpeg")
    _ArrayAdd($fourcc, "MJPG|")

    _ArrayAdd($codecs, "ljpeg")
    _ArrayAdd($fourcc, "LJPG|")

    _ArrayAdd($codecs, "h261")
    _ArrayAdd($fourcc, "H261|")

    _ArrayAdd($codecs, "h263")
    _ArrayAdd($fourcc, "H263|S263|")

    _ArrayAdd($codecs, "h263p")
    _ArrayAdd($fourcc, "H263|S263|")

    _ArrayAdd($codecs, "mpeg4")
    _ArrayAdd($fourcc, "XVID|FFDS|FVFW|DX50|DIVX|MP4V|3IV2|3IVX|MP4S|M4S2|RMP4|DM4V|DXGM|WV1F|FMP4|HDX4|")

    _ArrayAdd($codecs, "msmpeg4")
    _ArrayAdd($fourcc, "DIV3|MP43|COL1|DVX3|DIV4|DIV5|DIV6|AP41|MPG3|")

    _ArrayAdd($codecs, "msmpeg4v2")
    _ArrayAdd($fourcc, "MP42|DIV2|")

    _ArrayAdd($codecs, "wmv1")
    _ArrayAdd($fourcc, "WMV1|")

    _ArrayAdd($codecs, "wmv2")
    _ArrayAdd($fourcc, "WMV2|")

    _ArrayAdd($codecs, "mpeg1video")
    _ArrayAdd($fourcc, "MPEG|MPG1|")

    _ArrayAdd($codecs, "mpeg2video")
    _ArrayAdd($fourcc, "MPEG|MPG2|")

    _ArrayAdd($codecs, "ffvhuff")
    _ArrayAdd($fourcc, "HFYU|FFVH|")

    _ArrayAdd($codecs, "flv")
    _ArrayAdd($fourcc, "FLV1|")

    For $codec_i = 1 To UBound($codecs) - 1
        GUICtrlSetData($lVcodec, $codecs[$codec_i] & "|")
    Next
EndFunc   ;==>listCodecs

Func lVcodecChange()
    GUICtrlSetData($lFourcc, "")
    GUICtrlSetData($lFourcc, $fourcc[_GUICtrlComboGetCurSel($lVcodec) + 1])
    _GUICtrlComboSetCurSel($lFourcc, 0)
EndFunc   ;==>lVcodecChange

Func btnOptBrClick()
    If GUICtrlRead($InMovie) <> '' Then
        If GUICtrlRead($InFPS) > 0 Then
            $fps_ = GUICtrlRead($InFPS)
        Else
            $fps_ = $vidinfo[5]
        EndIf
        
    Else
        If GUICtrlRead($InFPS) > 0 Then
            $fps_ = GUICtrlRead($InFPS)
        Else
            $fps_ = 25
        EndIf
    EndIf
    $optimal_bitrate = 50 * $fps_ * GUICtrlRead($InWidth) * GUICtrlRead($InHeight) / 256 / 1000
    $result = MsgBox(0x4 + 0x20, "Info:", "The optimal bitrate for mpeg4 (" & GUICtrlRead($InWidth) & "x" & GUICtrlRead($InHeight) & " @" & $fps_ & " FPS) is " & $optimal_bitrate & " kbit/s." & @CRLF & " Do you want to use it?")
    If $result = 6 Then
        GUICtrlSetData($InVbitrate, $optimal_bitrate)
        InVbitrateChange()
    EndIf
EndFunc   ;==>btnOptBrClick

Func InVbitrateChange()
    If GUICtrlRead($cbVideoCodec) == $GUI_UNCHECKED And GUICtrlRead($InMovie) <> '' Then
        $vbitrate = $vidinfo[2]
    Else
        $vbitrate = GUICtrlRead($InVbitrate) * 1000
    EndIf
    $abitrate = -2
    ;MsgBox(0,"",GuiCtrlRead($lACodec))
    Switch GUICtrlRead($lACodec)
        Case 'copy'
            If GUICtrlRead($InMovie) = '' Then
                $abitrate = GUICtrlRead($InAbitrate) * 16 * 1000
            Else
                $abitrate = $vidinfo[7]
            EndIf
        Case 'lame'
            $abitrate = GUICtrlRead($InAbitrate) * 16 * 1000
        Case 'pcm'
            $abitrate = GUICtrlRead($lNch) * 16 * GUICtrlRead($lSrate)
        Case 'no audio'
            $abitrate = 0
            
    EndSwitch

    $size = ($vidinfo[10] * $vbitrate + $vidinfo[10] * $abitrate)
    $size = $size / 8
    $size = ($size / 1024) / 1024
    GUICtrlSetData($lEstimate, '(estimated size = ' & Round($size) & ' MB)')
    GUICtrlSetData($lAbitrate, $abitrate / 1000 & ' kb/s')
    GUICtrlSetData($lVbitrate, $vbitrate / 1000 & ' kb/s')
EndFunc   ;==>InVbitrateChange

Func btnSavePresetClick()
    $target = FileSaveDialog("Save A/V config to...", "", "Config files (*.ini)", 16)
    If $target <> '' Then
        If StringInStr($target, '.ini') = 0 Then
            $target &= '.ini'
        EndIf
        SaveOptions($target)
    EndIf
EndFunc   ;==>btnSavePresetClick

Func btnLoadPresetClick()
    $from = FileOpenDialog("Load A/V config from...", @ScriptDir & "\presets", "Config files (*.ini)")
    If $from <> '' Then
        LoadOptions($from)
    EndIf
EndFunc   ;==>btnLoadPresetClick

Func SaveOptions($file)
    IniWrite($file, 'options', 'width', GUICtrlRead($InWidth))
    IniWrite($file, 'options', 'height', GUICtrlRead($InHeight))
    IniWrite($file, 'options', 'zoom', GUICtrlRead($cbZoom) == $GUI_CHECKED)
    IniWrite($file, 'options', 'vhq', GUICtrlRead($cbVhq) == $GUI_CHECKED)
    IniWrite($file, 'options', 'vccopy', GUICtrlRead($cbVideoCodec) == $GUI_UNCHECKED)
    IniWrite($file, 'options', 'vcodec', GUICtrlRead($lVcodec))
    IniWrite($file, 'options', 'fourcc', GUICtrlRead($lFourcc))
    IniWrite($file, 'options', 'vbitrate', GUICtrlRead($InVbitrate))
    IniWrite($file, 'options', 'acodec', GUICtrlRead($lACodec))
    IniWrite($file, 'options', 'channels', GUICtrlRead($lNch))
    IniWrite($file, 'options', 'srate', GUICtrlRead($lSrate))
    IniWrite($file, 'options', 'normalize', GUICtrlRead($cbVolnorm) == $GUI_CHECKED)
    IniWrite($file, 'options', 'rmode', GUICtrlRead($lRmode))
    IniWrite($file, 'options', 'abitrate', GUICtrlRead($InAbitrate) * 16)
    IniWrite($file, 'options', 'vbrq', GUICtrlRead($lVbrQ))
    IniWrite($file, 'options', 'stereoenh', GUICtrlRead($cbStereoEnh) == $GUI_CHECKED)
    IniWrite($file, 'options', 'fps', GUICtrlRead($InFPS))
    IniWrite($file, 'options', 'container', GUICtrlRead($lContainer))
    
EndFunc   ;==>SaveOptions

Func LoadOptions($file)
    
    GUICtrlSetData($InWidth, IniRead($file, 'options', 'width', '320'))
    GUICtrlSetData($InHeight, IniRead($file, 'options', 'height', '240'))
    
    If IniRead($file, 'options', 'zoom', True) = 'True' Then
        GUICtrlSetState($cbZoom, $GUI_CHECKED)
    Else
        GUICtrlSetState($cbZoom, $GUI_UNCHECKED)
    EndIf
    
    If IniRead($file, 'options', 'vhq', True) = 'True' Then
        GUICtrlSetState($cbVhq, $GUI_CHECKED)
    Else
        GUICtrlSetState($cbVhq, $GUI_UNCHECKED)
    EndIf

    If IniRead($file, 'options', 'vccopy', 'False') = 'True' Then
        GUICtrlSetState($cbVideoCodec, $GUI_UNCHECKED)
        cbVideoCodecClick()
    Else
        GUICtrlSetState($cbVideoCodec, $GUI_CHECKED)
        cbVideoCodecClick()
    EndIf
    
    _GUICtrlComboSelectString($lVcodec, -1, IniRead($file, 'options', 'vcodec', 'mpeg4'))
    lVcodecChange()
    _GUICtrlComboSelectString($lFourcc, -1, IniRead($file, 'options', 'fourcc', 'XVID'))
    GUICtrlSetData($InVbitrate, IniRead($file, 'options', 'vbitrate', '375'))
    
    
    If IniRead($file, 'options', 'normalize', True) = 'True' Then
        GUICtrlSetState($cbVolnorm, $GUI_CHECKED)
    Else
        GUICtrlSetState($cbVolnorm, $GUI_UNCHECKED)
    EndIf
    
    _GUICtrlComboSelectString($lRmode, -1, IniRead($file, 'options', 'rmode', 'CBR'))
    lRmodeChange()
    
    
    _GUICtrlComboSelectString($lACodec, -1, IniRead($file, 'options', 'acodec', 'copy'))
    lACodecChange()

    _GUICtrlComboSelectString($lNch, -1, IniRead($file, 'options', 'channels', ''))
    _GUICtrlComboSelectString($lSrate, -1, IniRead($file, 'options', 'srate', '22050'))
    
    GUICtrlSetData($InAbitrate, IniRead($file, 'options', 'abitrate', '128') / 16)
    InVbitrateChange()
    
    _GUICtrlComboSelectString($lVbrQ, -1, IniRead($file, 'options', 'vbrq', '4'))
    If IniRead($file, 'options', 'stereoenh', False) = 'True' Then
        GUICtrlSetState($cbStereoEnh, $GUI_CHECKED)
    Else
        GUICtrlSetState($cbStereoEnh, $GUI_UNCHECKED)
    EndIf
    
    GUICtrlSetData($InFPS, IniRead($file, 'options', 'fps', 0))
    
    _GUICtrlComboSelectString($lContainer, -1, IniRead($file, 'options', 'container', 'avi'))
    
    GUISetState()
EndFunc   ;==>LoadOptions

Func getVidInfo($file)
    Global $vidinfo[11]

    $cmd = '"' & @ScriptDir & '\mplayer.exe" -slave -identify -quiet -frames 0 -vo null -ao null "' & $file & '"'

    SplashTextOn("", "Loading, please wait...", 320, 32, -1, -1, 1 + 32, "", 16, 1000)
    
    $pid = Run($cmd, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
    $text = ""
    While ProcessExists($pid)
        $text &= StdoutRead($pid)
    WEnd
    SplashOff()
    $out = StringSplit($text, @CRLF, 1)
    $count = $out[0]

    For $i = 1 To $count
        $line = $out[$i]
        $str = StringRegExp($line, '^([a-zA-Z_].*)=(.*?)$', 1)
        If @error = 0 Then
            Switch $str[0]
                Case 'ID_DEMUXER'
                    $vidinfo[0] = $str[1]
                    
                Case 'ID_VIDEO_FORMAT'
                    $vidinfo[1] = $str[1]
                    
                Case 'ID_VIDEO_BITRATE'
                    $vidinfo[2] = $str[1]
                    
                Case 'ID_VIDEO_WIDTH'
                    $vidinfo[3] = $str[1]
                    
                Case 'ID_VIDEO_HEIGHT'
                    $vidinfo[4] = $str[1]
                    
                Case 'ID_VIDEO_FPS'
                    $vidinfo[5] = $str[1]
                    
                Case 'ID_AUDIO_CODEC'
                    $vidinfo[6] = $str[1]
                    
                Case 'ID_AUDIO_BITRATE'
                    $vidinfo[7] = $str[1]
                    
                Case 'ID_AUDIO_RATE'
                    $vidinfo[8] = $str[1]
                    
                Case 'ID_AUDIO_NCH'
                    $vidinfo[9] = $str[1]
                    
                Case 'ID_LENGTH'
                    $vidinfo[10] = $str[1]
            EndSwitch
        EndIf
    Next
EndFunc   ;==>getVidInfo

Func BtnInfoClick()
    $tip = "------------------------------------------------" & @CRLF
    $tip &= "Movie Length:  " & $vidinfo[10] & " sec" & @CRLF
    $tip &= "FPS:       " & $vidinfo[5] & @CRLF

    $tip &= "Width:     " & $vidinfo[3] & @CRLF
    $tip &= "Height:        " & $vidinfo[4] & @CRLF
    
    $tip &= "Video bitrate: " & $vidinfo[2] / 1000 & " kbit/s" & @CRLF
    $tip &= "Audiobitrate:  " & $vidinfo[7] / 1000 & " kbit/s" & @CRLF
    
    $tip &= "Video codec:   " & $vidinfo[1] & @CRLF
    $tip &= "Audio codec:   " & $vidinfo[6] & @CRLF
    
    $tip &= "Audio nCh.:    " & $vidinfo[9]
    $tip &= @CRLF & "------------------------------------------------"
    MsgBox(0, "Input file info:", $tip)
EndFunc   ;==>BtnInfoClick

Func ListFonts()
    $i = 1
    While 1
        $var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $i)
        If @error <> 0 Then ExitLoop
        $font_filename = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $var)
        If StringInStr($font_filename, '.ttf') <> 0 Then
            GUICtrlSetData($lFonts, $var & '|')
        EndIf
        $i += 1
    WEnd
    _GUICtrlComboSetCurSel($lFonts, _GUICtrlComboSelectString($lFonts, -1, 'Arial Bold'))
    lFontsChange()
EndFunc   ;==>ListFonts

Func cbVideoCodecClick()
    If GUICtrlRead($cbVideoCodec) == $GUI_UNCHECKED Then
        GUICtrlSetState($InWidth, $GUI_DISABLE)
        GUICtrlSetState($InHeight, $GUI_DISABLE)
        GUICtrlSetState($cbZoom, $GUI_DISABLE)
        GUICtrlSetState($lVcodec, $GUI_DISABLE)
        GUICtrlSetState($lVbitrate, $GUI_DISABLE)
        GUICtrlSetState($lFourcc, $GUI_DISABLE)
        GUICtrlSetState($InVbitrate, $GUI_DISABLE)
        GUICtrlSetState($cbVhq, $GUI_DISABLE)
        GUICtrlSetState($lFonts, $GUI_DISABLE)
        GUICtrlSetState($InSubpos, $GUI_DISABLE)
        GUICtrlSetState($inSubwidth, $GUI_DISABLE)
        GUICtrlSetState($InFPS, $GUI_DISABLE)
        GUICtrlSetState($cb2pass, $GUI_DISABLE)
    Else
        GUICtrlSetState($InWidth, $GUI_ENABLE)
        GUICtrlSetState($InHeight, $GUI_ENABLE)
        GUICtrlSetState($cbZoom, $GUI_ENABLE)
        GUICtrlSetState($lVcodec, $GUI_ENABLE)
        GUICtrlSetState($lVbitrate, $GUI_ENABLE)
        GUICtrlSetState($lFourcc, $GUI_ENABLE)
        GUICtrlSetState($InVbitrate, $GUI_ENABLE)
        GUICtrlSetState($cbVhq, $GUI_ENABLE)
        GUICtrlSetState($lFonts, $GUI_ENABLE)
        GUICtrlSetState($InSubpos, $GUI_ENABLE)
        GUICtrlSetState($inSubwidth, $GUI_ENABLE)
        GUICtrlSetState($InFPS, $GUI_ENABLE)
        GUICtrlSetState($cb2pass, $GUI_ENABLE)
    EndIf
EndFunc   ;==>cbVideoCodecClick


Func lFontsChange()
    $fontname = GUICtrlRead($lFonts)
    $font = StringRegExpReplace($fontname, ' \(((\\")|[^"])+\)', "", 0)
    GUICtrlSetFont($lbFont, 14, 400, 0, $font)
EndFunc   ;==>lFontsChange

Func SecToHMS()
    
EndFunc   ;==>SecToHMS

Func BtnMovieClick()
    $movie = FileOpenDialog("Select input movie", "", "Multimedia files (*.avi;*.mpg;*.mpeg;*.asf;*.wav;*.swf;*.flv;*.rm;*.au;*.nut;*.mov;*.mp1;*.mp2;*.mp4;*.mpv;*.ogm;*.dv)", 1)
    If $movie <> '' Then
        OpenMovie($movie)
    EndIf
EndFunc   ;==>BtnMovieClick

Func OpenMovie($movie)
    GUICtrlSetData($InMovie, $movie)
    Dim $szDrive, $szDir, $szFName, $szExt
    $path = _PathSplit($movie, $szDrive, $szDir, $szFName, $szExt)
    If FileExists($path[1] & $path[2] & $path[3] & '.txt') Then
        $isub = $path[1] & $path[2] & $path[3] & '.txt'
    ElseIf FileExists($path[1] & $path[2] & $path[3] & '.sub') Then
        $isub = $path[1] & $path[2] & $path[3] & '.sub'
    ElseIf FileExists($path[1] & $path[2] & $path[3] & '.srt') Then
        $isub = $path[1] & $path[2] & $path[3] & '.srt'
    Else
        $isub = ''
    EndIf
    GUICtrlSetData($InSubtitle, $isub)
    $outf = $path[1] & $path[2] & $path[3] & '_converted' & $path[4]
    GUICtrlSetData($InOut, $outf)
    getVidInfo($movie)
    
    GUICtrlSetLimit($sStartpos, $vidinfo[10], 0)
    GUICtrlSetData($sStartpos, 0)
    GUICtrlSetLimit($sEndpos, $vidinfo[10], 0)
    GUICtrlSetData($sEndpos, $vidinfo[10])
    sStartposChange()
    sEndposChange()
    If GUICtrlRead($cbVideoCodec) == $GUI_UNCHECKED Then
        GUICtrlSetData($InVbitrate, $vidinfo[2] / 1000)
    EndIf
    
    If (GUICtrlRead($lACodec) = 'copy') Then
        GUICtrlSetData($InAbitrate, ($vidinfo[7] / 1000) / 16)
    EndIf
    
    InVbitrateChange()
EndFunc

Func BtnSubtitleClick()
    $subtitle = FileOpenDialog("Select input subtitle", "", "Subtitles (*.sub;*.txt;*.srt)", 1)
    If $subtitle <> '' Then
        GUICtrlSetData($InSubtitle, $subtitle)
    EndIf
EndFunc   ;==>BtnSubtitleClick


Func BtnOutClick()
    Dim $szDrive, $szDir, $szFName, $szExt
    $path = _PathSplit(GUICtrlRead($InOut), $szDrive, $szDir, $szFName, $szExt)
    
    $out = FileOpenDialog("Select output file", "", "Multimedia files (*.avi;*.mpg;*.asf;*.wav;*.swf;*.flv;*.rm;*.au;*.nut;*.mov;*.mp4;*.dv)", 8, $path[3] & $path[4])

    If $out <> '' Then
        GUICtrlSetData($InOut, $out)
    EndIf
EndFunc   ;==>BtnOutClick

Func BtnExitClick()
    SaveOptions(@ScriptDir & '\last.ini')
    FileDelete(@TempDir & '\preview.avi')
    Exit
EndFunc   ;==>BtnExitClick

Func BtnGenerateClick()
    
    If GUICtrlRead($cb2pass) == $GUI_CHECKED Then
        $cmd = generateCommandLine(GUICtrlRead($InOut), 0, 1)
        $cmd &= generateCommandLine(GUICtrlRead($InOut), 0, 2)
    Else
        $cmd = generateCommandLine(GUICtrlRead($InOut), 0)
    EndIf

    GUICtrlSetData($InBatch1, $cmd, 1)
EndFunc   ;==>BtnGenerateClick

Func btnRunClick()
    If GUICtrlRead($InMovie) = '' Or GUICtrlRead($InOut) = '' Then
        MsgBox(0x10 + 0x40000, "Error", "A required field is empty!")
        Return
    EndIf
    
    If GUICtrlRead($cb2pass) == $GUI_CHECKED Then
        $cmd = generateCommandLine(GUICtrlRead($InOut), 0, 1)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
        $cmd = generateCommandLine(GUICtrlRead($InOut), 0, 2)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
    Else
        $cmd = generateCommandLine(GUICtrlRead($InOut), 0)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
    EndIf

    If GUICtrlRead($cbDCMMS) == $GUI_CHECKED Then
        Run(@ProgramFilesDir & "\Makayama Interactive\Digital Camera Media Studio\Digital Camera Media Studio.exe")
        WinWaitActive("Digital Camera Media Studio")
        WinActivate("Hard disk")
        WinActivate("Open")
        Send("{ENTER}")
        Send(GUICtrlRead($InOut))
        Send("{ENTER}")
        Send("{TAB}{TAB}{TAB}{ENTER}")
    EndIf
EndFunc   ;==>btnRunClick

Func BtnPreviewClick()
    If GUICtrlRead($InMovie) = '' Then
        MsgBox(0x10 + 0x40000, "Error", "No input file specified!")
        Return
    EndIf
    FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
    If GUICtrlRead($cb2pass) == $GUI_CHECKED Then
        $cmd = generateCommandLine(GUICtrlRead($InOut), 1, 1)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
        $cmd = generateCommandLine(GUICtrlRead($InOut), 1, 2)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
    Else
        $cmd = generateCommandLine(GUICtrlRead($InOut), 1)
        FileChangeDir(FileGetDir(GUICtrlRead($InMovie)))
        RunWait($cmd)
    EndIf
    
    ;$cmd = generateCommandLine(@TempDir &'\preview.avi',1)
    ;RunWait($cmd,@ScriptDir)
    RunWait('"' & @ScriptDir & '\mplayer.exe" "' & @TempDir & '\preview.avi' & '"', @ScriptDir)
EndFunc   ;==>BtnPreviewClick

Func lRmodeChange()
    Switch GUICtrlRead($lRmode)
        Case 'CBR'
            GUICtrlSetState($InAbitrate, $GUI_ENABLE)
            GUICtrlSetState($lAbitrate, $GUI_ENABLE)
            GUICtrlSetState($lVbrQ, $GUI_DISABLE)
        Case 'VBR'
            GUICtrlSetState($InAbitrate, $GUI_DISABLE)
            GUICtrlSetState($lAbitrate, $GUI_DISABLE)
            GUICtrlSetState($lVbrQ, $GUI_ENABLE)
        Case 'ABR'
            GUICtrlSetState($InAbitrate, $GUI_ENABLE)
            GUICtrlSetState($lAbitrate, $GUI_ENABLE)
            GUICtrlSetState($lVbrQ, $GUI_DISABLE)
    EndSwitch
EndFunc   ;==>lRmodeChange

Func generateCommandLine($out_file, $preview, $pass = 1)
    $height = GUICtrlRead($InHeight)
    $width = GUICtrlRead($InWidth)

    If GUICtrlRead($cbIDX) == $GUI_CHECKED Then
        $idx = '-forceidx '
    Else
        $idx = ''
    EndIf
    
    $input = '"' & GUICtrlRead($InMovie) & '" '
    
    $acodec = GUICtrlRead($lACodec)
    Switch $acodec
        ;------------------------------------------------------------
        Case 'copy'
            $oac = '-oac copy '
            $oacopts = ''
            $af = ''
            $srate = ''
            ;------------------------------------------------------------
        Case 'no audio'
            $oac = '-nosound '
            $oacopts = ''
            $af = ''
            $srate = ''
            ;------------------------------------------------------------
        Case 'lame'
            $af = ''
            If GUICtrlRead($cbVolnorm) == $GUI_CHECKED Then
                $af &= 'volnorm'
            EndIf
            
            If GUICtrlRead($cbStereoEnh) == $GUI_CHECKED Then
                $af &= ',extrastereo=2.5'
            EndIf
            
            If $af <> '' Then
                $af = '-af ' & $af & ' '
            EndIf
            
            $oac = '-oac mp3lame '
            $oacopts = '-lameopts mode=' & _GUICtrlComboGetCurSel($lNch)
            $rmode = GUICtrlRead($lRmode)
            Switch $rmode
                Case 'CBR'
                    $oacopts &= ':cbr:br=' & GUICtrlRead($InAbitrate) * 16
                Case 'ABR'
                    $oacopts &= ':abr:br=' & GUICtrlRead($InAbitrate) * 16
                Case 'VBR'
                    $oacopts &= ':vbr=2:q=' & _GUICtrlComboGetCurSel($lVbrQ)
            EndSwitch
            $oacopts &= ' '
            $srate = '-srate ' & GUICtrlRead($lSrate) & ' '
            ;------------------------------------------------------------
        Case 'pcm'
            $af = '-af channels=' & GUICtrlRead($lNch)
            If GUICtrlRead($cbVolnorm) == $GUI_CHECKED Then
                $af &= ',volnorm'
            EndIf
            
            If GUICtrlRead($cbStereoEnh) == $GUI_CHECKED Then
                $af &= ',extrastereo'
            EndIf
            $af &= ' '
            
            $oac = '-oac pcm '
            $oacopts = ''
            $srate = '-srate ' & GUICtrlRead($lSrate) & ' '
            
            ;------------------------------------------------------------
    EndSwitch
    If GUICtrlRead($lContainer) <> 'avi' Then
        $of = '-of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames:format=' & GUICtrlRead($lContainer) & ' '
    Else
        $of = ''
    EndIf
    If GUICtrlRead($cbVideoCodec) == $GUI_UNCHECKED Then
        $ovc = '-ovc copy '
        $ovcopts = ''
        $vf = ''
        $font = ''
        $sub = ''
        $subpos = ''
        $subcp = ''
        $subwidth = ''
        $ofps = ''
        $fourcc = ''
        

    Else
        ;video filters
        If GUICtrlRead($cbZoom) == $GUI_CHECKED Then
            $vf = '-vf scale=-2:' & $height & ',crop=' & $width & ':' & $height
        Else
            $vf = '-vf expand=:::::' & CalcAR() & ',scale=' & $width & ':' & $height
        EndIf
        $vf &= ',harddup '
        
        If GUICtrlRead($lVcodec) == 'x264' Then
            $ovc = '-ovc x264 '
            $ovcopts = '-x264encopts bitrate=' & GUICtrlRead($InVbitrate)
        Else
            $ovc = '-ovc lavc '
            $ovcopts = '-lavcopts vcodec=' & GUICtrlRead($lVcodec);vmax_b_frames=0:
            If GUICtrlRead($cbVhq) == $GUI_CHECKED Or GUICtrlRead($cb2pass) == $GUI_CHECKED Then
                $ovcopts &= ':vhq'
                $vc_ = GUICtrlRead($lVcodec)
                If $vc_ = 'h263p' Or $vc_ = 'mpeg4' Or $vc_ = 'ffvhuff' Or $vc_ = 'flv' Then
                    $ovcopts &= ':v4mv'
                EndIf
            EndIf
            
            $ovcopts &= ':vbitrate=' & GUICtrlRead($InVbitrate)
        EndIf
        
        
        $fourcc = '-ffourcc ' & GUICtrlRead($lFourcc) & ' '
        
        ;subtitles
        If GUICtrlRead($InSubtitle) <> '' Then
            $font = '-font "' & @WindowsDir & '\Fonts\' & RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", GUICtrlRead($lFonts)) & '" '
            $sub = '-sub "' & GUICtrlRead($InSubtitle) & '" '
            $subpos = '-subpos ' & GUICtrlRead($InSubpos) & ' '
            $subcp = '-subcp "' & GUICtrlRead($InSubcp) & '" '
            $subwidth = '-subwidth ' & GUICtrlRead($inSubwidth) & ' '
        Else
            $font = ''
            $sub = ''
            $subpos = ''
            $subcp = ''
            $subwidth = ''
        EndIf
        
        If GUICtrlRead($InFPS) > 0 Then
            $ofps = '-ofps ' & GUICtrlRead($InFPS) & ' '
        Else
            $ofps = ''
        EndIf
    EndIf
    
    If $preview = 1 Then
        $out = '-o "' & @TempDir & '\preview.avi" '
        $other = '-ss ' & Round(Random(0, $vidinfo[10])) & ' -endpos 15 '
    Else
        $out = '-o "' & $out_file & '" '
        If GUICtrlRead($cbTime) == $GUI_CHECKED Then
            $other = '-ss ' & GUICtrlRead($sStartpos) & ' -endpos ' & GUICtrlRead($sEndpos) - GUICtrlRead($sStartpos) & ' '
        Else
            $other = ' '
        EndIf
    EndIf

    If GUICtrlRead($cb2pass) == $GUI_CHECKED Then
        $ovcopts1 = $ovcopts & ':turbo=1:vpass=1 '
        ;$ovcopts1 = $ovcopts &':vpass=1 '
        $ovcopts2 = $ovcopts & ':vpass=2 '
        If $pass == 1 Then
            $cmd = '"' & @ScriptDir & '\mencoder.exe" ' & $input & $idx & $ofps & $of & $ovc & $ovcopts1 & $fourcc & $vf & $sub & $subcp & $font & $subpos & $subwidth & '-oac copy ' & $other & '-o NUL: 2>&1' & @CRLF
        ElseIf $pass == 2 Then
            $cmd = '"' & @ScriptDir & '\mencoder.exe" ' & $input & $idx & $ofps & $of & $ovc & $ovcopts2 & $fourcc & $vf & $sub & $subcp & $font & $subpos & $subwidth & $oac & $oacopts & $srate & $af & $other & $out & ' 2>&1' & @CRLF
        EndIf
    Else
        $ovcopts &= ' '
        $cmd = '"' & @ScriptDir & '\mencoder.exe" ' & $input & $idx & $ofps & $of & $ovc & $ovcopts & $fourcc & $vf & $sub & $subcp & $font & $subpos & $subwidth & $oac & $oacopts & $srate & $af & $other & $out & @CRLF
    EndIf

    Return $cmd
EndFunc   ;==>generateCommandLine

Func cbTimeClick()
    If GUICtrlRead($cbTime) == $GUI_CHECKED Then
        GUICtrlSetState($sStartpos, $GUI_ENABLE)
        GUICtrlSetState($sEndpos, $GUI_ENABLE)
        GUICtrlSetState($InStartpos, $GUI_ENABLE)
        GUICtrlSetState($InEndpos, $GUI_ENABLE)
        GUICtrlSetState($ALabel21, $GUI_ENABLE)
        GUICtrlSetState($ALabel22, $GUI_ENABLE)
    Else
        GUICtrlSetState($sStartpos, $GUI_DISABLE)
        GUICtrlSetState($sEndpos, $GUI_DISABLE)
        GUICtrlSetState($InStartpos, $GUI_DISABLE)
        GUICtrlSetState($InEndpos, $GUI_DISABLE)
        GUICtrlSetState($ALabel21, $GUI_DISABLE)
        GUICtrlSetState($ALabel22, $GUI_DISABLE)
    EndIf
EndFunc   ;==>cbTimeClick

Func lACodecChange()
    $oac = GUICtrlRead($lACodec)
    Switch $oac
        Case 'copy', 'no audio'
            GUICtrlSetState($lNch, $GUI_DISABLE)
            GUICtrlSetState($lSrate, $GUI_DISABLE)
            GUICtrlSetState($cbVolnorm, $GUI_DISABLE)
            GUICtrlSetState($lRmode, $GUI_DISABLE)
            GUICtrlSetState($InAbitrate, $GUI_DISABLE)
            GUICtrlSetState($lVbrQ, $GUI_DISABLE)
            GUICtrlSetState($cbStereoEnh, $GUI_DISABLE)
            GUICtrlSetData($lNch, "")
        Case 'lame'
            If GUICtrlRead($lRmode) == 'VBR' Then
                GUICtrlSetState($lVbrQ, $GUI_ENABLE)
                GUICtrlSetState($InAbitrate, $GUI_DISABLE)
            Else
                GUICtrlSetState($InAbitrate, $GUI_ENABLE)
                GUICtrlSetState($lVbrQ, $GUI_DISABLE)
            EndIf
            
            GUICtrlSetState($lNch, $GUI_ENABLE)
            GUICtrlSetState($lSrate, $GUI_ENABLE)
            GUICtrlSetState($cbVolnorm, $GUI_ENABLE)
            GUICtrlSetState($lRmode, $GUI_ENABLE)
            GUICtrlSetState($cbStereoEnh, $GUI_ENABLE)
            GUICtrlSetData($lNch, "")
            GUICtrlSetData($lNch, "stereo|joint-stereo|dualchannel|mono", "joint-stereo")
        Case 'pcm'
            GUICtrlSetState($lNch, $GUI_ENABLE)
            GUICtrlSetState($lSrate, $GUI_ENABLE)
            GUICtrlSetState($cbVolnorm, $GUI_ENABLE)
            GUICtrlSetState($lRmode, $GUI_DISABLE)
            GUICtrlSetState($InAbitrate, $GUI_DISABLE)
            GUICtrlSetState($lVbrQ, $GUI_DISABLE)
            GUICtrlSetState($cbStereoEnh, $GUI_ENABLE)
            GUICtrlSetData($lNch, "")
            GUICtrlSetData($lNch, "1|2|3|4|5|6", "2")
    EndSwitch
    InVbitrateChange()
EndFunc   ;==>lACodecChange

Func FileGetDir($file)
    Dim $szDrive, $szDir, $szFName, $szExt
    _PathSplit($file, $szDrive, $szDir, $szFName, $szExt)
    Return $szDrive & $szDir
EndFunc   ;==>FileGetDir

Func CalcAR()
    $height = GUICtrlRead($InHeight)
    $width = GUICtrlRead($InWidth)
    $ar = $width / $height
    Return $ar
EndFunc   ;==>CalcAR
Edited by lokster

Share this post


Link to post
Share on other sites



hi

i like it, it seems pretty easy top handle mencoder now

i found a bug though easy to fix

H:\autoit\gui_mencoder\kmenc.au3(421,23) : WARNING: $cbFPS: possibly used before declaration.

if GUICtrlRead($cbFPS)

~~~~~~~~~~~~~~~~~~~~~^

H:\autoit\gui_mencoder\kmenc.au3(421,23) : ERROR: $cbFPS: undeclared global variable.

if GUICtrlRead($cbFPS)

i wrote a gui for conversion of audio files into mp3 using mplayer

Encoder Gui

Share this post


Link to post
Share on other sites

If I am judging only from the posts in this topic, I will say that no one is interested in my tool. But, anyway, I think that this is not true, so, after a long period of inactivity, the kMenc is alive again (now it's version 0.7)!

First post updated.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If I am judging only from the posts in this topic, I will say that no one is interested in my tool. But, anyway, I think that this is not true, so, after a long period of inactivity, the kMenc is alive again (now it's version 0.7)!

First post updated.

This looks like a tool that could come in handy..

can it support conversion to .3gp?

nice job!

Edited by blitzkrg

Share this post


Link to post
Share on other sites

First off, sorry for bumping an old topic.

Second, I registered here especially to thank you (lokster) for writing a nice frontend for the Mencoder tool. You really did a nice job and its interface is indeed so much better than PocketDivxEncoder :)

Thank you very much and thumbs up!

Share this post


Link to post
Share on other sites

hi lokster

i also just found your tool. i needed a video converter foy my new mobile phone ,so this program comes very handy! and i love the preset options too (makes life easier..)

thanks! nobbe

Share this post


Link to post
Share on other sites

Hello

so with this tool would i be able to rip the audio from a video clip and convert it to mp3?

Share this post


Link to post
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
Sign in to follow this  
Followers 0