快速找出MP3开始时的静音程度?


4

有什么方法可以快速简便地找出MP3开始时的静音程度?我知道有很多内容......我不需要太精确的东西。在50毫秒左右是很好的。

我有1000个左右的MP3,我想用它来做,所以我可以编写的解决方案是最好的。谢谢!

请注意,我不想修剪沉默,我需要知道沉默的长度。

Answers:


1

由于您尚未指定操作系统,我将假设Windows。

使用 ffmpeg的 与PowerShell ISE结合使用

电源外壳

$folder = "C:\path\to\musicfolder"
$ffmpeg = "C:\path\to\ffmpeg.exe"

$content = "track start     track end   Filepath`n"
Get-ChildItem $folder -Recurse -Include *.mp3,*.ogg,*.flac  | foreach {        

    $log = & $ffmpeg -hide_banner -i `"$_`" -af "silencedetect=duration=2:noise=-50dB" -f null - 2>&1
    #echo [string]$log

    $totalLength = [string]$log | where {$_ -match '(?<= Duration:.*)[\d:\.]+' } | % {$matches[0]}        
    $totalLength = ([TimeSpan]::Parse($totalLength)).TotalSeconds

    [string[]]$silenceEnd = $log | where {$_ -match '(?<=silence_end: )[-\d\.]+' } | % {$matches[0]}            
    If ($silenceEnd.count -gt 0 -And [double]$silenceEnd[0] -lt $totalLength/2) {
        [string]$trackStart = $silenceEnd[0]
    } else {
        [string]$trackStart = 0
    }

    [string[]]$silenceStart = $log | where {$_ -match '(?<=silence_start: )[-\d\.]+' } | % {$matches[0]}                
    If ($silenceStart.count -gt 0 -And $silenceStart[$silenceStart.count-1] -gt $totalLength/2) {
        [string]$trackEnd = $silenceStart[$silenceStart.count-1]
    } else {        
        [string]$trackEnd = $totalLength
    }    
    $content += "$trackStart                $trackEnd       $_  `n"
}
Clear-Content "$folder\silenceLog.txt"
Add-Content "$folder\silenceLog.txt" $content

示例输出

enter image description here

  • 第一列是以秒和毫秒为单位的时间戳,其中静音结束并且音乐开始
  • 第二列是以秒和毫秒为单位的时间戳,音乐结束并开始静音
  • 第三列是文件路径
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.