homebridge-camera-ui: Problem with Audio
Describe the bug Hello I have an error when Audio is on with an v4l2 camera + alsa device.
To Reproduce The problem appear everytime I start the Video visualization in Home app. if I disable audio, all works fine.
Here is my config file :
"cameras": [
{
"name": "Rpicam",
"motion": true,
"motionTimeout": 60,
"unbridge": true,
"hsv": true,
"prebuffering": true,
"prebufferLength": 4,
"videoConfig": {
"source": "-f video4linux2 -input_format h264 -framerate 25 -video_size hd720 -i /dev/video0 -f alsa -i default:CARD=Device",
"vcodec": "copy",
"audio": true,
"debug": true
},
"videoanalysis": {
"active": true
}
}
Logs Here are the Homebridge logs in debug mode :
[1/13/2022, 12:48:39 PM] Homebridge v1.4.0-beta.4 (HAP v0.10.0-beta.7) (Homebridge 34EB) is running on port 53540.
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Setting up camera, please be patient...
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Probe stream: ffmpeg -f video4linux2 -input_format h264 -framerate 25 -video_size hd720 -i /dev/video0 -f alsa -i default:CARD=Device
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: {"probe":true,"timedout":false,"audio":["pcm_s16le","48000 Hz","stereo","s16","1536 kb/s"],"video":["h264 (High)","yuv420p(progressive)","1280x720","25 fps","25 tbr","1000k tbn","2000k tbc"]}
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Incoming ping request for: /dev/video0 -f alsa - Timeout: 1s
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Pinging /dev/video0 -f alsa - successfull
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Start prebuffering...
[1/13/2022, 12:48:40 PM] [CameraUI] Rpicam: Prebuffering command: ffmpeg -hide_banner -loglevel error -fflags +genpts -f video4linux2 -input_format h264 -framerate 25 -video_size hd720 -i /dev/video0 -f alsa -i default:CARD=Device -vcodec copy -bsf:a aac_adtstoasc -acodec libfdk_aac -profile:a aac_low -flags +global_header -ar 8k -b:a 100k -ac 1 -f tee -map 0:v? -map 0:a? [movflags=frag_keyframe+empty_moov+default_base_moof:f=mp4]tcp://127.0.0.1:31319|[f=mpegts]tcp://127.0.0.1:20080
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Prebuffering scheduled for restart at 2AM: 791 minutes
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Incoming ping request for: /dev/video0 -f alsa - Timeout: 1s
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Pinging /dev/video0 -f alsa - successfull
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Start videoanalysis...
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Videoanalysis command: ffmpeg -hide_banner -loglevel error -hwaccel auto -analyzeduration 0 -probesize 500000 -f mpegts -i tcp://127.0.0.1:27137 -an -vcodec pam -pix_fmt rgba -f image2pipe -vf fps=2,scale=640:360 pipe:1
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Videoanalysis: Currently active zones: []
[1/13/2022, 12:48:41 PM] [CameraUI] Rpicam: Videoanalysis scheduled for restart at 3AM: 851 minutes
[1/13/2022, 12:48:42 PM] [CameraUI] Rpicam: Configuring unbridged accessory...
[1/13/2022, 12:48:42 PM] [CameraUI] Rpicam: Setting up accessory...
[1/13/2022, 12:48:42 PM] [CameraUI] Rpicam: Adding motion sensor service
[1/13/2022, 12:48:42 PM] [CameraUI] Rpicam: Initializing HomeKit Secure Video
[1/13/2022, 12:48:42 PM] [CameraUI] camera.ui v5.0.5 is listening on port 8081 (http)
[1/13/2022, 12:48:42 PM] Rpicam 5BC7 is running on port 46199.
[1/13/2022, 12:48:42 PM] Please add [Rpicam 5BC7] manually in Home app. Setup Code: 031-45-154
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Start stream requested: 1920x1080, 30 fps, 802 kbps
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Incoming ping request for: /dev/video0 -f alsa - Timeout: 1s
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Pinging /dev/video0 -f alsa - successfull
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Setting prebuffer stream as input
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Starting video stream: native
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: Stream command: ffmpeg -hide_banner -loglevel level+verbose -analyzeduration 0 -probesize 3100684 -f mpegts -i tcp://127.0.0.1:35830 -an -sn -dn -vcodec copy -pix_fmt yuv420p -color_range mpeg -f rawvideo -payload_type 99 -ssrc 13233275 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params olWC8D5/55LfjPg2dTckqgnV8nngwHnnIim7WcBF srtp://192.168.50.167:50190?rtcpport=50190&pkt_size=1318 -vn -sn -dn -acodec libfdk_aac -profile:a aac_eld -flags +global_header -f null -ar 16k -b:a 24k -ac 1 -payload_type 110 -ssrc 6957011 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params PsJ4fF8LPDGQb9aQHt9G95+QrlOtoSKDg8xuAri0 srtp://192.168.50.167:52863?rtcpport=52863&pkt_size=188 -progress pipe:1
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: [tcp @ 0xb6f2f650] [verbose] Starting connection attempt to 127.0.0.1 port 35830
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: [tcp @ 0xb6f2f650] [verbose] Successfully connected to 127.0.0.1 port 35830
[1/13/2022, 12:48:49 PM] [CameraUI] Rpicam: [h264 @ 0xb6f32870] [verbose] Reinit context to 1280x720, pix_fmt: yuv420p
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [mpegts @ 0xb6f2f010] [verbose] max_analyze_duration 5000000 reached at 5037411 microseconds st:0
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Input #0, mpegts, from 'tcp://127.0.0.1:35830':
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Duration: N/A, start: 2.958478, bitrate: N/A
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Program 1
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Metadata:
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] service_name : Service01
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] service_provider: FFmpeg
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Stream #0:0[0x100]: Video: h264 (High), 1 reference frame ([27][0][0][0] / 0x001B), yuv420p(progressive, left), 1280x720, 25 tbr, 90k tbn, 180k tbc
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [info] Output #1, rtp, to 'srtp://192.168.50.167:52863?rtcpport=52863&pkt_size=188':
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [error] Output file #1 does not contain any stream
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [AVIOContext @ 0x2b23290] [verbose] Statistics: 0 seeks, 0 writeouts
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: [AVIOContext @ 0xb6f2f7b0] [verbose] Statistics: 2785168 bytes read, 0 seeks
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: Prebuffer request ended
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: FFmpeg exited with code: 1 and signal: null - [error] Output file #1 does not contain any stream
[1/13/2022, 12:48:50 PM] [CameraUI] Rpicam: Stopped video stream.
[1/13/2022, 12:48:53 PM] [CameraUI] Rpicam: Snapshot requested: 1280 x 720
[1/13/2022, 12:48:53 PM] [CameraUI] Rpicam: Snapshot command: ffmpeg -hide_banner -loglevel error -analyzeduration 0 -probesize 3096736 -f mpegts -i tcp://127.0.0.1:17187 -frames:v 1 -f image2 -
[1/13/2022, 12:48:53 PM] [CameraUI] Rpicam: Prebuffer request ended
Environment
- Homebridge Version: v1.4.0-beta.4 in Docker
- Camera UI Version: v5.0.5
- Operating System: Raspbian Bullseye on RPI v4
- Browser: Home App in iOS
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (13 by maintainers)
Thank you for your help đ„ !
Iâm closing this issue, as I opened the feature request for rtsp server.
For the wiki, I tuned a little bit more the configuration. Here is what itâs look like now :
docker-compose.yml :
And the config.json :
On a Raspberry Pi 4, with Raspbian Bullseyes, Raspberry Pi Camera Running at ~30% CPU. Delay : ~1s in Home App
An other workaround is to use âforceprebufferâ on. But it consumes much CPU. I think you could add the option
-preset:v ultrafastwith the forceprebuffer option to lower the CPU impact.For information, here is my conf with an intermediate RTSP Server :
In the dockerfile, I defined 3 containers. The first, ârtspâ, is the rtsp server. The image I found works on RPi ARM and x86 machines.
The second, âffmpeg-usbcamâ, is based on the homebridge image to keep the same ffmpeg binary. The start command is replaced by a ffmpeg command that read the v4l2 Camera and audio streams, and send them to the RTSP Server.
The third, âhomebridgeâ, is the standard homebridge server.
Then the config.json file of homebridge is like this :
All seems to work with this configuration, even if Iâm sure I can improve it to be able to use the âcopyâ codec for audio stream too.
No problem ! I can switch the config back and forward without delay for your tests.