Here's my ffmpeg wrapper for any one interested, it acts on all selected files in explorer, it does enough that i no longer have a video conversion utility installed,i use avidemux for all other editing needs...
which spawns a menu that will act on all files selected inside explorer,any converted or output files such as a gif output will be to the same folder as selected files...
Edit:One more thing,recordings are saved to active/lastSavedTo explorer path...
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, force
DetectHiddenWindows, on
SetBatchLines, -1
GroupAdd, Explore, ahk_class CabinetWClass ; Add a class to the group
GroupAdd, Explore, ahk_class ExploreWClass ; Add a other class to the group
#ifWinActive,ahk_group Explore ; Set hotkeys to work in explorer only
Menu, Tray, Icon, C:\Windows\System32\shell32.dll, 85
Menu, Tray, Tip, %A_ScriptName%`n`nCtrl+Shift+Alt+C : ContextMenu `nCtrl+Shift+Alt+Esc : Interrupt Active Conversion.
TrayTip, [CyLoN] %A_ScriptName%, Ctrl+Shift+Alt+C : ContextMenu`n Ctrl+Shift+F11 : StopAnyActiveRecording`n Ctrl+Shift+F12 : Start/Stop Lossless Recording`n `n Ctrl+F9/Ctrl+Shift+F9 --->Start/Stop Recording Tones for OBS.
;OBS Hotkey ToneGenerator thread
SetTimer, obsRecNotifier, 2500
;replace tray menu with created menu
; OnMessage(0x404, "AHK_NOTIFYICON") ;allowing normal tray menu as replacing it makes process termination a tad difficult.
IfNotExist, %A_ScriptName%.README.txt
FileAppend, Press Ctrl+Shift+Alt+C to trigger menu and select conversion/processing task from the menu.`n For Any command on the menu to work ffmpeg.exe must be placed in the windows directory. `n Ctrl+Shift+Alt+Esc can be used to interrupt any active conversion. Incomplete file needs to be manually deleted though! `n`n Ctrl+Shift+Alt+P toggles progress bar. `n`nUpon Interruption Incomplete File Will Be deleted. `n Ctrl+Shift+F12 to record losless video to last folder that was recorded to `n`t Ctrl+Shift+F11 to stop any active recording`, Sound Tones will signify both actions. , %A_ScriptName%.README.txt
progressBarActive := True
; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Convert to Mp3 256k, MenuHandler
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Convert to Mp3 48k, MenuHandler
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Extract mp3 from Selected (no-conversion), MenuHandler
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Extract mp3 from Selected (no-conversion) + VideoThumbnail@30secMark, MenuHandler
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Trim Silence from Mp3, MenuHandler
Menu, MyMenu, Add ; Add a separator line.
Menu, MyMenu, Add, Resync Audio [+/-] prefixed seconds, MenuHandler
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
; Create another menu destined to become a submenu of the above menu.
Menu, Submenu1, Add, MP4 SourceQuality, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, MP4 720p, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, MP4 480p, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, MP4 360p, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, MKV To MP4 SourceQuality, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, FLV To MP4 SourceQuality, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, TS To MP4 SourceQuality, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, DAT To MP4 SourceQuality, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, Change Video Container to MP4(Fastest)(Identical Video/Audio to Source) - Limited MediaPlayer Support Based On Source Format, MenuHandler
Menu, Submenu1, Add ; Add a separator line.
Menu, Submenu1, Add, MP4 Lossless Conversion(Source or Superior Quality and Greatest Size), MenuHandler
Menu, Submenu2, Add, ffmpeg_RECORD_display, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_display_activeWindow, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_display_mic, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_display_stereoMix, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_mic, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_webcam_mic, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_RECORD_webcam_stereoMix, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_LIST_DEVICES_DEBUG, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED_AudioResync@450ms+AllInputs+Win7Inputs, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED_AudioResync@450ms, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_LOSLESS_display_GreatestSize_stereoMix_AudioResync@450ms, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED, MenuHandler
Menu, Submenu2, Add ; Add a separator line.
Menu, Submenu2, Add, ffmpeg_LOSLESS_display_GreatestSize_stereoMix, MenuHandler
; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
Menu, MyMenu, Add, Convert to Mp4, :Submenu1
Try
Menu, MyMenu, Icon, Convert to Mp4, Shell32.dll, 116, 40
Menu, MyMenu, Add, RECORD, :Submenu2
Try
Menu, MyMenu, Icon, RECORD, Shell32.dll, 204, 40
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Extract Animated Gif from Video, MenuHandler ; Add another menu item beneath the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Extract VideoThumbnail from Video@30secMark at Video Resolution, MenuHandler ; Add another menu item beneath the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Extract clip from video at SourceQuality, MenuHandler ; Add another menu item beneath the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Delete other file format with Mp3 counterpart i.e(x.avi and x.mp3), MenuHandler ; Add another menu item beneath the submenu.
Menu, MyMenu, Add ; Add a separator line below the submenu.
Menu, MyMenu, Add, Delete other file format with Mp4 counterpart i.e(x.avi and x.mp4), MenuHandler ; Add another menu item beneath the submenu.
;Menu, MyMenu, Show
return ; End of script's auto-execute section.
+!^c::
Menu, MyMenu, Show
Return
#IfWinActive,ahk_group Explore ; Set hotkeys to work in explorer only
MButton::
Menu, MyMenu, Show
Return
#IfWinActive
+!^p::
If progressBarActive{
Progress, off
progressBarActive := False
}Else{
progressBarActive := True
Progress, a t b x0 y0 w%A_ScreenWidth%, [%i%/%listToConvNum%] %OutFileName%, PROCESSING, Conversion Progress ;'b' always ontop off & 't' to give progress bar own button on taskbar
Progress, % i*100/listToConvNum ; Set the position of the bar to 0-100
}
Return
+!^Esc::
term := True ;send termination signal to current processing loop
Process, Close, ffmpeg.exe
RunWait, %comspec% /c Taskkill /f /t /im ffmpeg.exe, , Hide
MsgBox, 0x40010, %A_ScriptName%, INTERRUPTED!`n`nLastProcessedFile[Incomplete Files Will Be Deleted]: `n%OutFileName%
FileDelete, %OutDir%\%convertTo%
Return
MenuHandler:
;MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
Sleep, 250
sel := Explorer_GetSelected()
path := Explorer_GetPath()
Loop, Parse, sel, `n
{
SplitPath, A_LoopField, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
IfEqual, OutExtension, lnk
{
FileGetShortcut, %A_LoopField%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
SplitPath, A_LoopField, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
}
listToConv .= OutExtension != "lnk" ? A_LoopField "`n" : OutTarget "`n"
}
IfEqual, A_ThisMenu, Submenu2
Goto, recHandler ;jump
MsgBox, 0x40031, %A_ScriptName%, %A_ThisMenuItem%`? `n`n***Invalid files will be ignored`,so they can be included in selection.*** `n`n %listToConv%
IfMsgBox, Cancel
Return
listToConvNum := ListCount(listToConv)
listToConv := ""
FileAppend, [%TimeString%] COMMAND ---> %A_ThisMenuItem% `n, %A_Desktop%\%A_ScriptName%.LOG.log
Loop, Parse, sel, `n
{
SplitPath, A_LoopField, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
IfEqual, OutExtension, lnk
{
FileGetShortcut, %A_LoopField%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
SplitPath, OutTarget, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
}
FormatTime, TimeString, T8 T2 T4 R
FileAppend, [%TimeString%] processing ---> %A_LoopField% `n, %A_Desktop%\%A_ScriptName%.LOG.log
i++
If progressBarActive
{
; WinGetActiveTitle, activeTitle
; Progress, b x0 y0 w%A_ScreenWidth%, %OutFileName%, CONVERTING, This Progress Bar
Progress, a t b x0 y0 w%A_ScreenWidth%, [%i%/%listToConvNum%] %OutFileName%, PROCESSING, Conversion Progress ;'b' always ontop off & 't' to give progress bar own button on taskbar
Progress, % i*100/listToConvNum ; Set the position of the bar to 0-100
; Sleep, 25
; WinActivate, %activeTitle% ;to prevent progress bar stealing focus while processing files.
}
;mp3 conversions/extractions
If ( A_ThisMenuItem = "Convert to Mp3 256k" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%.mp3
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -acodec libmp3lame -ab 256 "%OutDir%\%OutNameNoExt%.mp3", , Hide
}Else If ( A_ThisMenuItem = "Convert to Mp3 48k" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%.mp3
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -acodec libmp3lame -ab 48k "%OutDir%\%OutNameNoExt%.mp3", , Hide
}Else If ( A_ThisMenuItem = "Extract mp3 from Selected (no-conversion)" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%.mp3
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -vn "%OutDir%\%OutNameNoExt%.mp3", , Hide
}Else If ( A_ThisMenuItem = "Extract mp3 from Selected (no-conversion) + VideoThumbnail@30secMark" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%.mp3
RunWait, %comspec% /c echo n|ffmpeg -ss 00:00:30 -i "%OutDir%\%OutFileName%" -vframes 1 -q:v 2 "%OutDir%\%OutNameNoExt%.jpg", , Hide
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -vn "%OutDir%\%OutNameNoExt%.mp3", , Hide
}Else If ( A_ThisMenuItem = "Trim Silence from Mp3" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%[noSilence].mp3
InputBox, threshHold, Input Silence Threshold in dB, Lower is More sensitive & will trim more sound`,i.e -25 will more trimming than -40(which is the default)!, , 636, 136, 538, 416, , , -40
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -af silenceremove=0:0:0:-1:1:%threshHold%dB -y "%OutDir%\%OutNameNoExt%[noSilence].mp3", , Hide
}Else If ( A_ThisMenuItem = "Resync Audio [+/-] prefixed seconds" AND A_ThisMenu = "MyMenu" ){
convertTo = %OutNameNoExt%[Resync].mp4
InputBox, resyncSeconds, Resync Audio, Input Seconds To Pull-Back/Push-Fwd audio with respect to video!`n--> output video will have [Resync] suffix., , 428, 144, 564, 212, , , -0.45
If ErrorLevel
Return
RunWait, %comspec% /c ffmpeg -i "%OutDir%\%OutFileName%" -itsoffset %resyncSeconds% -i "%OutDir%\%OutFileName%" -map 0:0 -map 1:1 -acodec copy -vcodec copy -y "%OutDir%\%OutNameNoExt%[Resync].mp4", , Hide
}
;Convert to Mp4
If ( A_ThisMenuItem = "MP4 SourceQuality" AND A_ThisMenu = "Submenu1" ){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "MP4 720p" AND A_ThisMenu = "Submenu1" ){
convertTo = %OutNameNoExt%[720p].mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -s hd720 "%OutDir%\%OutNameNoExt%[720p].mp4", , Hide
}Else If ( A_ThisMenuItem = "MP4 480p" AND A_ThisMenu = "Submenu1" ){
convertTo = %OutNameNoExt%[480p].mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -s hd480 "%OutDir%\%OutNameNoExt%[480p].mp4", , Hide
}Else If ( A_ThisMenuItem = "MP4 360p" AND A_ThisMenu = "Submenu1" ){
convertTo = %OutNameNoExt%[360p].mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -s ega "%OutDir%\%OutNameNoExt%[360p].mp4", , Hide
}Else If ( A_ThisMenuItem = "MKV To MP4 SourceQuality" AND A_ThisMenu = "Submenu1" AND OutExtension = "mkv"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "FLV To MP4 SourceQuality" AND A_ThisMenu = "Submenu1" AND OutExtension = "flv"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -c copy -copyts "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "TS To MP4 SourceQuality" AND A_ThisMenu = "Submenu1" AND OutExtension = "ts"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -c copy -copyts "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "DAT To MP4 SourceQuality" AND A_ThisMenu = "Submenu1" AND OutExtension = "dat" OR A_ThisMenuItem = "DAT To MP4 SourceQuality" AND A_ThisMenu = "Submenu1" AND OutExtension = "mpg"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -c:v libx264 -preset slow -crf 15 -c:a aac -strict experimental -b:a 128k "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "Change Video Container to MP4(Fastest)(Identical Video/Audio to Source) - Limited MediaPlayer Support Based On Source Format" AND A_ThisMenu = "Submenu1"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -c copy -copyts -scodec mov_text "%OutDir%\%OutNameNoExt%.mp4", , Hide
}Else If ( A_ThisMenuItem = "MP4 Lossless Conversion(Source or Superior Quality and Greatest Size)" AND A_ThisMenu = "Submenu1"){
convertTo = %OutNameNoExt%.mp4
RunWait, %comspec% /c echo n|ffmpeg -i "%OutDir%\%OutFileName%" -c:v libx264 -crf 0 -c:a copy -copyts "%OutDir%\%OutNameNoExt%.mp4", , Hide
}
;Video to Gif
If ( A_ThisMenuItem = "Extract Animated Gif from Video" AND A_ThisMenu = "MyMenu" ){
If !timeRangeDefined{
InputBox, startTime, video2gif, StartTime(time in video where gif will start off)`,`nomitting starttime by clearing the input field will `nconvert full video into gif!`n`nNOTE:gif files are upto 20x the size of a video equivalent..., , , , , , , , 00:01:00
InputBox, endTime, video2gif, gifLength(how many seconds to encode to gif since start time)`,`n`n10`, means 10 seconds starting from previously input start time will be`nsaved to gif`,so based on previous default value`, gif will be 10seconds`nlong and will start at minute 1 of the video..., , 446, 212, , , , , 10
timeRangeDefined := True
}
If startTime
RunWait, %comspec% /c echo n| ffmpeg -i "%OutDir%\%OutFileName%" -ss %startTime% -t %endTime% "%OutDir%\%OutNameNoExt%.gif", , Hide
Else If endTime
RunWait, %comspec% /c echo n| ffmpeg -i "%OutDir%\%OutFileName%" "%OutDir%\%OutNameNoExt%.gif", , Hide
Else If (!startTime AND !endTime){
MsgBox, 0x40010, %A_ScriptName%, Range NOT DEFINED OR INCORRECTLY DEFINED`, TryAGAIN!
}
}
;video snapshot
If ( A_ThisMenuItem = "Extract VideoThumbnail from Video@30secMark at Video Resolution" AND A_ThisMenu = "MyMenu" ){
RunWait, %comspec% /c echo n|ffmpeg -ss 00:00:30 -i "%OutDir%\%OutFileName%" -vframes 1 -q:v 2 "%OutDir%\%OutNameNoExt%.jpg", , Hide
}
;extract clip from video
If ( A_ThisMenuItem = "Extract clip from video at SourceQuality" AND A_ThisMenu = "MyMenu" ){
If !timeRangeDefined{
InputBox, startTime, clipExtract, StartTime(time in video where clip will start off)`,`nomitting starttime by clearing the input field will `nextract clip from video begining + n Seconds , , , , , , , , 00:01:00
InputBox, endTime, clipExtract, clipLength(how many seconds to encode to clip since start time)`,`n`n10`, means 10 seconds starting from previously input start time will be`nsaved to clip`,so based on previous default value`, clip will be 10seconds`nlong and will start at minute 1 of the video..., , 446, 212, , , , , 10
timeRangeDefined := True
}
If startTime
RunWait, %comspec% /c echo n| ffmpeg -i "%OutDir%\%OutFileName%" -ss %startTime% -t %endTime% "%OutDir%\%OutNameNoExt%.CLIP%A_NOW%.mp4", , Hide
Else If endTime
RunWait, %comspec% /c echo n| ffmpeg -i "%OutDir%\%OutFileName%" -ss 00:00:00 -t %endTime% "%OutDir%\%OutNameNoExt%.CLIP%A_NOW%.mp4", , Hide
Else If (!startTime AND !endTime){
MsgBox, 0x40010, %A_ScriptName%, Range NOT DEFINED OR INCORRECTLY DEFINED`, TryAGAIN!
}
}
;Delete Files with MP4 Counter part
If ( A_ThisMenuItem = "Delete other file format with Mp4 counterpart i.e(x.avi and x.mp4)" AND A_ThisMenu = "MyMenu" AND OutExtension != "Mp4"){
FileGetSize, thisFileSize, %OutDir%\%OutNameNoExt%.mp4
IfExist, %OutDir%\%OutNameNoExt%.mp4 ;if the file has an MP4 counterpart delete original,i.e current file.
If (thisFileSize AND thisFileSize != 0)
{
FileDelete, %OutDir%\%OutFileName%
FormatTime, TimeString, T8 T2 T4 R
FileAppend, [%TimeString%] DELETING ---> %A_LoopField% `n, %A_Desktop%\%A_ScriptName%.LOG.log
}
}Else If ( A_ThisMenuItem = "Delete other file format with Mp3 counterpart i.e(x.avi and x.mp3)" AND A_ThisMenu = "MyMenu" AND OutExtension != "mp3" AND OutExtension != "jpg" AND OutExtension != "description"){
FileGetSize, thisFileSize, %OutDir%\%OutNameNoExt%.mp3
IfExist, %OutDir%\%OutNameNoExt%.mp3 ;if the file has an MP4 counterpart delete original,i.e current file.
If (thisFileSize AND thisFileSize != 0)
{
FileDelete, %OutDir%\%OutFileName%
FormatTime, TimeString, T8 T2 T4 R
FileAppend, [%TimeString%] DELETING ---> %A_LoopField% `n, %A_Desktop%\%A_ScriptName%.LOG.log
}
}
;Zero File Remnant Safeguard
FileGetSize, convertToSize, %OutDir%\%convertTo%
If (convertToSize = 0){
MsgBox, 0x40010, %A_ScriptName%, Conversion To %convertTo% Failed!`n`nPress Ok to delete zerobyte file and proceed with conversion.
FileDelete, %OutDir%\%convertTo%
}
If term
{
Progress, Off
stats := ""
term := ""
convertTo := ""
i := ""
Return
}
If !stats
stats .= "`n" A_ThisMenuItem "`n[Only Valid Selected Files below are acted UpOn...Rest are Ignored.]" "`n`n"
stats .= A_LoopField "`n"
}
Progress, 100 ; Set the position of the bar to 0-100
timeRangeDefined := False ;reset
MsgBox, 0x40040, %A_ScriptName%, CONVERSION COMPLETE! %stats%
Progress, Off
stats := ""
term := ""
convertTo := ""
i := ""
return
/*
Library for getting info from a specific explorer window (if window handle not specified, the currently active
window will be used). Requires AHK_L or similar. Works with the desktop. Does not currently work with save
dialogs and such.
Explorer_GetSelected(hwnd="") - paths of target window's selected items
Explorer_GetAll(hwnd="") - paths of all items in the target window's folder
Explorer_GetPath(hwnd="") - path of target window's folder
example:
F1::
path := Explorer_GetPath()
all := Explorer_GetAll()
sel := Explorer_GetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
return
Joshua A. Kinnison
2011-04-27, 16:12
*/
Explorer_GetPath(hwnd="")
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
return A_Desktop
path := window.LocationURL
path := RegExReplace(path, "ftp://.*@","ftp://")
StringReplace, path, path, file:///
StringReplace, path, path, /, \, All
; thanks to polyethene
Loop
If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
Else Break
return path
}
Explorer_GetAll(hwnd="")
{
return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
return Explorer_Get(hwnd,true)
}
Explorer_GetWindow(hwnd="")
{
; thanks to jethrow for some pointers here
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process!="explorer.exe")
return
if (class ~= "(Cabinet|Explore)WClass")
{
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window
}
else if (class ~= "Progman|WorkerW")
return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
{
ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
if !hwWindow ; #D mode
ControlGet, hwWindow, HWND,, SysListView321, A
ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
Loop, Parse, files, `n, `r
{
path := base "\" A_LoopField
IfExist %path% ; ignore special icons like Computer (at least for now)
ret .= path "`n"
}
}
else
{
if selection
collection := window.document.SelectedItems
else
collection := window.document.Folder.Items
for item in collection
ret .= item.path "`n"
}
return Trim(ret,"`n")
}
ListCount(ByRef list){
StringReplace, list, list, `n, `n, UseErrorLevel
Return ErrorLevel + 1
}
INI(rw, ini_section, ini_key, key_value:="", key_default_value:="", ini_file:="######.ini"){ ;r/w - 'r' to read & 'w' to write to ini
If (rw = "r"){ ;read from ini
IniRead, thisKey, %ini_file%, %ini_section%, %ini_key%, %key_default_value%
Return ( thisKey != "ERROR" ? thisKey : "")
}Else{ ;write to ini
IniWrite, %key_value%, %ini_file%, %ini_section%, %ini_key%
}
}
;==========================================================
GuiStart:
Gui , font, s8 bold, Verdana
Gui , Add , button , w150 h75 vButton1 gGuiClose, RECORDING...`n`nClick to Terminate Recording!
Gui , -caption
Gui , Show ,AutoSize Center xCenter y0 NA, ffmpeg.RECORDER
Return
GuiClose:
Critical
GuiControl,, Button1, Stopping...
While ( WinExist("ahk_pid " . PID) OR WinExist("ahk_pid " . pid1) OR WinExist("ahk_pid " . pid2) OR WinExist("ahk_pid " . pid3) ){
WinClose, ahk_pid %PID%
WinClose, ahk_pid %PID1%
WinClose, ahk_pid %PID2%
WinClose, ahk_pid %PID3%
If (A_Index=10){
Process, Close, %pid2% ;pid 2 is reserved for audio recording instances that tend to get stuck!!!
WinActivate, ahk_pid %pid3%
PostMessage, 0x112, 0xF060,,, ahk_pid %pid3% ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
}
Sleep, 50
}
Gui, Destroy
Critical, off
MsgBox, 0x40040, %A_ScriptName%, Recording Saved to %SaveDir%\%fileName%
Return
;========================================================
;record menu handlers
recHandler:
msgout:=""
( INI("r", "DEVICES", "PrimaryMicrophone",,, "ffmpeg.rec.ini") ? "" : INI("w", "DEVICES", "PrimaryMicrophone", "Microphone (Realtek High Defini",, "ffmpeg.rec.ini") )
( INI("r", "DEVICES", "SpeakerOutputStereoMix",,, "ffmpeg.rec.ini") ? "" : INI("w", "DEVICES", "SpeakerOutputStereoMix", "Stereo Mix (Realtek High Defini",, "ffmpeg.rec.ini") )
( INI("r", "DEVICES", "USBCamera",,, "ffmpeg.rec.ini") ? "" : INI("w", "DEVICES", "USBCamera", "USB 2.0 Camera",, "ffmpeg.rec.ini") )
( INI("r", "RecordingFPS", "RecordingFPS",,, "ffmpeg.rec.ini") ? "" : INI("w", "RecordingFPS", "RecordingFPS", "30",, "ffmpeg.rec.ini") )
( INI("r", "BufferSize", "BufferSize",,, "ffmpeg.rec.ini") ? "" : INI("w", "BufferSize", "BufferSize", "200M",, "ffmpeg.rec.ini") )
( INI("r", "BufferSize", "RealTimeBufferSize",,, "ffmpeg.rec.ini") ? "" : INI("w", "BufferSize", "RealTimeBufferSize", "1024M",, "ffmpeg.rec.ini") )
path := Explorer_GetPath()
lastSaveDir := INI("r", "LastSaveDir", "LastSaveDir",,, "ffmpeg.rec.ini")
SaveDir := ( InStr(path, ":\") ? path : (lastSaveDir ? lastSaveDir : A_Desktop) )
INI("w", "LastSaveDir", "LastSaveDir", SaveDir,, "ffmpeg.rec.ini")
devMicrophonePrimary := INI("r", "DEVICES", "PrimaryMicrophone",,, "ffmpeg.rec.ini")
devStereoMix := INI("r", "DEVICES", "SpeakerOutputStereoMix",,, "ffmpeg.rec.ini")
devUsbCamera := INI("r", "DEVICES", "USBCamera",,, "ffmpeg.rec.ini")
recFPS := INI("r", "RecordingFPS", "RecordingFPS",,, "ffmpeg.rec.ini")
bufferSize := INI("r", "BufferSize", "BufferSize",,, "ffmpeg.rec.ini") ;-bufsize
rtBufferSize := INI("r", "BufferSize", "RealTimeBufferSize",,, "ffmpeg.rec.ini") ;-rtbufsize
; MsgBox % devMicrophonePrimary "`n" devStereoMix "`n" devUsbCamera "`n" recFPS "`n" bufferSize
If (A_ThisMenu = "Submenu2" AND A_ThisMenuItem != "ffmpeg_LIST_DEVICES_DEBUG"){
WinGet, activeProcess, ProcessName, A
InputBox, fileName, SaveAs (mp4 for HD`,any other for LowRes), Input file name to save to desktop(including extension):, , 350, 136, , , , , %activeProcess%[%A_Now%].mp4
If ErrorLevel
Return
}Else If ( fileName="" || !InStr(fileName, ".") ){ ;if cancel or no extension defined
If (A_ThisMenuItem != "ffmpeg_LIST_DEVICES_DEBUG"){
MsgBox, 0x40010, %A_ScriptName%, Invalid FileName or No File Extension Given`, Aborting!
Return
}
}
If ( A_ThisMenuItem = "ffmpeg_RECORD_display" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f gdigrab -framerate %recFPS% -i desktop "%SaveDir%\%fileName%" -y, , Hide, PID
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_display_activeWindow" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
Sleep, 2500
WinGetActiveTitle, _activeWindow
RunWait, %comspec% /c ffmpeg -f gdigrab -framerate %recFPS% -i title="%_activeWindow%" "%SaveDir%\%fileName%" -y, , Hide, PID
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_display_mic" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devMicrophonePrimary%" -itsoffset 0.45 -f gdigrab -framerate %recFPS% -i desktop -y "%SaveDir%\%fileName%", , Hide, pid
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_display_stereoMix" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -itsoffset 0.45 -f gdigrab -framerate %recFPS% -i desktop -y "%SaveDir%\%fileName%", , Hide, pid
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_mic" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devMicrophonePrimary%" -y "%SaveDir%\%fileName%.mp3", , Hide, PID2
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_webcam_mic" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i video="%devUsbCamera%"`:audio="%devMicrophonePrimary%" -framerate %recFPS% -y "%SaveDir%\%fileName%", , Hide, PID3
}Else If ( A_ThisMenuItem = "ffmpeg_RECORD_webcam_stereoMix" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i video="%devUsbCamera%"`:audio="%devStereoMix%" -framerate %recFPS% -y "%SaveDir%\%fileName%", , Hide, PID3
; Gosub, GuiClose
}Else If (A_ThisMenuItem = "ffmpeg_LIST_DEVICES_DEBUG" AND A_ThisMenu = "Submenu2" ){
Run, %comspec% /k ffmpeg -list_devices true -f dshow -i dummy
}Else If (A_ThisMenuItem = "ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED_AudioResync@450ms+AllInputs+Win7Inputs" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -rtbufsize %rtBufferSize% -loglevel info -f dshow -video_device_number 0 -i video="screen-capture-recorder" -f dshow -audio_device_number 0 -i audio="virtual-audio-capturer" -f dshow -audio_device_number 0 -i audio="%devMicrophonePrimary%" -filter_complex amix=inputs=2 -vcodec libx264 -pix_fmt yuv420p -preset ultrafast -vsync vfr -acodec libmp3lame -f mp4 -y "%SaveDir%\%fileName%", , Hide, PID
}Else If (A_ThisMenuItem = "ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED_AudioResync@450ms" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -itsoffset 0.45 -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -crf 1 -maxrate 20M -bufsize %bufferSize% -vsync vfr -acodec libmp3lame -f mp4 -y "%SaveDir%\%fileName%", , Hide, PID
}Else If (A_ThisMenuItem = "ffmpeg_LOSLESS_display_GreatestSize_stereoMix_AudioResync@450ms" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -itsoffset 0.45 -f gdigrab -framerate %recFPS% -draw_mouse 1 -i desktop -c:v libx264 -qp 0 -pix_fmt yuv444p -preset ultrafast -y "%SaveDir%\%fileName%", , Hide, PID
}Else If (A_ThisMenuItem = "ffmpeg_GamePlayRecordingOptimised_30fpsLOCKED" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -crf 1 -maxrate 20M -bufsize %bufferSize% -y "%SaveDir%\%fileName%", , Hide, PID
}Else If (A_ThisMenuItem = "ffmpeg_LOSLESS_display_GreatestSize_stereoMix" AND A_ThisMenu = "Submenu2" ){
Gosub, GuiStart
RunWait, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -f gdigrab -framerate %recFPS% -draw_mouse 1 -i desktop -c:v libx264 -qp 0 -pix_fmt yuv444p -preset ultrafast -y "%SaveDir%\%fileName%", , Hide, PID
}
Return
; -itsoffset 0.45 will advance the input on it's left with respect to the input on it's right., in the cases above audio advances by 450ms
^+F12::
Gosub, HotkeyRecStart
Gosub, GuiStart
Run, %comspec% /c ffmpeg -f dshow -i audio="%devStereoMix%" -f gdigrab -framerate %recFPS% -draw_mouse 1 -i desktop -c:v libx264 -qp 0 -pix_fmt yuv444p -preset ultrafast -y "%SaveDir%\%fileName%", , Hide, PID
Return
^+F10::
Gosub, HotkeyRecStart
Gosub, GuiStart
; RunWait, %comspec% /c ffmpeg -loglevel info -f dshow -video_device_number 0 -i video="screen-capture-recorder" -f dshow -audio_device_number 0 -i audio="virtual-audio-capturer" -f dshow -audio_device_number 0 -i audio="%devMicrophonePrimary%" -filter_complex amix=inputs=2 -vcodec libx264 -pix_fmt yuv420p -preset ultrafast -vsync vfr -acodec libmp3lame -f mp4 -y "%SaveDir%\%fileName%", , Hide, PID
RunWait, %comspec% /c ffmpeg -rtbufsize 1024M -f dshow -i video="UScreenCapture":audio="%devStereoMix%" -r 40 -vcodec libx264 -threads 0 -crf 0 -preset ultrafast -tune zerolatency -acodec libmp3lame -y "%SaveDir%\%fileName%.flv", , Hide, PID
Return
^+F11::
Gosub, GuiClose
SoundBeep, 500
Return
HotkeyRecStart:
Loop, 2
SoundBeep, 1000
lastSaveDir := INI("r", "LastSaveDir", "LastSaveDir",,, "ffmpeg.rec.ini")
SaveDir := ( InStr(path, ":\") ? path : (lastSaveDir ? lastSaveDir : A_Desktop) )
devMicrophonePrimary := INI("r", "DEVICES", "PrimaryMicrophone",,, "ffmpeg.rec.ini")
devStereoMix := INI("r", "DEVICES", "SpeakerOutputStereoMix",,, "ffmpeg.rec.ini")
devUsbCamera := INI("r", "DEVICES", "USBCamera",,, "ffmpeg.rec.ini")
recFPS := INI("r", "RecordingFPS", "RecordingFPS",,, "ffmpeg.rec.ini")
bufferSize := INI("r", "BufferSize", "BufferSize",,, "ffmpeg.rec.ini") ;-bufsize
rtBufferSize := INI("r", "BufferSize", "RealTimeBufferSize",,, "ffmpeg.rec.ini") ;-rtbufsize
WinGet, activeProcess, ProcessName, A
fileName := activeProcess . "[" . A_Now . "].mp4"
Return
;=========================================================================================================================
~^F9::
~^+F9:: ;mcgee's setup
recording := ( !recording AND WinExist("ahk_exe obs64.exe") ? ToneRec() : (WinExist("ahk_exe obs64.exe") ? ToneRecStopped() : ToneRecErr()) )
Return
obsRecNotifier(){
Global
If ( GetKeyState("Ctrl") AND GetKeyState("F9") ){
recording := ( !recording AND WinExist("ahk_exe obs64.exe") ? ToneRec() : (WinExist("ahk_exe obs64.exe") ? ToneRecStopped() : ToneRecErr()) 30 -i
if (window=RealTimeBufferSize)
}Else If ( ProcessExist("obs64.exe") AND ProcessExist("ffmpeg-mux64.exe") ){
recording := True
}Else If ( ProcessExist("obs64.exe") AND !ProcessExist("ffmpeg-mux64.exe") ){
recording := False
}
}
ToneRec(){
SoundBeep, 2000
Return True
}
ToneRecStopped(){
SoundBeep, 500
Return False
}
ToneRecErr(){
SoundBeep, 1500, 1000
}
;=========================================================================================================================
ProcessExist(procName){
Process, Exist, %procName%
Return ErrorLevel
}
AHK_NOTIFYICON(wParam, lParam)
{
if (lParam = 0x205){ ; WM_RBUTTONUP
Menu, MyMenu, Show
Return 0
}
}