Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What's a quick and easy way to find out how much silence is at the start of an MP3? I know there's a lot that goes into that... I don't need anything too precise. Within 50 or so milliseconds is great.

I have 1000 or so MP3s I want to do this with, so a solution I could script with would be best. Thanks!

Note that I don't want to trim the silence, I need to know the length of the silence.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Since you haven't specified your OS, I'll assume Windows.

Use ffmpeg in combination with 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

Example output

enter image description here

  • First column is a time stamp in seconds and milliseconds where silence ends and music starts
  • Second column is a time stamp in seconds and milliseconds where music ends and silence starts
  • Third column is the file path
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.