利用 PowerShell 与 FFMPEG 切掉音频内的静音

ShikiSuen

战斗机
配乐人星公民
正式用户
🧱星陨矿
16,246
🧊星能体
46
🍀星灵素
2
🏵️星元核
0
本想用 Audiofile Myriad 完成这个工作的,却发现这玩意在 Big Sur 系统上完全不执行任何批处理操作。
看 Steinberg WaveLab 也不支持这个,我就只好找脚本批处理这种事情。

这个 PWSH 脚本仅用来切除音频内的绝对数字静音。诸位可以根据 FFMPEG 的参考手册来调整这个脚本。
macOS 系统需要单独安装 PowerShell,且 FFMPEG 需要单独安装(该脚本针对 MacPorts 版 FFMPEG 优化,请 HomeBrew 用户自行调整)。
Windows 系统内建 PowerShell,但是 FFMPEG 需要单独安装。
Windows 10 专业版、企业版用户也可以使用 Linux 子系统内建的封包管理器来安装 Linux 专用版 PowerShell 与 FFMPEG。

脚本出处:https://www.emxr.com/music-making/s...rom-audio-sample-files-in-bulk-or-batch-mode/

Bash:
# ### 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"
 

ken_20

战斗机
混录师星公民
正式用户
    🧱星陨矿
    69,918
    🧊星能体
    47
    🍀星灵素
    2
    🏵️星元核
    0
    技术大神啊
     

    ShikiSuen

    战斗机
    配乐人星公民
    正式用户
    🧱星陨矿
    16,246
    🧊星能体
    46
    🍀星灵素
    2
    🏵️星元核
    0
    ken_20哪里,只是 macOS 放著个终端机不好好利用的话也太暴殄天物了。
    Windows 原先在这方面是绝对短版,直到出现了 WSL。
     

    ShikiSuen

    战斗机
    配乐人星公民
    正式用户
    🧱星陨矿
    16,246
    🧊星能体
    46
    🍀星灵素
    2
    🏵️星元核
    0
    ken_20我平时用 zsh 居多,毕竟 macOS 内建 zsh。PWSH 脚本这次倒是第一次用,还是用别人写好的脚本改的。