homebridge-plugins / homebridge-camera-ffmpeg

Homebridge Plugin Providing FFmpeg-based Camera Support
https://homebridge-plugins.github.io/homebridge-camera-ffmpeg/
Apache License 2.0
1.09k stars 227 forks source link

Correct returnAudioTarget for direct playback on the Raspberry #1432

Closed rachedamer closed 10 months ago

rachedamer commented 10 months ago

I am currently trying to build a video doorbell using a Raspberry Pi 2 Zero for which I need two-way audio. For this, I want to playback the return audio directly on the Pi running Homebridge via a USB speaker that is connected to it. What would be the correct ffmpeg parameters for returnAudioTarget to do so?

The audio device to play the return audio lists under aplay -l as follows:

Karte 2: UACDemoV10 [UACDemoV1.0], Gerät 0: USB Audio [USB Audio] Sub-Geräte: 1/1 Sub-Gerät #0: subdevice #0

I was thinking of

-f alsa "hw:2,0"

or

-f pulse "default"

Am I thinking correctly?

rachedamer commented 10 months ago

I tried both options now, but as soon as I press the Speak-Button in the Home app, the Homebridge log shows

[Two-way] FFmpeg exited with code: 187 and signal: null (Error)

and the picture freezes.

I have compiled my own version of ffmpeg with the following options:

ffmpeg version N-113150-ge063c1d079 Copyright (c) 2000-2023 the FFmpeg developers built with gcc 10 (Raspbian 10.2.1-6+rpi1) configuration: --enable-libx264 --enable-gpl --enable-libmp3lame --enable-libfdk-aac --enable-nonfree --enable-libpulse libavutil 58. 36.100 / 58. 36.100 libavcodec 60. 36.100 / 60. 36.100 libavformat 60. 20.100 / 60. 20.100 libavdevice 60. 4.100 / 60. 4.100 libavfilter 9. 14.102 / 9. 14.102 libswscale 7. 6.100 / 7. 6.100 libswresample 4. 13.100 / 4. 13.100 libpostproc 57. 4.100 / 57. 4.100

rachedamer commented 10 months ago

I turned on debug logging for two-way audio and now I get the following (using "-f pulse default"):

[31.12.2023, 13:31:26] [Camera FFmpeg] [Gegensprechanlage] [Two-way] [PulseAudio outdev @ 0x45d55e0] [error] Cannot connect context: Access denied. [31.12.2023, 13:31:26] [Camera FFmpeg] [Gegensprechanlage] [Two-way] [out#0/pulse @ 0x45d80c0] [error] Could not write header (incorrect codec parameters ?): Generic error in an external library [31.12.2023, 13:31:26] [Camera FFmpeg] [Gegensprechanlage] [Two-way] [af#0:0 @ 0x45d6690] [error] Error sending frames to consumers: Generic error in an external library [31.12.2023, 13:31:26] [Camera FFmpeg] [Gegensprechanlage] [Two-way] [af#0:0 @ 0x45d6690] [error] Task finished with error code: -542398533 (Generic error in an external library) [31.12.2023, 13:31:26] [Camera FFmpeg] [Gegensprechanlage] [Two-way] [af#0:0 @ 0x45d6690] [error] Terminating thread with return code -542398533 (Generic error in an external library)

Outputting from the command line as user pi using "ffmpeg -f pulse default" works fine.

rachedamer commented 10 months ago

Okay, I think I found the issue. PulseAudio doesn't accept inputs from multiple users which is why it output the file from the command line as user 'pi' but not any input from the homebridge user. My workaround was to use ALSA instead of Pulse which I could make work by using plughw instead of hw. So "returnAudioTarget": "-f alsa plughw:2,0", did the trick for me.