ahk控制ffmpeg录制win10的桌面和声音:https://www.52pojie.cn/thread-1409815-1-1.html

 

1.调用ffmpeg进行桌面录制+视频合并

; https://www.youtube.com/watch?v=7b358-kh9AM
; https://www.the-automator.com/quickly-record-your-desktop-for-free-with-ffmpeg-and-autohotkey/
#NoEnv
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
SetTitleMatchMode, 3 ; 确保 winMinimize 并将控制 C 发送到 ConsoleWindowClass 在下面工作
DetectHiddenWindows,On ; 添加是因为最小化窗口

; 【视频合并】https://www.youtube.com/watch?v=A_Wt86oSTYQ
; 【另一个中文录制解释】https://www.52pojie.cn/forum.php?mod=viewthread&tid=1409815

; ffmpeg文件 := https://ffmpeg.org/ffmpeg-devices.html#gdigrab  来自 ffmpeg 的 gdigrab 文档
; 获取设备列表 ffmpeg:= ffmpeg -list_devices true -f dshow -i dummy
; 特定区域 := https://stackoverflow.com/questions/6766333/capture-windows-screen-with-ffmpeg/47591299
;********************Control+Shift+R=开始录制***********************************
^+r::
FileDelete, %A_ScriptDir%\temp.mp4
Sleep 50

ff_params = -rtbufsize 1500M  -thread_queue_size 512 -f gdigrab -video_size 1920x1080  -i desktop -f dshow -i audio="Microphone (Yeti Stereo Microphone)" -crf 0  -filter:a "volume=1.5" -vcodec libx264 temp.mp4
Run ffmpeg %ff_params% ; 使用命令参数运行 ffmpeg

Sleep 150 ; 等待命令窗口出现
WinMinimize, ahk_class ConsoleWindowClass ; 最小化 CMD 窗口
return

;********************Control+Shift+S= 停止录制***********************************
^+s::
ControlSend, , ^c, ahk_class ConsoleWindowClass  ; 将 ctrl-c 发送到停止录制的命令窗口
Sleep 500
InputBox, New_File_Name,文件名,你想给你的 .mp4 文件起什么名字?,,300,130 ; 获取新视频的文件名
if (New_File_Name = "") or (Error = 1) ;如果你不给它一个名字,它不会重命名它,也不会运行它
  Return 

Run, explore %A_ScriptDir% ; 打开工作文件夹
FileMove, %A_ScriptDir%\temp.mp4, %A_ScriptDir%\%New_File_Name%.mp4  ; 将临时文件重命名为新文件。
Run, %A_ScriptDir%\%New_File_Name%.mp4 ; 现在播放新文件名
Return

 

2.从头到尾录制带有静音修剪的声音,带界面设置的示例

; 出处:http://forum.script-coding.com/viewtopic.php?id=17666
/*
对于一个项目,有必要从头到尾录制带有静音修剪的声音。
为 ffmpeg 编写了 gui。
https://www.videohelp.com/software/ffmpeg
ffmpeg.exe 需要重命名为 ffmpeg_script.exe。
该脚本创建 temp.wav,然后将其擦除。
结果存储在 %A_Now%.mp3 中。
*/

NoiseGate := -70

#SingleInstance force
OnExit, MP3RecordGuiClose

LOAD_DLL_Mf_Mfplat()
MFStartup(version := 2, MFSTARTUP_FULL := 0)
MFCreateAttributes(pMFAttributes, 1)
IMFAttributes_SetGUID(pMFAttributes, MF_GUID(GUID, "MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE"), MF_GUID(GUID1, "MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID"))
MFEnumDeviceSources(pMFAttributes, pppSourceActivate, pcSourceActivate)
Loop % pcSourceActivate
{
  IMFActivate := NumGet(pppSourceActivate + (A_Index - 1)*A_PtrSize)
  name := IMFActivate_GetAllocatedString(IMFActivate, MF_GUID(GUID, "MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME"))
  if (A_Index = 1)
    RecordingDevices .= name "||"
  else
    RecordingDevices .= name "|"
  ObjRelease(IMFActivate)
}
DllCall("ole32\CoTaskMemFree", "ptr", pppSourceActivate)
ObjRelease(pMFAttributes)
MFShutdown()
UNLOAD_DLL_Mf_Mfplat()

Gui, MP3Record: +AlwaysOnTop -DpiScale
Gui, MP3Record: Add, Text, x12, RecordingDevice:
Gui, MP3Record: Add, DDL, vRecordingDevice x12 w250, % RecordingDevices
Gui, MP3Record: Add, Button, x12 y62 w120 h20 vRecord gMP3Record, Start Recording
Gui, MP3Record: Add, Text, x54 y86 w80 vMP3Time
Gui, MP3Record: Show
return

MP3Record:
GuiControlGet, RecordingDevice
if (CurrentState != "Record")
{
  loop
  {
    Process, Exist, ffmpeg_script.exe
    if ErrorLevel
    {
      Process, Close, ffmpeg_script.exe
      Process, WaitClose, ffmpeg_script.exe
    }
    else
      break
  }
  Run, ffmpeg_script.exe -f dshow -i audio="%RecordingDevice%" -acodec copy -y temp.wav, , hide, pid
  loop
  {
    if DllCall("AttachConsole", "uint", pid)
      break
    sleep 10
  }
  hConIn := DllCall("CreateFile", "str", "CONIN$", "uint", 0xC0000000, "uint", 0x3, "uint", 0, "uint", 0x3, "uint", 0, "uint", 0, "ptr")
  if (hConIn = -1)
  {
    msgbox error CreateFile %A_LastError%
    ExitApp
  }
  VarSetCapacity(ir, 24, 0)		 ; ir := new INPUT_RECORD
  NumPut(1, ir, 0, "UShort")		; ir.EventType := KEY_EVENT
  NumPut(1, ir, 8, "UShort")		; ir.KeyEvent.wRepeatCount := 1
  min := sec := 0
  CurrentState := "Record"
  GuiControl,, Record, Stop Recording
  SetTimer, Count, 1000
}
else
{
  CurrentState := ""
  GuiControl,, Record, Start Recording
  SetTimer, Count, Off
  NumPut(Asc("q"), ir, 14, "UShort")
  NumPut(true, ir, 4, "Int")  ; ir.KeyEvent.bKeyDown := true
  if !DllCall("WriteConsoleInput", "ptr", hConIn, "ptr", &ir, "uint", 1, "uint*", 0)
  {
    msgbox error WriteConsoleInput one %A_LastError%
    ExitApp
  }
  NumPut(false, ir, 4, "Int") ; ir.KeyEvent.bKeyDown := false
  if !DllCall("WriteConsoleInput", "ptr", hConIn, "ptr", &ir, "uint", 1, "uint*", 0)
  {
    msgbox error WriteConsoleInput two %A_LastError%
    ExitApp
  }
  DllCall("CloseHandle", "ptr", hConIn)
  hConIn := ""
  DllCall("FreeConsole")
  Process, WaitClose, ffmpeg_script.exe
  MsgBox, 274340,, Save recorded mp3?
  IfMsgBox Yes
  {
    Run, ffmpeg_script.exe -i temp.wav -ab 320k -acodec libmp3lame -y -af "silenceremove=start_periods=1:start_duration=0:start_threshold=%NoiseGate%dB`,areverse`,silenceremove=start_periods=1:start_duration=0:start_threshold=%NoiseGate%dB`,areverse" "%A_Now%.mp3", , hide
    Process, WaitClose, ffmpeg_script.exe
  }
  GuiControl,, MP3Time
  FileDelete, temp.wav
}
return

Count:
sec++
if (sec = 60)
{
  min++
  sec := 0
}
GuiControl, MP3Record:, MP3Time, % "0:" Format("{1:02}", min) ":" Format("{1:02}", sec)
return

MP3RecordGuiClose:
loop
{
  Process, Exist, ffmpeg_script.exe
  if ErrorLevel
  {
    Process, Close, ffmpeg_script.exe
    Process, WaitClose, ffmpeg_script.exe
  }
  else
    break
}
FileDelete, temp.wav
ExitApp


LOAD_DLL_Mf_Mfplat()
{
  if !DllCall("GetModuleHandle","str","Mf")
    DllCall("LoadLibrary","Str", "Mf.dll", "ptr")
  if !DllCall("GetModuleHandle","str","Mfplat")
    DllCall("LoadLibrary","Str", "Mfplat.dll", "ptr")
}

UNLOAD_DLL_Mf_Mfplat()
{
  if hModule := DllCall("GetModuleHandle", "str", "Mf", "ptr")
    DllCall("FreeLibrary", "ptr", hModule)
  if hModule := DllCall("GetModuleHandle", "str", "Mfplat", "ptr")
    DllCall("FreeLibrary", "ptr", hModule)
}

MFStartup(version, dwFlags)
{
  hr := DllCall("Mfplat.dll\MFStartup", "uint", version, "uint", dwFlags)
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

MFCreateAttributes(ByRef ppMFAttributes, cInitialSize)
{
  hr := DllCall("Mfplat.dll\MFCreateAttributes", "ptr*", ppMFAttributes, "uint", cInitialSize)
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IMFAttributes_SetGUID(this, guidKey, guidValue)
{
  hr := DllCall(NumGet(NumGet(this+0)+24*A_PtrSize), "ptr", this, "ptr", guidKey, "ptr", guidValue)
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

MFEnumDeviceSources(pAttributes, ByRef pppSourceActivate, ByRef pcSourceActivate)
{
  hr := DllCall("Mf.dll\MFEnumDeviceSources", "ptr", pAttributes, "ptr*", pppSourceActivate, "uint*", pcSourceActivate)
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

IMFActivate_GetAllocatedString(this, guidKey)
{
  hr := DllCall(NumGet(NumGet(this+0)+13*A_PtrSize), "ptr", this, "ptr", guidKey, "ptr*", ppwszValue, "uint*", pcchLength)
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
  AllocatedString := StrGet(ppwszValue, pcchLength, "UTF-16")
  DllCall("ole32\CoTaskMemFree", "ptr", ppwszValue)
  return AllocatedString
}

MF_GUID(ByRef GUID, name)
{
  static init:=1, _:={}
  if init
  {
    init:=0
    _.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE := [0xc60ac5fe, 0x252a, 0x478f, 0xa0, 0xef, 0xbc, 0x8f, 0xa5, 0xf7, 0xca, 0xd3]
    _.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID := [0x14dd9a1c, 0x7cff, 0x41be, 0xb1, 0xb9, 0xba, 0x1a, 0xc6, 0xec, 0xb5, 0x71]
    _.MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME := [0x60d0e559, 0x52f8, 0x4fa2, 0xbb, 0xce, 0xac, 0xdb, 0x34, 0xa8, 0xec, 0x1]
  }
  if _.haskey(name)
  {
    p := _[name]
    VarSetCapacity(GUID,16)
    ,NumPut(p.1+(p.2<<32)+(p.3<<48),GUID,0,"int64")
    ,NumPut(p.4+(p.5<<8)+(p.6<<16)+(p.7<<24)+(p.8<<32)+(p.9<<40)+(p.10<<48)+(p.11<<56),GUID,8,"int64")
    return &GUID
  }
  else return name
}

_Error(val)
{
  msgbox % val
  ExitApp
}

MFShutdown()
{
  hr := DllCall("Mfplat.dll\MFShutdown")
  if hr or ErrorLevel
    _Error(A_ThisFunc " error: " hr "`nErrorLevel: " ErrorLevel)
}

 

3.使用ffmpeg来修剪WAV或FLAC文件开头和结尾的静音

; 出处:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=114907

; 它使用ffmpeg来修剪WAV或FLAC文件开头和结尾的静音。它还可以选择更改输出采样率和调整封面艺术的大小。没有质量损失。我通过修剪同一个FLAC文件150次对其进行了测试。ffmpeg.exe必须位于脚本目录中。修剪愉快

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
; Script made by Ivan Radolović
;@Ahk2Exe-Bin C:\Program Files\AutoHotkey\Compiler\Unicode 32-bit.bin

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Persistent
#NoTrayIcon
#SingleInstance off
global TrimBeginTreshold, TrimEndTreshold, NormalizeValue, ResizeScale, Samplerate
  
RegRead, TrimBeginTreshold, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimBeginTreshold
RegRead, TrimEndTreshold, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimEndTreshold
RegRead, ResizeScale, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, ResizeScale
RegRead, Samplerate, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, Samplerate

RegRead, FirstRun, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, FirstRun
If ErrorLevel
  {
  TrimBeginTreshold := -70
  TrimEndTreshold := -70
  ResizeScale := "Keep"
  Samplerate := "Keep"
  RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, FirstRun, 1
  RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimBeginTreshold, %TrimBeginTreshold%
  RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimEndTreshold, %TrimEndTreshold%
  RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, ResizeScale, %ResizeScale%
  RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, Samplerate, %Samplerate%
  }

mapped_valueBegin := TrimBeginTreshold
mapped_valueEnd := TrimEndTreshold

IfNotExist, ffmpeg.exe
  {
  Msgbox, ffmpeg.exe do not exist in script dir. App exits
  ExitApp
  }

; Define GUI dimensions and drag-and-drop area
Gui, Main:+AlwaysOnTop
Gui, Main:+Resize
; Create edit box and make it read-only
Gui, Main:Add, Edit, ReadOnly vMyEditBox w50 h50
Gui, Main:Show, w480 h320, WavFlac Trim 1.0 powered by ffmpeg

; Create menu bar
Menu, MyMenu, Add, Start, MyMenu_Start
Menu, MyMenu, Add, About, MyMenu_About
Menu, MyMenu, Add, Options, MyMenu_Options
Menu, MyMenu, Add, Exit, MyMenu_Exit
Gui, Main:Menu, MyMenu

GuiControl, Main:Text, MyEditBox, Drop wav and flac files here

return

; Options menu
MyMenu_Options:
TrimBeginTresholdScrollbar := ((TrimBeginTreshold - (-99)) / (-30 - (-99))) * 100
TrimEndTresholdScrollbar := ((TrimEndTreshold - (-99)) / (-30 - (-99))) * 100
;NormalizeValueScrollbar := ((NormalizeValue - 0) / (-50 - 0)) * (100 - 0) + 0

CoverartItemList := "Keep|150:150|300:300|600:600|800:800|1200:1200"
SamplerateItemList := "Keep|32000|44100|48000|96000|192000"
Loop, parse, CoverartItemList, |,
    if (A_LoopField = ResizeScale)
    SelectCoverartItemNumber := A_Index
Loop, parse, SamplerateItemList, |,
    if (A_LoopField = Samplerate)
    SelectSamplerateItemNumber := A_Index
Gui, Main:+Disabled
Gui, Main:-AlwaysOnTop
Gui, Options:+AlwaysOnTop
Gui, Options:+Owner 
Gui, Options:Add, GroupBox, x10 y30 w230 h80, Trim silence
Gui, Options:Add, Text, x20 y50 w80 h20, Begin Treshold:
Gui, Options:Add, Slider, x100 y50 w100 h20 vTrimBeginTresholdSlider gUpdateTrimBeginTreshold, %TrimBeginTresholdScrollbar%
Gui, Options:Add, Text, x205 y50 w30 h20 vTrimBeginTresholdDisplay, %TrimBeginTreshold%dB
Gui, Options:Add, Text, x20 y80 w80 h20, End Treshold:
Gui, Options:Add, Slider, x100 y80 w100 h20 vTrimEndTresholdSlider gUpdateTrimEndTreshold, %TrimEndTresholdScrollbar%
Gui, Options:Add, Text, x205 y80 w30 h20 vTrimEndTresholdDisplay, %TrimEndTreshold%dB
Gui, Options:Add, Text, x20 y128 w80 h20, Resize Coverart
Gui, Options:Add, DropDownList, x110 y128 w100 h200 Choose%SelectCoverartItemNumber% vDropDownListCoverartSelection, %CoverartItemList%
Gui, Options:Add, Text, x20 y154 w80 h20, Samplerate
Gui, Options:Add, DropDownList, x110 y152 w100 h200 Choose%SelectSamplerateItemNumber% vDropDownListSamplerateSelection, %SamplerateItemList%
Gui, Options:Add, Button, x40 y188 w80 h30 gApplyButton vDefaultButton, OK
Gui, Options:Add, Button, x140 y188 w80 h30 gCancelButton, Cancel
Gui, Options:Show, w260 h240, Options
return

; Update the text next to the Trim Begin Treshold slider
UpdateTrimBeginTreshold:
mapped_valueBegin := ((TrimBeginTresholdSlider - 0) / (100 - 0)) * (-30 - (-99)) + (-99)
mapped_valueBegin := Round(mapped_valueBegin)
GuiControlGet, TrimBeginTresholdDisplay, , %mapped_valueBegin%
GuiControl,, TrimBeginTresholdDisplay, %mapped_valueBegin%dB
return

; Update the text next to the Trim End Treshold slider
UpdateTrimEndTreshold:
mapped_valueEnd := ((TrimEndTresholdSlider - 0) / (100 - 0)) * (-30 - (-99)) + (-99)
mapped_valueEnd := Round(mapped_valueEnd)
GuiControlGet, TrimEndTresholdDisplay, , %mapped_valueEnd%
GuiControl,, TrimEndTresholdDisplay, %mapped_valueEnd%dB
return

; Update the text next to the Normalize Treshold slider
UpdateNormalizeValue:
mapped_norm_value := ((NormalizeValueSlider - 0) / (100 - 0)) * (-50 - 0) + 0
mapped_norm_value := Round(mapped_norm_value)
GuiControlGet, NormalizeValueDisplay, , %mapped_norm_value%
GuiControl,, NormalizeValueDisplay, %mapped_norm_value%dB
return

; Apply button
ApplyButton:
TrimBeginTreshold := mapped_valueBegin
TrimEndTreshold := mapped_valueEnd
;NormalizeValue := mapped_norm_value
Gui, Main:-Disabled
Gui, Main:+AlwaysOnTop
Gui, Options:Submit, NoHide
ResizeScale := DropDownListCoverartSelection
Samplerate := DropDownListSamplerateSelection
RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimBeginTreshold, %TrimBeginTreshold%
RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, TrimEndTreshold, %TrimEndTreshold%
RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, ResizeScale, %ResizeScale%
RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\AnoApps\WavFlacTrim, Samplerate, %Samplerate%
Gui, Options:Destroy
return

; Cancel button
CancelButton:
Gui, Main:+AlwaysOnTop
Gui, Main:-Disabled
Gui, Options:Cancel
Gui, Options:Destroy
return

; Close the Options GUI
OptionsGuiClose:
Gui, Main:+AlwaysOnTop
Gui, Main:-Disabled
Gui, Options:Destroy
return

MainGuiSize:
; Get the new dimensions of the GUI window
Gui, +LastFound
WinGetPos, X, Y, Width, Height, A
Width -= 18
Height -= 60
; Resize the edit box to fill the new dimensions of the GUI window
GuiControl, Move, MyEditBox, x0 y0 w%Width% h%Height%

return

; Define actions for menu items
MyMenu_Start:
Gui, -AlwaysOnTop
Gui, +Disabled
FileSelectFile, SelectedFiles, M3, , Open a file, Audio (*.flac; *.wav;)
Gui, +AlwaysOnTop
Gui, -Disabled
if (SelectedFiles = "")
  return
ProcessFailed := "0"
ProcessSeccess := "0"
GuiControl, Text, MyEditBox, Trimming...
Loop, parse, SelectedFiles, `n
  {
    if (A_Index = 1)
      {
      OutDir := A_LoopField
      Continue
      }
    else
    {
    Status := "Done."
    ProcessedCount := A_Index
    SelectedFile := OutDir . "\" . A_LoopField
    SelectedFile := StrReplace(SelectedFile, "\\", "\")
    SplitPath, SelectedFile, OutFileName, OutDir, OutExtension, OutNameNoExt
    success := TrimFile(SelectedFile)

    if (success) {
      ProcessSeccess++
    } else {
      ProcessFailed++
      Status := "Failed to trim."
    }

    FileGetAttrib, Attributes, %OutDir%\tmp%RndNumber%.%OutExtension%
    if InStr(Attributes, "R") {
      Attribute := " ----> File is ReadOnly "
      Status := "Failed to trim."
      ProcessFailed++
      ProcessSeccess--
      FileMove, %OutDir%\tmp%RndNumber%.%OutExtension%, %SelectedFile%
    }

    ListProcessedFiles := ListProcessedFiles 
                . Attribute 
                . OutFileName
                . " - " 
                . Status 
                . "`n"
    Attribute := ""
    GuiControl, Text, MyEditBox, %ListProcessedFiles%
  }
  }
  ListProcessedFiles := ListProcessedFiles
            . "`nDone, " 
            . ProcessSeccess 
            . " file/s sucessfully trimmed., " 
            . ProcessFailed 
            . " failed."
  GuiControl, Text, MyEditBox, %ListProcessedFiles%
  ListProcessedFiles := ""
  ProcessFailed := ""
  ProcessSeccess := ""
IfExist, C:\Program Files (x86)\Mp3tag\mp3tag.exe
  {
  Gui, +Disabled
  Msgbox, 262180, Suggestion: Mp3tag, Do you want to open trimmed files in Mp3tag?
  Gui, -Disabled
  IfMsgBox Yes
    Run, C:\Program Files (x86)\Mp3tag\mp3tag.exe /fp:"%SelectedFile%"
  }
return

MyMenu_About:
Gui, +Disabled
MsgBox, 262208, About, WavFlac Trim 1.0 is powered by ffmpeg.`n`n Script made by Ivan Radolović 2023 ©
Gui, -Disabled
return

MainGuiClose:
MyMenu_Exit:
ExitApp
return

MainGuiDropFiles:
ProcessFailed := "0"
ProcessSeccess := "0"
GuiControl, Text, MyEditBox, Trimming...
Loop, parse, A_GuiEvent, `n
{
  Status := "Done."
  ProcessedCount := A_Index
  SelectedFile := A_LoopField
  SplitPath, SelectedFile, OutFileName, OutDir, OutExtension, OutNameNoExt
  success := TrimFile(SelectedFile)

  if (success) {
    ProcessSeccess++
  } else {
    ProcessFailed++
    Status := "Failed to trim."
  }

  FileGetAttrib, Attributes, %OutDir%\tmp%RndNumber%.%OutExtension%
  if InStr(Attributes, "R") {
    Attribute := " ----> File is ReadOnly "
    Status := "Failed to trim."
    ProcessFailed++
    ProcessSeccess--
    FileMove, %OutDir%\tmp%RndNumber%.%OutExtension%, %SelectedFile%
  }

  ListProcessedFiles := ListProcessedFiles 
              . Attribute 
              . OutFileName
              . " - " 
              . Status 
              . "`n"
  Attribute := ""
  GuiControl, Text, MyEditBox, %ListProcessedFiles%
}
ListProcessedFiles := ListProcessedFiles
          . "`nDone, " 
          . ProcessSeccess 
          . " file/s sucessfully trimmed., " 
          . ProcessFailed 
          . " failed."
GuiControl, Text, MyEditBox, %ListProcessedFiles%
ListProcessedFiles := ""
ProcessFailed := ""
ProcessSeccess := ""
IfExist, C:\Program Files (x86)\Mp3tag\mp3tag.exe
  {
  Gui, +Disabled
  Msgbox, 262180, Suggestion: Mp3tag, Do you want to open trimmed files in Mp3tag?
  Gui, -Disabled
  IfMsgBox Yes
    Run, C:\Program Files (x86)\Mp3tag\mp3tag.exe /fp:"%SelectedFile%"
  }
return


TrimFile(SelectedFile) {
  Random, RndNumber, NewSeed
  SplitPath, SelectedFile, OutFileName, OutDir, OutExtension, OutNameNoExt
  if (OutExtension != "flac" and OutExtension != "wav") {
  return 0
}
  FileMove, %SelectedFile%, %OutDir%\tmp%RndNumber%.%OutExtension%
  if ErrorLevel 
    return 0
  if ResizeScale != Keep
   resizeCoverArt := "-vf scale=" . ResizeScale
  if Samplerate != Keep
    Resample := "-ar " . Samplerate
  AF_Param = silenceremove=start_periods=1:start_silence=0.1:start_threshold=%TrimBeginTreshold%dB:detection=rms,areverse,silenceremove=start_periods=1:start_silence=0.1:start_threshold=%TrimEndTreshold%dB:detection=rms,areverse
  RunWait, ffmpeg.exe -i "%OutDir%\tmp%RndNumber%.%OutExtension%" %Resample% -af "%AF_Param%" -compression_level 10 %resizeCoverArt% "%SelectedFile%" , , Hide
  if ErrorLevel {
    FileMove, %OutDir%\tmp%RndNumber%.%OutExtension%, %SelectedFile%
    return 0
  } else {
    FileDelete, %OutDir%\tmp%RndNumber%.%OutExtension%
    return 1
  }
}

 

4.mpv调用

; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=58510&p=246750#p246750
#NoEnv
SetBatchLines -1
SetWorkingDir %A_ScriptDir%

Gui, +HWNDhGUI
Gui, Add, Text, x50 y50 w700 h500 HWNDhText, 
Gui, Show, w800 h620

mpv := "D:\Program Files\mpv\mpv.exe"
Run, %mpv% --idle --input-ipc-server=\\.\pipe\mpvsocket --wid=%hText% ; Or --wid=%hGUI%
return

GuiDropFiles:
  mpv_loadfile(A_GuiEvent)
return

mpv_loadfile(ByRef filename) {
  mpv_command("loadfile """ StrReplace(filename, "\", "\\") """")
}

mpv_command(ByRef sCommand) {
  Run, %ComSpec% /c echo %sCommand% > \\.\pipe\mpvsocket,, Hide
}

GuiClose:
ExitApp

WM_KeyDown(wParam, lParam, nMsg, hWnd) {
  static _ := OnMessage(0x100, "WM_KeyDown")
  key := GetKeyName( Chr(wParam) )
  ControlSend, mpv1, % "{" key "}", A
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。