ha-ffmpeg
ha-ffmpeg copied to clipboard
Support for microphone direct input
This is how I can easily use ffmpeg to detect noise using a microphone directly:
ffmpeg -f alsa -i hw:0,0 -af silencedetect=n=-40dB:d=1 -f null -
It seems like it is impossible to build such command using ffmpeg_noise HA integration, because haffpeg always puts input to the first place.
This is what I tried:
- platform: ffmpeg_noise
input: "hw:0,0"
extra_arguments: -f alsa
initial_state: true
duration: 1
reset: 20
peak: -40
And it didn't work because the command haffmpeg built was
'ffmpeg', '-i', 'hw:0,0', '-vn', '-f', 'alsa', '-filter:a', 'silencedetect=n=-40dB:d=1', '-f', 'null', '-']
As you can see, -f alsa follows after -i hw:0,0, so ffmpeg can't recognize the input.
I know that it's possible to stream data from microphone using rtp and then process it as described here, but I also know that it adds a lot of complications to the systemd configuration and it is not very efficient because the streaming constantly uses 10-15% of my CPU.
How difficult it would be to add support for direct microphone input?
@zhulik I'm not sure if this is still relevant :slightly_smiling_face: but you can try passing alsa related arguments to the input option. For example, I'm using this config with my mic:
- platform: ffmpeg_noise
input: -f alsa -ac 1 -i hw:1,0
extra_arguments: '-hide_banner -nostats -filter:a highpass=f=6000'
peak: -22
reset: 20
@black-roland Thanks, I'll try it
Works for me with such configuration:
- platform: ffmpeg_noise
input: -f alsa -channels 1 -i hw:1
extra_arguments: -filter:a highpass=f=99,lowpass=f=250
initial_state: true
duration: 2
reset: 3
peak: -45
But there is an issue, it stops working after some time (~1h), nothing in logs, binary_sensor is all time in "Clear" state, and microphone itself is in busy state (means process is running, but not piped to Home Assistant?)
This is output when I try to run ffmpeg command in HASS container cmd:
[alsa @ 0x7f8ddd7940] cannot open audio device hw:1 (Resource busy) hw:1: I/O error