AutoHotkey FFmpeg GUI for WebMs

WebM guide for retards in case you need it.

; This is a FFmpeg GUI for making WebMs
; If you don't already have FFmpeg, go to https://ffmpeg.zeranoe.com/builds/ and download the STATIC version
; This script was made with AutoHotkey
; If you don't already have AutoHotkey, go to https://autohotkey.com/download/ and download it
; I recommend getting the portable version, but do whatever you want
; Save this script and put it in ffmpeg's bin folder (where ffmpeg.exe and ffplay.exe are)
; You can create a shortcut to the script and put it in the desktop if that is more comfortable for you
; It only works on Windows. I assume Linux users don't need GUIs
; Quick mini-tutorial: http://puu.sh/qAf2I/4a45131f4a.webm

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force
;============================================================;
;============================================================;
startx := 10 ; default is 10
starty := 3 ; default is 6
col_1 := startx
col_2 := col_1+105
row_1 := starty
row_2 := row_1+27
row_3 := row_2+27
row_4 := row_3+27
row_5 := row_4+27
row_6 := row_5+27
row_7 := row_6+27
row_8 := row_7+27
row_9 := row_8+27
row_10 := row_9+27
row_11 := row_10+27
row_12 := row_11+27
row_13 := row_12+27
row_14 := row_13+27
row_15 := row_14+27
row_16 := row_15+27
row_17 := row_16+27
row_18 := row_17+27
row_19 := row_18+27
; Rows are for the edit boxes and buttons, which are 6 pixels taller than the text, 3 for top and 3 for bottom
; Edit boxes and buttons are both 20 pixels tall
; Buttons are placed 1 unit further than specified. If you tell it 10, it will be placed at 11
;============================================================;
;============================================================;
IniRead, def_Bitrate, FFmpeg_GUI_settings.ini, QUALITY, def_Bitrate, %A_Space%
IniRead, def_qmax, FFmpeg_GUI_settings.ini, QUALITY, def_qmax, %A_Space%
IniRead, def_Framerate, FFmpeg_GUI_settings.ini, QUALITY, def_Framerate, same as input
IniRead, def_Threads, FFmpeg_GUI_settings.ini, ENCODING, def_Threads, 3
IniRead, def_CT, FFmpeg_GUI_settings.ini, FILTERS, def_CT, 0
IniRead, def_CB, FFmpeg_GUI_settings.ini, FILTERS, def_CB, 0
IniRead, def_CL, FFmpeg_GUI_settings.ini, FILTERS, def_CL, 0
IniRead, def_CR, FFmpeg_GUI_settings.ini, FILTERS, def_CR, 0
IniRead, def_Size_X, FFmpeg_GUI_settings.ini, FILTERS, def_Size_X, %A_Space%
IniRead, def_Size_Y, FFmpeg_GUI_settings.ini, FILTERS, def_Size_Y, %A_Space%
IniRead, def_Audio_quality, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_quality, 0
IniRead, def_Audio_channels, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_channels, same as input
IniRead, def_Audio_samples, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_samples, same as input
goto drag_drop
;============================================================;
;============================================================;
drag_drop:
Gui, add, text,w280 +Center, Drag and drop your file on this window
Gui, show, w300 h300
return

GuiDropFiles:
    input_file_path = %A_GuiEvent%
    SplitPath, input_file_path,, input_file_directory,,input_file_name
    Gui, Destroy
    goto OptionsWindow
Return
;============================================================;
;============================================================;
OptionsWindow:
Gui, font, underline
Gui, add, text, cBlue gOpenInput, Input file: %input_file_path%
Gui, font
Gui, add, text,, Metadata Title
Gui, add, text,, Trim Start
Gui, add, text,, Trim Duration
Gui, add, text,, Bitrate (Kb/s)
Gui, add, text,, Max quantizer
Gui, add, text,, Framerate
Gui, add, text,, Threads
Gui, add, text,, Crop top
Gui, add, text,, Crop bottom
Gui, add, text,, Crop left
Gui, add, text,, Crop right
Gui, add, text,, Size horiz
Gui, add, text,, Size vert
Gui, add, text,, Extra filters
Gui, add, text,, Audio quality
Gui, add, text,, Audio channels
Gui, add, text,, Audio sample rate
Gui, add, edit, x100 y%row_2% w390 h20 vMeta_Title, %input_file_name%
Gui, add, edit, x100 y%row_3% w100 vTrim_Start
Gui, add, edit, x100 y%row_4% w100 vTrim_Duration
Gui, add, edit, x100 y%row_5% w100 vBitrate, %def_Bitrate%
Gui, add, edit, x100 y%row_6% w100 vqmax, %def_qmax%
Gui, add, edit, x100 y%row_7% w100 vFramerate, %def_Framerate%
Gui, add, edit, x100 y%row_8% w100 vThreads, %def_Threads%
Gui, add, text, x%col_1% y215 w480 0x10 ; horizontal line
Gui, add, text, x%col_1% y216 w480 0x10 ; horizontal line
Gui, add, edit, x100 y%row_9% w100 vCT, %def_CT%
Gui, add, edit, x100 y%row_10% w100 vCB, %def_CB%
Gui, add, edit, x100 y%row_11% w100 vCL, %def_CL%
Gui, add, edit, x100 y%row_12% w100 vCR, %def_CR%
Gui, add, edit, x100 y%row_13% w100 vSize_X, %def_Size_X%
Gui, add, edit, x100 y%row_14% w100 vSize_Y, %def_Size_Y%
Gui, add, edit, x100 y%row_15% w390 vExtra_Filters
Gui, add, text, x%col_1% y404 w480 0x10 ; horizontal line
Gui, add, text, x%col_1% y405 w480 0x10 ; horizontal line
Gui, add, edit, x100 y%row_16% w100 vAudio_quality, %def_Audio_quality%
Gui, add, edit, x100 y%row_17% w100 vAudio_channels, %def_Audio_channels%
Gui, add, edit, x100 y%row_18% w100 vAudio_samples, %def_Audio_samples%
Gui, add, text, x%col_1% y485 w480 0x10 ; horizontal line
Gui, add, text, x%col_1% y486 w480 0x10 ; horizontal line
Gui, add, button, x210 y%row_5% h21 gdef_Bitrate, Make default
Gui, add, button, x210 y%row_6% h21 gdef_qmax, Make default
Gui, add, button, x210 y%row_7% h21 gdef_Framerate, Make default
Gui, add, button, x210 y%row_8% h21 gdef_Threads, Make default
Gui, add, button, x210 y%row_9% h21 gdef_CT, Make default
Gui, add, button, x210 y%row_10% h21 gdef_CB, Make default
Gui, add, button, x210 y%row_11% h21 gdef_CL, Make default
Gui, add, button, x210 y%row_12% h21 gdef_CR, Make default
Gui, add, button, x210 y%row_13% h21 gdef_Size_X, Make default
Gui, add, button, x210 y%row_14% h21 gdef_Size_Y, Make default
Gui, add, button, x210 y%row_16% h21 gAudio_quality, Make default
Gui, add, button, x210 y%row_17% h21 gAudio_channels, Make default
Gui, add, button, x210 y%row_18% h21 gAudio_samples, Make default
Gui, add, checkbox, x10 y%row_19% vApply_Filters, Check this if you want to apply filters (cropping, resizing, etc.)
Gui, add, checkbox, x10 vEnable_audio, Check this if you want to enable audio
Gui, add, button, x10 w240 h50 gffmpeg, Execute the ffmpeg command
Gui, add, button, x250 y527 w240 h25 gPreviewWebm, Preview the WebM
Gui, add, button, x250 y552 w240 h25 gOpenWebm, Open the WebM
Gui, add, text, x10, The WebM will have the same name as the input and will be placed in the same directory.
Gui, add, text,+Wrap w480, If the command prompt fails to open, the FFmpeg command will be on your clipboard, so open the command prompt, paste the command and then press enter.
Gui, add, button, x10 w480 ginfo, INFO
Gui, add, link,, <a href="http://pastebin.com/NXzfdja7">Source code / update</a>
Gui, show, w500, ffmpeg for retards
return
;============================================================;
;============================================================;
OpenInput:
run, %input_file_path%
return
;============================================================;
;============================================================;
PreviewWebm:
Gui, submit, nohide
if (Trim_Start != "" && Trim_Duration != ""){
    ffmpeg_preview = ffplay -ss %Trim_Start% -i "%input_file_path%"
    ffmpeg_preview = %ffmpeg_preview% -t %Trim_Duration%
    } else {
    ffmpeg_preview = ffplay -i "%input_file_path%"
    }

if (Apply_Filters){
ffmpeg_filters = crop=iw-%CL%-%CR%:ih-%CT%-%CB%:%CL%:%CT%
if (Size_X && !Size_Y){
    ffmpeg_filters = %ffmpeg_filters%,scale=%Size_X%:-1
    }
if (Size_Y){
    ffmpeg_filters = %ffmpeg_filters%,scale=-1:%Size_Y%
    }
if (Extra_Filters){
    ffmpeg_filters = %ffmpeg_filters%,%Extra_Filters%
    }
ffmpeg_preview = %ffmpeg_preview% -vf "%ffmpeg_filters%"
    }

if !(Enable_audio){
    ffmpeg_preview := ffmpeg_preview . " -an"
}

clipboard := ffmpeg_preview
run, %comspec% /k %ffmpeg_preview%
return
;============================================================;
;============================================================;
ffmpeg:
Gui, submit, nohide
if (Trim_Start != "" && Trim_Duration != ""){
    ffmpeg_command = ffmpeg -ss %Trim_Start% -i "%input_file_path%"
    ffmpeg_command = %ffmpeg_command% -t %Trim_Duration%
    } else {
    ffmpeg_command = ffmpeg -i "%input_file_path%"
    }
ffmpeg_command := ffmpeg_command . " -c:v libvpx -threads " . Threads . " -quality good -cpu-used 0 -lag-in-frames 16 -auto-alt-ref 1 -qcomp 1"
if (Bitrate != ""){
    ffmpeg_command := ffmpeg_command . " -b:v " . Bitrate . "K"
    }
if (qmax != ""){
    ffmpeg_command := ffmpeg_command . " -qmax " . qmax
    }
;==============================;
if (Apply_Filters){
if (CT = "")
    {
    CT=0
    }
if (CB = "")
    {
    CB=0
    }
if (CL = "")
    {
    CL=0
    }
if (CR = "")
    {
    CR=0
    }
ffmpeg_filters = crop=iw-%CL%-%CR%:ih-%CT%-%CB%:%CL%:%CT%
if (Size_X && !Size_Y){
    ffmpeg_filters = %ffmpeg_filters%,scale=%Size_X%:-1
    }
if (Size_Y){
    ffmpeg_filters = %ffmpeg_filters%,scale=-1:%Size_Y%
    }
if (Extra_Filters){
    ffmpeg_filters = %ffmpeg_filters%,%Extra_Filters%
    }
ffmpeg_command = %ffmpeg_command% -vf "%ffmpeg_filters%"
}

if (Enable_audio){
    if (Audio_quality = ""){
        Audio_quality=0
    }
    ffmpeg_command := ffmpeg_command . " -c:a libvorbis -qscale:a " . Audio_quality
    if (Audio_channels != "same as input" && Audio_channels != ""){
        ffmpeg_command := ffmpeg_command . " -ac " . Audio_channels
    }
    if (Audio_samples != "same as input" && Audio_samples != ""){
        ffmpeg_command := ffmpeg_command . " -ar " . Audio_samples
    }
} else {
    ffmpeg_command := ffmpeg_command . " -an"
}
;;==============================;;
if (Framerate != "same as input"){
    ffmpeg_command := ffmpeg_command . " -r " . Framerate
    }
ffmpeg_command = %ffmpeg_command% -metadata title="%Meta_Title%"
ffmpeg_command := ffmpeg_command . " -sn -y -f webm"
clipboard = %ffmpeg_command% -pass 1 NUL && %ffmpeg_command% -pass 2 "%input_file_directory%\%input_file_name%.webm" && del ffmpeg2pass-0.log
run, %comspec% /k %ffmpeg_command% -pass 1 NUL && %ffmpeg_command% -pass 2 "%input_file_directory%\%input_file_name%.webm" && del ffmpeg2pass-0.log
return
;============================================================;
;============================================================;
OpenWebm:
ifExist, %input_file_directory%\%input_file_name%.webm
run, %input_file_directory%\%input_file_name%.webm
return
;============================================================;
;============================================================;
info:
info =
(
First of all, if you don't want to use a certain function, leave it blank.
If there is any problem with this script or if you have any suggestions, send me a message at my pastebin http://pastebin.com/u/thisisthepastebinuse
Quick mini-tutorial: http://puu.sh/qAf2I/4a45131f4a.webm

=============================================================================

Metadata Title
4chanX allows users to see the title metadata of a video file. This means that you can put the source of your chinese cartoons there so that other anons don't spam the thread with SAUCE, though they'll do it anyway.

Trim Start and Trim Duration
If your input video file is too long, you might want to trim it to make it shorter. Trim Start is the point at which FFmpeg will start encoding the WebM, and Trim Duration is the duration of the WebM. The starting point could be 2:12.257, for example, and the duration could be 12 or 1:28. As you can see, you can either use either seconds or the full HH:MM:SS.MIL notation when defining the starting point or the duration of the trim.

Bitrate
This is the target bitrate of the WebM. How do you know what bitrate your video should have? Use the following formula:
FileSize*8/Time
FileSize is in KB and time is in seconds. If I want a 3000 kB WebM which is 15 seconds long, its target bitrate would be 3000*8/15 = 1600 KB.

Max quantizer
This can be a number from 0 to 63. The lower this number, the better the image quality you will get.

Framerate
The framerate of your WebM. Don't touch this if you don't want to change the framerate of the original video.

Threads
The number of threads you want to use when encoding, can't be 0 (auto) with VP8. It is recommended to use the number of real cores - 1. I assume most people have a 4 core CPU, so the default value is 3.

=============================================================================

Crop top/bottom/left/right
As its name indicates, this will crop your video file. Useful for getting rid of the letterbox some videos have.

Size horix/vert
The size of your WebM. Be careful, you only want to define one of the sizes, not both of them. If you write the hrizontal size of your video, the vertical size will be automatically calculated in order to keep the aspect ratio of your video. If you write the vertical size of your WebM, the horizontal one will be automatically calculated according to the aspect ratio of the input file.

Extra filters
Let's say you want to rotate your video file counterclockwise. You would have to write "transpose=cclock" in the input box, without the quotes, obviously. If you want to transpose and then do something else, you have to separate the filters by a comma, like this: "transpose=cclock,another=filter", without the quotes.

In order to apply the cropping, resizing and other filters, you need to check the checkbox under "Extra filters".

=============================================================================

Audio quality
Values from 0 to 10. 10 is the best quality and 0 is the worst. You'll pretty much never need a quality higher than 2.

Audio channels
2 is stereo, 1 is mono. Anything more than 2 is overkill for 4chan.

Audio sample rate
Don't touch this if you don't know what a sampling rate is.

In order to apply the audio settings and get a WebM with sound, you need to check the appropiate checkbox.

=============================================================================

4chan WebM limits
/wsg/ and /gif/:    4096 KB, 300 seconds (5 min), 2048x2048 pixels, sound allowed
other boards:   3072 KB, 120 seconds (2 min), 2048x2048 pixels, no sound allowed

Documentation
http://wiki.webmproject.org/ffmpeg
https://trac.ffmpeg.org/wiki/Encode/VP8
https://www.ffmpeg.org/ffmpeg.html
https://www.ffmpeg.org/ffmpeg-codecs.html#libvpx
https://www.webmproject.org/docs/encoder-parameters/
https://wiki.installgentoo.com/index.php/WebM

A guide made by Anon for /wsg/:
http://i.imgur.com/5o2yTYc.png
http://4chandata.org/wsg/WebM-Academy-a810990
)
GUI, 2:add, Edit, w480 h700 -E0x200 +Readonly, %info%
GUI, 2:show, w500, INFO
return
;============================================================;
;============================================================;
; This section writes the values from the boxes to the ini file when the user presses the "Make default" button

def_Bitrate:
Gui, submit, nohide
IniWrite, %Bitrate%, FFmpeg_GUI_settings.ini, QUALITY, def_Bitrate
return

def_qmax:
Gui, submit, nohide
IniWrite, %qmax%, FFmpeg_GUI_settings.ini, QUALITY, def_qmax
return

def_Framerate:
Gui, submit, nohide
IniWrite, %Framerate%, FFmpeg_GUI_settings.ini, QUALITY, def_Framerate
return

def_Threads:
Gui, submit, nohide
IniWrite, %Threads%, FFmpeg_GUI_settings.ini, ENCODING, def_Threads
return

def_CT:
Gui, submit, nohide
IniWrite, %CT%, FFmpeg_GUI_settings.ini, FILTERS, def_CT
return

def_CB:
Gui, submit, nohide
IniWrite, %CB%, FFmpeg_GUI_settings.ini, FILTERS, def_CB
return

def_CL:
Gui, submit, nohide
IniWrite, %CL%, FFmpeg_GUI_settings.ini, FILTERS, def_CL
return

def_CR:
Gui, submit, nohide
IniWrite, %CR%, FFmpeg_GUI_settings.ini, FILTERS, def_CR
return

def_Size_X:
Gui, submit, nohide
IniWrite, %Size_X%, FFmpeg_GUI_settings.ini, FILTERS, def_Size_X
return

def_Size_Y:
Gui, submit, nohide
IniWrite, %Size_Y%, FFmpeg_GUI_settings.ini, FILTERS, def_Size_Y
return

Audio_quality:
Gui, submit, nohide
IniWrite, %Audio_quality%, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_quality
return

Audio_channels:
Gui, submit, nohide
IniWrite, %Audio_channels%, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_channels
return

Audio_samples:
Gui, submit, nohide
IniWrite, %Audio_samples%, FFmpeg_GUI_settings.ini, QUALITY, def_Audio_samples
return
Edit
Pub: 20 Nov 2017 00:08 UTC
Edit: 20 Nov 2017 09:39 UTC
Views: 2345