brutella / hkcam

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

Camera Not Available. #58

Closed Gaiz84 closed 3 years ago

Gaiz84 commented 4 years ago

Having problems during viewing the HKcam. Getting the message: “ This camera is being viewed by someone else” But no one else is viewing also not with another device.
I do get every 15 sec a refresh of the screen when I’m viewing the cam in preview mode. Hope someone can help!

brutella commented 4 years ago

Does this message also appear when you restart your Raspberry Pi?

Gaiz84 commented 4 years ago

This message appears in about 10min after reboot. Before that it works fine.

brutella commented 4 years ago

Please verify that the ffmpeg process is terminated once you stop viewing the live stream from your iOS device.

Gaiz84 commented 4 years ago

How to verify this? When I close the HomeKit-app with double tap on homebutton and swipe the app up it keeps working fine after restarting the app.

kevlacross commented 4 years ago

I have the Same Problem

robacarp commented 4 years ago

@brutella I also have this problem. When I ps aux | grep ffmpeg I see many defunct processes. After terminating and restarting the hkcam process, they go away. Watching the server while I open up the camera, and then close it, I see this:

Is there something in my server config that should be changed to allow the ffmpeg processes to be properly terminated?

brutella commented 4 years ago

@robacarp What app are you using to view the camera stream?

robacarp commented 4 years ago

@brutella the apple default app “Home”

standaniels commented 4 years ago

I have this issue too. I'm on iOS 13.1, Apple TV is on 13.0 I believe. And the issues occurs in Apple's Home app and Home+ 4.

$ ps aux | grep ffmpeg
root       580  0.0  0.0      0     0 ?        Z    Sep26   0:01 [ffmpeg] <defunct>
root       583  0.0  0.0      0     0 ?        Z    Sep26   0:05 [ffmpeg] <defunct>
root       584  0.0  0.0      0     0 ?        Z    Sep26   0:02 [ffmpeg] <defunct>
root       639  0.0  0.0      0     0 ?        Z    Sep26   0:02 [ffmpeg] <defunct>
root       641 35.9 18.3 170624 69488 ?        S    Sep26 327:18 ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1
root       642 12.1 10.2 189112 38640 ?        Sl   Sep26 110:34 ffmpeg -f v4l2 -framerate 30 -i /dev/video1 -an -codec:v h264_omx -pix_fmt yuv420p -vsync vfr -video_size 1280:-2 -framerate 30 -level:v 4.0 -f rawvideo -b:v 299k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params 40IuWBTMTQZ+AssZvNvIZ4Wj6MqtQvnh75hruqy1 srtp://192.168.2.163:63307?rtcpport=63307&localrtcpport=63307&pkt_size=1378&timeout=60
pi        1309  0.0  0.4   4332  1868 pts/0    S+   09:00   0:00 grep --color=auto ffmpeg

Immediately after rebooting there's a defunct ffmpeg process:

$ ps aux | grep ffmpeg
root       527  0.9  0.0      0     0 ?        Z    09:06   0:01 [ffmpeg] <defunct>
pi         577  0.0  0.4   4332  1868 pts/0    S+   09:10   0:00 grep --color=auto ffmpeg

When I try to watch a live stream of the camera, it succeeds:

$ ps aux | grep ffmpeg
root       527  0.7  0.0      0     0 ?        Z    09:06   0:01 [ffmpeg] <defunct>
root       578 36.5 18.7 171976 70840 ?        R    09:10   0:15 ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1
root       579 17.1 10.2 189112 38664 ?        Rl   09:10   0:07 ffmpeg -f v4l2 -framerate 30 -i /dev/video1 -an -codec:v h264_omx -pix_fmt yuv420p -vsync vfr -video_size 1280:-2 -framerate 30 -level:v 4.0 -f rawvideo -b:v 299k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params pEHbFINtHJRKai95POxyAq3zHcdVs+ds8fg/S7Rm srtp://192.168.2.225:55488?rtcpport=55488&localrtcpport=55488&pkt_size=1378&timeout=60
pi         587  0.0  0.5   4332  1948 pts/0    S+   09:10   0:00 grep --color=auto ffmpeg

After closing the live stream the process is marked as defunct:

$ ps aux | grep ffmpeg
root       527  0.6  0.0      0     0 ?        Z    09:06   0:01 [ffmpeg] <defunct>
root       578 35.5  0.0      0     0 ?        Z    09:10   0:36 [ffmpeg] <defunct>
root       579 15.9  0.0      0     0 ?        Z    09:10   0:16 [ffmpeg] <defunct>
pi         589  0.0  0.4   4332  1864 pts/0    S+   09:11   0:00 grep --color=auto ffmpeg

But I'm still able to connect the camera; another ffmpeg process is created:

$ ps aux | grep ffmpeg
root       527  0.4  0.0      0     0 ?        Z    09:06   0:01 [ffmpeg] <defunct>
root       578 20.7  0.0      0     0 ?        Z    09:10   0:36 [ffmpeg] <defunct>
root       579  9.2  0.0      0     0 ?        Z    09:10   0:16 [ffmpeg] <defunct>
root       590  3.1  0.0      0     0 ?        Z    09:11   0:02 [ffmpeg] <defunct>
root       592  4.0  0.0      0     0 ?        Z    09:12   0:02 [ffmpeg] <defunct>
root       594  5.7  0.0      0     0 ?        Z    09:12   0:02 [ffmpeg] <defunct>
root       597 37.9 18.6 171976 70592 ?        R    09:12   0:09 ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1
root       598 19.6 10.2 189112 38688 ?        Rl   09:12   0:04 ffmpeg -f v4l2 -framerate 30 -i /dev/video1 -an -codec:v h264_omx -pix_fmt yuv420p -vsync vfr -video_size 1280:-2 -framerate 30 -level:v 4.0 -f rawvideo -b:v 299k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params zhlgiXnJe14SS4Xd0LwQgTrUY1r/j6Q2S52njoLR srtp://192.168.2.225:59981?rtcpport=59981&localrtcpport=59981&pkt_size=1378&timeout=60

And again, closing the stream marks the process as . But I'm still able to start a live stream, which results in another ffmpeg process...

brutella commented 4 years ago

I have no idea why there are ffmpeg process marked as defunct. I've learned from stackoverflow that it means that a parent process hasn't correctly killed the child (ffmpeg) process.

This already worked in my environment using Go1.11/12 and Raspbian Stretch Lite 2019-04-08.

Which Raspbian version are you using? Which Go version are you using? Which ffmpeg version are you using?

standaniels commented 4 years ago

I've used the raspbian-stretch-lite-2019-04-08-hkcam-v0.0.9-armv6 image without any changes. I can't find go on the Pi, or is that irrelevant since I didn't build the image myself?

pi@camera:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

pi@camera:~ $ ffmpeg -version
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
robacarp commented 4 years ago

Which Raspbian version are you using?

My Rasbian is identical -- Stretch. Mine was installed from a factory image straight to the SD card.

Which ffmpeg version are you using?

ffmpeg is 3.2.12-1, installed with just apt install ffmpeg
ffmpeg version 3.2.12-1~deb9u1+rpt1 Copyright (c) 2000-2018 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

Which Go version are you using?

None, I just downloaded the binary release:

$ wget https://github.com/brutella/hkcam/releases/download/v0.0.8/hkcam-v0.0.8_linux_armhf.tar.gz
$ tar xzf hkcam-v0.0.8_linux_armhf.tar.gz
$ cd hkcam-v0.0.8_linux_armhf/
$ sudo cp usr/bin/hkcam /usr/local/bin

For my own sanity the process I went through is documented here

Tymo3 commented 4 years ago

Gents, I have the same issue (raps zero, camera 8Mpix). I have very exact version as standaniels. Ios 13.1.2

But I have added "-multi-stream" info "run" script. It works but every time it leaves next ffmpeg defunc

pi@raspberrypi:~ $ more /etc/sv/hkcam/run 
#!/bin/sh -e
exec 2>&1
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
exec hkcam -multi_stream --data_dir=/var/lib/hkcam/data --verbose=true

e.g. after 10 minutes lock/unlock phone and taking a look at Home app...

every 2.0s: ps -ef | grep ffmpeg                                          raspberrypi: Sat Oct 12 12:40:52 2019

root       526   457  0 12:29 ?        00:00:01 [ffmpeg] <defunct>
root       528   457  2 12:30 ?        00:00:14 [ffmpeg] <defunct>
root       529   457  1 12:30 ?        00:00:06 [ffmpeg] <defunct>
root       538   457  9 12:30 ?        00:00:59 [ffmpeg] <defunct>
root       539   457  3 12:30 ?        00:00:21 [ffmpeg] <defunct>
root       549   457  2 12:31 ?        00:00:16 [ffmpeg] <defunct>
pi         606   569  1 12:32 pts/1    00:00:09 watch ps -ef | grep ffmpeg
root       663   457  0 12:33 ?        00:00:02 [ffmpeg] <defunct>
root       673   457  0 12:33 ?        00:00:02 [ffmpeg] <defunct>
root       683   457  7 12:33 ?        00:00:36 [ffmpeg] <defunct>
root       684   457  1 12:33 ?        00:00:05 [ffmpeg] <defunct>
root       699   457  2 12:33 ?        00:00:10 [ffmpeg] <defunct>
root       780   457  1 12:34 ?        00:00:06 [ffmpeg] <defunct>
root       848   457  0 12:34 ?        00:00:02 [ffmpeg] <defunct>
root       866   457  1 12:34 ?        00:00:05 [ffmpeg] <defunct>
root       871   457  0 12:34 ?        00:00:02 [ffmpeg] <defunct>
root       903   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       917   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       935   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       955   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       970   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       984   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root       998   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root      1012   457  0 12:35 ?        00:00:02 [ffmpeg] <defunct>
root      1030   457  0 12:36 ?        00:00:02 [ffmpeg] <defunct>
root      1056   457  0 12:36 ?        00:00:02 [ffmpeg] <defunct>
root      1086   457  0 12:36 ?        00:00:02 [ffmpeg] <defunct>
root      1116   457  0 12:36 ?        00:00:02 [ffmpeg] <defunct>
root      1142   457  0 12:37 ?        00:00:02 [ffmpeg] <defunct>
root      1172   457  1 12:37 ?        00:00:02 [ffmpeg] <defunct>
root      1198   457  1 12:37 ?        00:00:02 [ffmpeg] <defunct>
root      1228   457  1 12:37 ?        00:00:02 [ffmpeg] <defunct>
root      1254   457  1 12:38 ?        00:00:02 [ffmpeg] <defunct>
root      1284   457  1 12:38 ?        00:00:02 [ffmpeg] <defunct>
root      1310   457  1 12:38 ?        00:00:02 [ffmpeg] <defunct>
root      1340   457  1 12:38 ?        00:00:02 [ffmpeg] <defunct>
root      1366   457  1 12:39 ?        00:00:02 [ffmpeg] <defunct>
root      1397   457  2 12:39 ?        00:00:02 [ffmpeg] <defunct>
root      1427   457  2 12:39 ?        00:00:02 [ffmpeg] <defunct>
root      1453   457  3 12:39 ?        00:00:02 [ffmpeg] <defunct>
root      1483   457  4 12:39 ?        00:00:02 [ffmpeg] <defunct>
root      1509   457  5 12:40 ?        00:00:02 [ffmpeg] <defunct>
root      1539   457  9 12:40 ?        00:00:02 [ffmpeg] <defunct>
root      1570   457 24 12:40 ?        00:00:02 [ffmpeg] <defunct>
root      1580   457 50 12:40 ?        00:00:02 ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1
pi        1586   606  0 12:40 pts/1    00:00:00 watch ps -ef | grep ffmpeg
pi        1587  1586  0 12:40 pts/1    00:00:00 sh -c ps -ef | grep ffmpeg
pi        1589  1587  0 12:40 pts/1    00:00:00 grep ffmpeg
Tymo3 commented 4 years ago

... and as a continuation (according to this post) for "defunct" you have to kill parent in this case "hkcam" process

[...]"defunct", which means the process has either completed its task or has been corrupted or killed, but its child processes are still running or these parent process is monitoring its child process. To kill this kind of process, kill -9 PID doesn't work. You can try to kill them with this command but it will show this again and again.

Determine which is the parent process of this defunct process and kill it. [...]

klaaskox commented 4 years ago

I am facing the same problem. Killing the parent process (or rebooting) solves it, but it keeps coming back.

RefineryX commented 4 years ago

I am having the same issue. It looks like the process is not quitting successfully when closing the camera feed within the Home App. It leaves the process running and I am faced with "wait until someone else in the home stops viewing this camera and try again" message.

I am running the default image.

Running ps aux | grep ffmpeg gives me:


root       524  2.0  0.0      0     0 ?        Z    16:30   0:12 [ffmpeg] <defunct>
root       525  1.1  0.0      0     0 ?        Z    16:30   0:07 [ffmpeg] <defunct>
root       533  0.4  0.0      0     0 ?        Z    16:33   0:02 [ffmpeg] <defunct>
root       535  0.4  0.0      0     0 ?        Z    16:33   0:02 [ffmpeg] <defunct>
root       537  2.2  0.0      0     0 ?        Z    16:33   0:09 [ffmpeg] <defunct>
root       538  1.2  0.0      0     0 ?        Z    16:33   0:05 [ffmpeg] <defunct>
root       546  0.8  0.0      0     0 ?        Z    16:36   0:02 [ffmpeg] <defunct>
root       548  4.7  0.0      0     0 ?        Z    16:36   0:10 [ffmpeg] <defunct>
root       549  2.5  0.0      0     0 ?        Z    16:36   0:05 [ffmpeg] <defunct>
root       559  3.8  0.0      0     0 ?        Z    16:39   0:02 [ffmpeg] <defunct>
root       561 37.5 18.4 171976 69824 ?        R    16:39   0:15 ffmpeg -f v4l2 -i /dev/video0 -codec:v copy -f v4l2 /dev/video1
root       562 20.3 10.1 189112 38504 ?        Sl   16:39   0:08 ffmpeg -f v4l2 -framerate 30 -i /dev/video1 -an -codec:v h264_omx -pix_fmt yuv420p -vsync vfr -video_size 1280:-2 -framerate 30 -level:v 4.0 -f rawvideo -b:v 800k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params eG1iULEgyreg6C4QhveVYiUVBAmJT6J3mrXJS22f srtp://192.168.0.28:53862?rtcpport=53862&localrtcpport=53862&pkt_size=1378&timeout=60
pi         570  0.0  0.5   4360  2040 pts/0    S+   16:40   0:00 grep --color=auto ffmpeg```
robacarp commented 4 years ago

I'm just noticing that when the camera is Unavailable on the phone, it is sometimes still fine and available on bigger screens - ipad/macos.

brutella commented 3 years ago

@Gaiz84 This should be fixed now with c20bcd1