这个 PWSH 脚本仅用来切除音频内的绝对数字静音。诸位可以根据 FFMPEG 的参考手册来调整这个脚本。
macOS 系统需要单独安装 PowerShell,且 FFMPEG 需要单独安装(该脚本针对 MacPorts 版 FFMPEG 优化,请 HomeBrew 用户自行调整)。
Windows 系统内建 PowerShell,但是 FFMPEG 需要单独安装。
Windows 10 专业版、企业版用户也可以使用 Linux 子系统内建的封包管理器来安装 Linux 专用版 PowerShell 与 FFMPEG。
- # ### Set the source and target folders ####################
- $sourceDir = "/var/tmp/SourceDir"
- $targetDir = $sourceDir + "_trimmed"
- # ### Set the desired FFmpeg directives ################################################################
- $ffmpegDirectives = "-af silenceremove=window=0:detection=peak:stop_mode=all:start_mode=all:stop_periods=-1:stop_threshold=0: -c:a pcm_s32le -y"
- # ### Set the location of the FFmpeg program ################################################################
- $ffmpegPath = "/opt/local/bin/ffmpeg"
- # ### No changes needed below this line ################################################################
- Write-Host "--------------------------------------------------------------------"
- Write-Host "Trim Silence from files "
- $now = Get-Date -Format "HH:mm:ss"
- Write-Host @("script started at " + $now )
- # Set-Location $sourceDir
- New-Item -Path $targetDir -Force -ItemType directory | Out-Null
- $wavFileList = Get-ChildItem -Path $sourceDir -Name -Include "*.wav"
- $fileCount = 0
- foreach ( $wavFile in $wavFileList ) {
- $fileCount++
- $sourcePath = Join-Path $sourceDir $wavFile
- $targetPath = Join-Path $targetDir $wavFile
- # Write-Host @($sourcePath + " >>> " + $targetPath)
- $ffmpegParameters = " -loglevel error -i """ + $sourcePath + """ " + $ffmpegDirectives + " """ + $targetPath + """"
- # Write-Host $ffmpegParameters
- Start-Process -FilePath $ffmpegPath -ArgumentList $ffmpegParameters -NoNewWindow
- }
- # ########################################################################
- Write-Host @("Files processed: " + $fileCount)
- $now = Get-Date -Format "HH:mm:ss"
- Write-Host @("script completed at " + $now )
- Write-Host "-------------------------------------------------------------`n"
复制代码
本帖最后由 ShikiSuen 于 21-9-17 16:33 编辑