Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; A simple gui for ffmpeg
- ; by Schreq
- ; v1.3 (2017/11/13)
- ;
- ; TODO:
- ; -tune fastdecode for sony vegas compat
- ; dropdown for color space
- ; hevc_nvenc
- #noenv
- #keyhistory 0
- #notrayicon
- #singleinstance off
- listlines, off
- setworkingdir %a_scriptdir%
- filelist := "filelist.txt"
- batchfile := "encode.bat"
- format := { start: "ffmpeg.exe -hide_banner"
- , concat: " -f concat -safe 0 -i {:s}"
- , normal: " -i ""{:s}"""
- , cv: " -c:v {:s}"
- , libx264: " -crf {:s} -preset {:s}"
- , h264_nvenc: " -qp {:s} -profile:v high -preset {:s}"
- , ca: " -c:a {:s}"
- , aac: " -b:a {:s}k"
- , cut: " -ss {:s} -to {:s} -copyts"
- , size: " -vf scale={:s}:{:s}"
- , fps: " -r {:s}"
- , output: " ""{:s}.{:s}""" }
- tabs := "General||Edit"
- , outfolder := a_scriptdir
- , videofiles
- := "Video (*.avi; *.flv; *.mkv; *.mov; *.mp4; *.mpg; *.webm)"
- , encodersv := "libx264||h264_nvenc|copy"
- , encodersa := "aac||copy"
- , muxers := "mp4||mkv"
- , starttime := 20000101000000
- , endtime := 20000101000100
- , crfdefault := 23
- , crfmax := 51
- , bradefault := 192 ; bitrate audio
- , bramin := 96
- , bramax := 320
- , resxdefault := -1
- , resydefault := 720
- , fpsdefault := 30
- , presets
- := "ultrafast|superfast|veryfast|faster|fast|medium||slow|slower|"
- . "veryslow|placebo"
- , presets_nvenc
- := "default|slow|medium||fast|hp|hq|bd|ll|llhq|llhp|lossless|"
- . "losslesshp"
- tooltiptext := { encoderv
- : "libx264: x264 is a free software library developed by VideoLAN for`n"
- . "encoding video streams into the H.264/MPEG-4 AVC format. Slow but`n"
- . "gives the best compression/quality.`n"
- . "`n"
- . "h264_nvenc: Nvidia NVENC is a feature in its graphics cards that`n"
- . "performs H.264 video encoding, offloading this compute-intensive`n"
- . "task from the CPU.`n"
- . "`n"
- . "copy: Direct stream copy, no encoding is done. Use this to not lose`n"
- . "quality when transcoding. It's not possible to resize or change the`n"
- . "fps in copy mode.`n"
- , muxer
- : "A muxer is an engine which will combine media assets into a single`n"
- . "output container such as a mp4 or mkv (Matroska)."
- , docut
- : "Enable to cut out a clip from the source file."
- , starttime
- : "The start time of the clip to cut out in HH:MM:SS format."
- , endtime
- : "The end time of the clip to cut out in HH:MM:SS format."
- , doresize
- : "Enable to resize the output. In order to keep the aspect ratio the`n"
- . "same, we need to specify only one component, either the width or`n"
- . "height, and set the other component to -1."
- , dofps
- : "Enable to change the framerate of the output."
- , preset_libx264
- : "A preset is a collection of options that will provide a certain`n"
- . "encoding speed to compression ratio. A slower preset will provide`n"
- . "better compression (compression is quality per filesize).`n"
- . "For constant quality encoding, you will simply save bitrate by`n"
- . "choosing a slower preset. The general guideline is to use the`n"
- . "slowest preset that you have patience for.`n"
- . "Ignore placebo as it is not useful."
- , preset_h264_nvenc
- : "A preset is a collection of options that will provide a certain`n"
- . "encoding speed to compression ratio. A slower preset will provide`n"
- . "better compression (compression is quality per filesize).`n"
- . "For constant quality encoding, you will simply save bitrate by`n"
- . "choosing a slower preset.`n"
- . "`n"
- . "default`n"
- . "slow: High Quality 2 passes`n"
- . "medium: High Quality 1 pass (Default)`n"
- . "fast: High Performance 1 pass`n"
- . "hp: High Performance`n"
- . "hq: High Quality`n"
- . "bd: Blue-ray Disk`n"
- . "ll: Low Latency`n"
- . "llhq: Low Latency High Quality`n"
- . "llhp: Low Latency High Performance`n"
- . "lossless`n"
- . "losslesshp: Lossless High Performance"
- , crf_libx264
- : "You can set the values between 0 and 51, where lower values would`n"
- . "result in better quality, at the expense of higher file sizes.`n"
- . "Higher values mean more compression, but at some point you will`n"
- . "notice the quality degradation.`n"
- . "`n"
- . "For x264, sane values are between 18 and 28. The default is 23,`n"
- . "so you can use this as a starting point."
- , crf_h264_nvenc
- : "You can set the values between 0 and 51, where lower values would`n"
- . "result in better quality, at the expense of higher file sizes.`n"
- . "Higher values mean more compression, but at some point you will`n"
- . "notice the quality degradation.`n"
- . "`n"
- . "For x264, sane values are between 18 and 28. The default is 23,`n"
- . "so you can use this as a starting point."
- , encodera
- : "aac: Advanced Audio Coding (AAC) is a proprietary audio coding`n"
- . "standard for lossy digital audio compression. Designed to be the`n"
- . "successor of the MP3 format, AAC generally achieves better sound`n"
- . "quality than MP3 at the same bit rate.`n"
- . "`n"
- . "copy: Direct stream copy, no encoding is done. Use this to not`n"
- . "lose quality when transcoding."
- , bra
- : "Bitrate refers to the number of bits (or the amount of data) that`n"
- . "are processed over a certain amount of time. The higher the rate`n"
- . "is, the better the quality of sound is. However, this also`n"
- . "increases the file size." }
- prevcontrol := ""
- onmessage( 0x200, "WM_MOUSEMOVE" )
- onmessage( 0x2A3, "WM_MOUSELEAVE" )
- ; File list
- gui, add, tab3, , %tabs%
- gui, add, text, xm+10 y+m, Files
- gui, add, listview, r5 w190 -hdr vfiles, Files
- gui, add, button, gaddfile -wrap section, Add
- gui, add, button, gdelfile -wrap ys, Remove
- gui, add, checkbox, vdocat gcatchanged ys+5 disabled, Concatenate
- ; VIDEO
- gui, font, bold
- gui, add, text, w45 xs y+15, Video
- gui, font
- ; Video encoder selection
- gui, add, text, section w45 xs y+10, Encoder
- gui, add, dropdownlist, vencoderv gencodervchanged w100 ys-4
- , %encodersv%
- ; Preset selection
- gui, add, text, section vpresetlabel w45 xs, Preset
- gui, add, dropdownlist, vpreset w100 ys-4, %presets%
- ; CRF selection
- gui, add, text, section vcrflabel w45 xs, Quality
- gui, add, edit, vcrfvalue center readonly -tabstop w60 ys-4
- , %crfdefault%
- gui, add, text, vcrfb1 section, Good
- gui, add, text, vcrfb2 ys, Bad
- gui, add, slider,
- (
- vcrfslider gcrfchanged altsubmit buddy1crfb1 buddy2crfb2 center
- noticks range0-%crfmax% xs ys
- ), %crfdefault%
- ; AUDIO
- gui, font, bold
- gui, add, text, w45 xm+10 y+10, Audio
- gui, font
- ; Audio encoder selection
- gui, add, text, section w45 y+10, Encoder
- gui, add, dropdownlist, vencodera gencoderachanged w100 ys-4
- , %encodersa%
- ; Audio bitrate selection
- gui, add, text, section vbralabel w45 xs, Bitrate
- gui, add, edit, vbra limit3 number w100 ys-4, %bradefault%
- gui, add, updown, vbraupdown range%bramin%-%bramax%, %bradefault%
- gui, add, text, vbraunit ys, kbit/s
- gui, tab, 2
- ; Cut times
- gui, add, checkbox, section vdocut gcutchanged left xm+10 y+m, Cut
- gui, add, text, section vstartlabel disabled w45 xs y+10, Start
- gui, add, datetime, vstarttime 1 choose%starttime% w100 ys-4 disabled
- , HH:mm:ss
- gui, add, text, section vendlabel disabled w45 xs, End
- gui, add, datetime, vendtime 1 choose%endtime% w100 ys-4 disabled
- , HH:mm:ss
- ; Resize
- gui, add, checkbox, section vdoresize gresizechanged left xm+10 y+15
- , Resize
- gui, add, text, section vresizelabel w45 xs y+10 disabled, Size
- gui, add, edit, vresx number w55 ys-4 disabled, %resxdefault%
- gui, add, updown, vresxupdown range-1-99999 disabled, %resxdefault%
- gui, add, text, ys vresxlabel disabled, X
- gui, add, edit, vresy number w55 ys-4 disabled, %resydefault%
- gui, add, updown, vresyupdown range-1-99999 disabled, %resydefault%
- ; FPS
- gui, add, checkbox, section vdofps gfpschanged left xm+10 y+15
- , Framerate
- gui, add, text, section vfpslabel w45 xs y+10 disabled, FPS
- gui, add, edit, vfps number w100 ys-4 disabled, %fpsdefault%
- gui, add, updown, vfpsupdown disabled, %fpsdefault%
- gui, tab
- gui, add, text, section vmuxerlabel w45 xm+10 y+10, Muxer
- gui, add, dropdownlist, vmuxer w45 ys-4, %muxers%
- gui, add, button, grunffmpeg -wrap w99 ys-5, Run
- gui +owndialogs
- gui, show, autosize
- gui, submit, nohide
- return
- WM_MOUSEMOVE()
- {
- global tooltiptext, encoderv, prevcontrol
- static currcontrol
- if ( a_guicontrol == "" )
- return
- if ( a_guicontrol <> prevcontrol ) {
- settimer, displaytooltip, off
- currcontrol := a_guicontrol
- , prevcontrol := currcontrol
- settimer, displaytooltip, -750
- }
- return
- displaytooltip:
- if ( currcontrol == "preset" )
- key := currcontrol "_" encoderv
- else if ( substr( currcontrol, 1, 3 ) == "crf" )
- key := "crf_" . encoderv
- else if ( substr( currcontrol, 1, 3 ) == "bra" )
- key := "bra"
- else if ( substr( currcontrol, 1, 3 ) == "res" )
- key := "doresize"
- else if ( substr( currcontrol, 1, 3 ) == "fps" )
- key := "dofps"
- else
- key := currcontrol
- tooltip % tooltiptext[key]
- return
- }
- WM_MOUSELEAVE()
- {
- global prevcontrol
- tooltip
- settimer, displaytooltip, off
- prevcontrol := ""
- }
- changectl( state, ctrls )
- {
- local i, ctrl
- for i, ctrl in ctrls
- guicontrol, %state%, %ctrl%
- }
- encodervchanged()
- {
- global
- static prevenc := encoderv
- gui, submit, nohide
- if ( encoderv == prevenc )
- return
- local controls
- := [ "presetlabel", "preset", "crflabel", "crfvalue"
- , "crfslider", "crfb1", "crfb2", "doresize", "resizelabel"
- , "resx", "resy", "resxlabel", "resxupdown", "resyupdown"
- , "dofps", "fpslabel", "fps", "fpsupdown" ]
- if ( encoderv == "copy" )
- changectl( "disable", controls )
- else if ( prevenc == "copy" )
- changectl( "enable", controls )
- if ( encoderv == "libx264" )
- guicontrol, , preset, |%presets%
- else if ( encoderv == "h264_nvenc" )
- guicontrol, , preset, |%presets_nvenc%
- prevenc := encoderv
- }
- encoderachanged()
- {
- global
- static prevenc := encodera
- gui, submit, nohide
- if ( encodera == prevenc )
- return
- local controls := [ "bralabel", "bra", "braupdown", "braunit" ]
- if ( encodera == "copy" )
- changectl( "disable", controls )
- else
- changectl( "enable", controls )
- prevenc := encodera
- }
- cutchanged()
- {
- global
- gui, submit, nohide
- local controls
- := [ "startlabel", "endlabel", "starttime", "endtime" ]
- if docut
- changectl( "enable", controls )
- else
- changectl( "disable", controls )
- }
- resizechanged()
- {
- global
- gui, submit, nohide
- local controls
- := [ "resizelabel", "resx", "resxlabel", "resy", "resxupdown"
- , "resyupdown"]
- if doresize
- changectl( "enable", controls )
- else
- changectl( "disable", controls )
- }
- fpschanged()
- {
- global
- gui, submit, nohide
- local controls := [ "fpslabel", "fps", "fpsupdown" ]
- if dofps
- changectl( "enable", controls )
- else
- changectl( "disable", controls )
- }
- crfchanged()
- {
- global encoderv, crfslider, crfvalue
- if ( encoderv <> "h264_nvenc" and crfslider = 0 )
- guicontrol, text, crfvalue, lossless
- else
- guicontrol, text, crfvalue, %crfslider%
- }
- addfile()
- {
- local files, path, filepath
- gui +owndialogs
- fileselectfile, files, m, , , %videofiles%
- loop, parse, files, `n
- {
- if ( a_index == 1 ) {
- path := a_loopfield
- } else {
- filepath := path "\" a_loopfield
- lv_add( "", filepath )
- }
- }
- lv_modifycol()
- if ( lv_getcount() > 1 )
- guicontrol, enable, docat
- }
- delfile()
- {
- local selected, row := lv_getcount()
- loop
- {
- if row < 0
- break
- selected := lv_getnext( row )
- if selected
- lv_delete( selected )
- row--
- }
- if ( lv_getcount() < 2 ) {
- guicontrolget, docat
- if docat {
- guicontrol, , docat, 0
- catchanged()
- }
- guicontrol, disable, docat
- }
- lv_modifycol()
- }
- catchanged()
- {
- global
- guicontrolget, docat
- if docat {
- ; disable the cut checkbox and time input boxes for concat mode
- guicontrol, disable, docut
- if docut
- changectl( "disable"
- , [ "startlabel", "endlabel", "starttime", "endtime" ] )
- } else {
- guicontrol, enable, docut
- if docut
- changectl("enable"
- , [ "startlabel", "endlabel", "starttime", "endtime" ] )
- }
- }
- genfilelist( concatfile )
- {
- ; '`n' = replace `n with `r`n when writing
- ; '-' = locks the file for read, write and delete access
- file := fileopen( concatfile, "w`n-" )
- if not isobject( file ) {
- msgbox, 16, , Error: Could not open "%concatfile%" for writing. Exiting.
- exitapp
- }
- loop
- {
- if not lv_gettext( filepath, a_index )
- break
- ;stringreplace, filepath, filepath, \, /, 1
- fileappend, file '%filepath%'`n, %concatfile%
- file.writeline( "file '" filepath "'")
- }
- file.close()
- }
- runffmpeg()
- {
- local filecount := lv_getcount()
- gui, submit, nohide
- if not filecount {
- msgbox, 16, , Error: No files added for encoding.
- return
- }
- if ( filecount > 1 and not docat ) {
- runbatch()
- return
- }
- local outfile
- gui +owndialogs
- fileselectfile, outfile, s, , , % "Video (*." muxer ")"
- if errorlevel
- return
- if substr( outfile, -3 ) == "." muxer
- outfile := substr( outfile, 1, -4 )
- local cmd = format["start"]
- if ( filecount > 1 ) {
- genfilelist( filelist )
- cmd .= format( format["concat"], filelist )
- } else {
- local infile
- lv_gettext( infile, 1 )
- cmd .= format( format["normal"], infile )
- if docut {
- cmd .= format( format["cut"]
- , regexreplace( starttime
- , "\d{8}(\d\d)(\d\d)(\d\d)", "$1:$2:$3" )
- , regexreplace( endtime
- , "\d{8}(\d\d)(\d\d)(\d\d)", "$1:$2:$3" ) )
- }
- }
- if doresize
- cmd .= format( format["size"], resxupdown, resyupdown )
- cmd .= format( format["cv"], encoderv )
- if dofps
- cmd .= format( format["fps"], fpsupdown )
- if ( encoderv <> "copy" )
- cmd .= format( format[encoderv], crfslider, preset )
- cmd .= format( format["ca"], encodera )
- if ( encodera <> "copy" )
- cmd .= format( format[encodera], bra )
- cmd .= format( format["output"], outfile, muxer )
- run, cmd.exe /c %cmd% & pause
- }
- runbatch()
- {
- global
- gui +owndialogs
- fileselectfolder, selected, *%outfolder%, ,
- if errorlevel
- return
- outfolder := selected
- ; '`n' = replace `n with `r`n when writing
- ; '-' = locks the file for read, write and delete access
- file := fileopen( batchfile, "w`n-" )
- if not isobject( file ) {
- msgbox, 16, , Error: Could not open "%batchfile%" for writing. Exiting.
- exitapp
- }
- file.writeline( "@echo off" )
- local filecount := lv_getcount()
- loop, %filecount%
- {
- local cmd = format["start"]
- local infile
- lv_gettext( infile, a_index )
- cmd .= format( format["normal"], infile )
- if docut {
- cmd .= format( format["cut"]
- , regexreplace( starttime
- , "\d{8}(\d\d)(\d\d)(\d\d)", "$1:$2:$3" )
- , regexreplace( endtime
- , "\d{8}(\d\d)(\d\d)(\d\d)", "$1:$2:$3" ) )
- }
- if doresize
- cmd .= format( format["size"], resxupdown, resyupdown )
- cmd .= format( format["cv"], encoderv )
- if dofps
- cmd .= format( format["fps"], fpsupdown )
- if ( encoderv <> "copy" )
- cmd .= format( format[encoderv], crfslider, preset )
- cmd .= format( format["ca"], encodera )
- if ( encodera <> "copy" )
- cmd .= format( format[encodera], bra )
- splitpath, infile, , , , infile
- cmd .= format( format["output"], outfolder "\" infile "_" encoderv, muxer )
- file.writeline( "echo." )
- file.writeline( "echo " a_index " of " filecount)
- file.writeline( cmd )
- }
- file.writeline( "pause" )
- file.close()
- run, %batchfile%
- }
- guidropfiles()
- {
- global
- loop, parse, a_guievent, `n
- lv_add( "", a_loopfield )
- lv_modifycol()
- if ( lv_getcount() > 1 )
- guicontrol, enable, docat
- }
- guiclose()
- {
- exitapp
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement