brutella / hkcam

Open-Source HomeKit Surveillance Camera
https://hochgatterer.me/hkcam/
Apache License 2.0
920 stars 141 forks source link

HKCam only works with FFmpeg command via ssh #116

Closed PvdGulik closed 3 years ago

PvdGulik commented 3 years ago

Hello brutella,

After flashing a SD card etc. and put it in my Raspberry Pi Zero W, HKCam does not work. If I open the Home app, the led on the camera blinks one time but camera does not respond. When I connect to the Pi via SSH and give the following command, the camera starts, and is visible in the Home-app.

ffmpeg -f v4l2 -i /dev/video0 -vf format=yuv420p -f v4l2 /dev/video1 or ffmpeg -f v4l2 -i /dev/video0 -pix_fmt yuv420p -f v4l2 /dev/video1

If I use the command ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1 found in the HKCam/current logging, this is the output: ffmpeg version 3.2.14-1~deb9u1+rpt1 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516 configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 34.101 / 55. 34.101 libavcodec 57. 64.101 / 57. 64.101 libavformat 57. 56.101 / 57. 56.101 libavdevice 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100 [video4linux2,v4l2 @ 0x17c1180] Time per frame unknown Input #0, video4linux2,v4l2, from '/dev/video0': Duration: N/A, start: 6373.624168, bitrate: N/A Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 31 tbr, 1000k tbn, 1000k tbc [v4l2 @ 0x17c2f20] V4L2 output device supports only a single raw video stream Could not write header for output file #0 (incorrect codec parameters ?): Invalid argumentStream mapping: Stream #0:0 -> #0:0 (copy) Last message repeated 1 times

If I use the command ffmpeg -f v4l2 -i /dev/video0 -vf format=yuv420p -f v4l2 /dev/video1 I suggested above this is the output: ffmpeg version 3.2.14-1~deb9u1+rpt1 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516 configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 34.101 / 55. 34.101 libavcodec 57. 64.101 / 57. 64.101 libavformat 57. 56.101 / 57. 56.101 libavdevice 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100 [video4linux2,v4l2 @ 0x1204180] Time per frame unknown Input #0, video4linux2,v4l2, from '/dev/video0': Duration: N/A, start: 6567.309262, bitrate: N/A Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 31 tbr, 1000k tbn, 1000k tbc [swscaler @ 0x12099c0] deprecated pixel format used, make sure you did set range correctly Output #0, v4l2, to '/dev/video1': Metadata: encoder : Lavf57.56.101 Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, q=2-31, 200 kb/s, 31 fps, 31 tbn, 31 tbc Metadata: encoder : Lavc57.64.101 rawvideo Stream mapping: Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native)) Press [q] to stop, [?] for help frame= 71 fps= 24 q=-0.0 Lsize=N/A time=00:00:02.29 bitrate=N/A dup=36 drop=0 speed=0.779x

How to solve this, or where in HKCam should I change the FFmpeg command according my command?

Thank you

robin-siegl commented 3 years ago

I got the same issue. Video not showing in the home app from apple. The commands you wrote doesn't work for me as workaround.

PvdGulik commented 3 years ago

Do you get errors when you give the command ffmpeg -f v4l2 -i /dev/video0 -vf format=yuv420p -f v4l2 /dev/video1

With a other Webcam I don't need to give the specific command with -vf format=yuv420p, but the standard command works ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1

But at the end, I always have to start the FFmpeg-command to get it working. Don't no why?

robin-siegl commented 3 years ago

No, didn't get any errors. I don't know if this is issue on my side, i already tried different homekit camera solutions. I always get the issue where the camera can't get a connection.

PvdGulik commented 3 years ago

I found a better solution: use in front of FFmpeg the following LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so

So resulting in LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1

Now only, how do I tell HKCAM to start with this?

PvdGulik commented 3 years ago

I’m sure there must be something wrong with the ffmpeg command which HKCam generates:

When I start the command as I mentioned before,ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1 , I don’t get errors.

When HKCam is running and I open in the Homekit-app the camera, I get these logging errors.

But when HKCam is running and I give the command, ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1, the streaming starts in the Homekit App.

So I’m searching where the command is build. What I see in the logging is: /usr/bin/ffmpeg [ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1] I think it should be: /usr/bin/ffmpeg [-f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1], so without the second ffmeg

What do you think?

PvdGulik commented 3 years ago

Solved, I'll publish a install instruction for Buster