L5730
Addicted to Fun and Learning
Hi all,
Not sure if this is the correct section, but it makes the most sense (unless I am corrected).
I've a few loudness meters to use in the DAW, but nothing that can scan an audio file and provide a nice graphed plot.
I knew ffmpeg could utilise the ebur128 audio filter to generate all the necessary stats every 100ms (Momentary, Short-Term, Integrated), so it was just a matter of formatting that data into a CSV file which could be handed over to a program to plot a graph.
..and after messing around with gnuplot recently, I thought this should work for this purpose.
Here is the Powershell code for a "Send-To" (right-click context menu) item in Windows 10 (and maybe 7 if updated).
Of course, you'll have to download and compile or just download the already compiled gnuplot binary.
The correct path to gnuplot.exe needs to be entered for the variable "$gnuplot".
It is assumed ffmpeg.exe (at least v3.4) is in the system path, like C:\Windows\System32. If not, then it should be properly pathed in this script.
It uses the system 'Temp' folder for temporary files, which are deleted afterwards. The plot image also ends up there unless changed "$outplot"
Save this as a .ps1 file somewhere.
To make it run as a send to, create a shortcut to the .ps1 file in the Windows SendTo folder (hit WinKey+'R', then type 'shell:sendto' without the quotes, then Enter key).
Make the shortcut (hold shift and ctrl and drag the .ps1 in to create a shortcut). Open the shortcut properties and add 'Powershell.exe -ExecutionPolicy bypass -file ' before the path to the ps1 file. Then follow after the path with ' -infile'. OK and close out (all test without quotes).
Windows security is probably setup to prevent running unsigned and scripts not verified locally. It seems a bit pointless when a simple argument turns that off. Oh well.
Yeah, it's a bit clumsily done. There are plenty of options that can be changed for colours, line thickness and stuff, as well as plot size, axis ranges etc.
I'm working on some code ideas to handle larger data sets and reducing it for speed. No point supplying data that can't be drawn as there isn't enough pixel space to plot them!
Examples:
Not sure if this is the correct section, but it makes the most sense (unless I am corrected).
I've a few loudness meters to use in the DAW, but nothing that can scan an audio file and provide a nice graphed plot.
I knew ffmpeg could utilise the ebur128 audio filter to generate all the necessary stats every 100ms (Momentary, Short-Term, Integrated), so it was just a matter of formatting that data into a CSV file which could be handed over to a program to plot a graph.
..and after messing around with gnuplot recently, I thought this should work for this purpose.
Here is the Powershell code for a "Send-To" (right-click context menu) item in Windows 10 (and maybe 7 if updated).
Of course, you'll have to download and compile or just download the already compiled gnuplot binary.
The correct path to gnuplot.exe needs to be entered for the variable "$gnuplot".
It is assumed ffmpeg.exe (at least v3.4) is in the system path, like C:\Windows\System32. If not, then it should be properly pathed in this script.
It uses the system 'Temp' folder for temporary files, which are deleted afterwards. The plot image also ends up there unless changed "$outplot"
Save this as a .ps1 file somewhere.
To make it run as a send to, create a shortcut to the .ps1 file in the Windows SendTo folder (hit WinKey+'R', then type 'shell:sendto' without the quotes, then Enter key).
Make the shortcut (hold shift and ctrl and drag the .ps1 in to create a shortcut). Open the shortcut properties and add 'Powershell.exe -ExecutionPolicy bypass -file ' before the path to the ps1 file. Then follow after the path with ' -infile'. OK and close out (all test without quotes).
Windows security is probably setup to prevent running unsigned and scripts not verified locally. It seems a bit pointless when a simple argument turns that off. Oh well.
Code:
# takes selected audio file,
# uses ffmpeg ebur128 filter for lufs stats
# and converts data to csv for graphing.
# uses gnuplot to plot the graph.
Param($infile)
$outcsv = "$env:Temp\loudnesscsv.txt"
$gnuplotcommandfile = "$env:Temp\gnuplotcmdfile.txt"
$outplot = "$env:Temp\LoudnessPlot.png"
$gnuplot = "C:\Program Files (x86)\gnuplot\gnuplot.exe"
Write-Host "Getting Loudness Data with ffmpeg."
$lufs_data = & ffmpeg.exe -i $infile -af ebur128 -f null - 2>&1
#$lufs_data | Out-File "t:\lufsdata.txt" -Encoding ASCII
Write-Host "Data Collected, now formatting to csv file."
$csv = $(
ForEach($rawentry in $lufs_data){
$entry = if($rawentry -match "parsed_ebur128"){$rawentry}
$array_tmsir = $entry -split(":") -split (" ") | ?{$_ -ne ""} | Select-Object -index 4,9,11,13,16
if($array_tmsir){
$time = $array_tmsir[0]
$Momentary = $array_tmsir[1]
$Short = $array_tmsir[2]
$Integrated = $array_tmsir[3]
$lra = $array_tmsir[4]
"$([math]::Round($time,1))" + ",$Momentary,$Short,$Integrated,$lra"
}
}
)
$csv | Out-String | Out-File $outcsv -Encoding ASCII
$entries = $csv.count
Write-Host "Running GNUPlot..."
$(
"set terminal png size 1280,720;"
"set output '$outplot';"
"set datafile separator ',';"
"set title `"$($infile -replace("\\","\\"))`" noenhanced;"
"set yrange [-60:0];"
"set ylabel 'Loudness (LUFS)';"
"set ytic 6;"
"set ytics nomirror;"
"set y2tics;"
"set y2range [0:30];"
"set y2tic 1;"
"set y2label 'Loudness Range (LU)';"
"set grid;"
"set key top left;"
"set xdata time;"
"set format x '%M:%S';"
"set xlabel 'Time (MM:SS)';"
"set autoscale xfix;"
"plot '$outcsv' using (`$0/10):2 axes x1y1 with lines lc rgb '#ff0000' lw 1 title 'Momentary', \"
" '' using (`$0/10):3 axes x1y1 with lines lc rgb '#8080ff' lw 3 title 'Short-Term', \"
" '' using (`$0/10):4 axes x1y1 with lines lc rgb '#0000ff' lw 4 title 'Integrated', \"
" '' using (`$0/10):5 axes x1y2 with lines lc rgb '#00aa00' lw 2 title 'Loudness Range';"
) | Out-String | Out-File $gnuplotcommandfile -Encoding ASCII
cmd.exe /c "`"$gnuplot`" <$gnuplotcommandfile"
Remove-Item -LiteralPath $outcsv
Remove-Item -LiteralPath $gnuplotcommandfile
& $outplot
exit
Yeah, it's a bit clumsily done. There are plenty of options that can be changed for colours, line thickness and stuff, as well as plot size, axis ranges etc.
I'm working on some code ideas to handle larger data sets and reducing it for speed. No point supplying data that can't be drawn as there isn't enough pixel space to plot them!
Examples: