Calculating audio peak with shell and ffmpeg

When I run the following script in Terminal I get a lot of information about the audio file, including the audio peak which is what I want to know:

but when I run the same script in KM using the Execute Shell, nothing comes up:

ffmpeg -i /Users/dannywyatt/My\ Files/Inbox\ Global/Timbales\ Samples/high\ hit/high\ hit\ 01.wav -filter:a volumedetect -f null /dev/nul

Since I seem to still have an issue with KM finding the path for ffmpeg:
Action 15605696 failed: Execute a Shell Script failed with script error: text-script: line 1: ffmpeg: command not found

I used the version that seems to find ffmpeg, but I get no results:

/opt/anaconda3/bin/ffmpeg -i /Users/dannywyatt/My\ Files/Inbox\ Global/Timbales\ Samples/high\ hit/high\ hit\ 01.wav -filter:a volumedetect -f null /dev/null

I also tried this, but I have no idea if there's anything wrong here?
I can see PATH on the script, but the variable is ENV_PATH, so I'm not sure if this influences?

Also tried the script by removing the last part "-f null /dev/null", not sure if this makes any difference or not?

Extra info about this script from ffmpeg:
https://trac.ffmpeg.org/wiki/AudioVolume

Yes, hard-coding the path is simpler and I do not think you need to worry about environmental variables here.

"You can output to /dev/null... if you want to choose a muxer but not actually output a file" (FFmpeg wiki: Null). So I would leave that in.

Does your Execute a Shell Script action definitely run? Try replacing "Display results large" with "Display results in a window". As I test output settings right now, I am getting unpredictable results, so I wonder if there might even be a bug in KM related to this action (I am using V. 11.0.2 and changing the display output setting does not always take immediate effect).

PS
I believe you should be able to remove this line export PATH-"/opt/anaconda3/bin: $PATH". Further reading:

Yes the action is working. I have this macro with this action below for example which I just tested and it works
image

This doesn't work:
image

neither does this:
image

For these 2 above I get no Engine errors. I only get the error when I use this:
image

So for examples 2 and 3, with the output of the action set to "Display results in a window", you see a window, but it is empty, yes?

(Example 4 is as expected because of the missing path to ffmpeg).

No, not even a window pops up.
I see the icon of the engine at the top rotating for like 1/4 of a second and it stops. Nothing happens other than that

But again, this works in Terminal so the issue is with KM

The issue is that ffmpeg writes to standard error (stderr), not standard output (stdout). Here are two easy ways in which you can get the Execute shell script action to handle this.

Solution 1

You can redirect stderr to stdout using 2>&1 e.g.

ffmpeg -i " /Users/dannywyatt/My Files/Inbox Global/test .wav" -filter:a volumedetect -f null /dev/null 2>&1

Solution 2

Go to the cog icon in the Execute shell script action and enable "Include errors".

That is all too technical for me, I'm afraid...

I tried both solutions and they both work.
I was able to create a macro for a single file and it's working (by removing all the info I don't need), now I have to create a new one for when I have multiple files selected so I can have a list.

Great! Thank you so much for your time and help! Truly valuable!
You saved me so much time and work by not doing it by hand using an app :raised_hands:

1 Like