Didel / HomeKitCam

A project to make a Raspberry Pi driven, HomeKit Enabled camera.
MIT License
79 stars 11 forks source link

Entering camera stream in iOS Home app crashes PiCamera_accessory.js #3

Open pawelrup opened 7 years ago

pawelrup commented 7 years ago

Hi! When I enter camera stream in iOS Home app PiCamera_accessory.js crashes.

bitrate:  299
avconv stream:  -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params gAi3S7pQdEW/Z7GPqOGtV8TgR/2xLvHcUXtD+Lcv srtp://192.168.1.14:60622?rtcpport=60622&localrtcpport=60622&pkt_size=1378
events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: spawn avconv ENOENT
    at _errnoException (util.js:1026:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
    at onErrorNT (internal/child_process.js:374:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

If it could help, I have Raspbery PI Zero W with Camera v2.1 and 16GB SD Card, clean Raspbian Stretch Lite installed from raspberrypi.org with enabled camera using sudo raspi-config and HAP-NodeJS installed as recommended on instalation guide.

theopoon commented 7 years ago

Can you confirm avconv is installed? on some pi images it does not.

pawelrup commented 7 years ago

I installed avconv with libav-tools and it's not crashing now. In Home app on main screen it refreshes screenshot every about 10 seconds, but when I will enter camera to see live streaming it's loading for 30s and displays "No response. This camera is not responding".

theopoon commented 7 years ago

Log the streaming command to console, test the command in terminal by itself to see any error(s)

pawelrup commented 7 years ago

This is all console log I have until it shows "No response".

*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
HAP-NodeJS starting...
  EventedHTTPServer Server listening on port 51062 +0ms
  EventedHTTPServer [::ffff:192.168.178.37] New connection from client +2s
  EventedHTTPServer [::ffff:192.168.178.37] HTTP server listening on port 38191 +19ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /pair-verify +146ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: POST /pair-verify +7ms
  HAPServer [EC:22:3D:D3:CE:CE] Pair verify step 1/2 +57ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +176ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /pair-verify +145ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: POST /pair-verify +3ms
  HAPServer [EC:22:3D:D3:CE:CE] Pair verify step 2/2 +17ms
  HAPServer [EC:22:3D:D3:CE:CE] Client 044BD08A-A723-446A-AB53-4DCD4DCD792A verification complete +34ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +15ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /accessories +139ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /accessories +2ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +82ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +143ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +2ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":22,"ev":true}] +15ms
  Accessory [Node Camera] Registering Characteristic "Streaming Status" for events +11ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +148ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +2ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":15,"ev":true}] +9ms
  Accessory [Node Camera] Registering Characteristic "Streaming Status" for events +3ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +6ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics?id=1.22 +16ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /characteristics?id=1.22 +2ms
  Accessory [Node Camera] Getting value for Characteristic "Streaming Status" +21ms
  Accessory [Node Camera] Got Characteristic "Streaming Status" value: AQEA +10ms
  EventedHTTPServer [::ffff:192.168.178.37] Muting event '1.22' notification for this connection since it originated here. +13ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +3ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics?id=1.15 +108ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /characteristics?id=1.15 +3ms
  Accessory [Node Camera] Getting value for Characteristic "Streaming Status" +7ms
  Accessory [Node Camera] Got Characteristic "Streaming Status" value: AQEA +3ms
  EventedHTTPServer [::ffff:192.168.178.37] Muting event '1.15' notification for this connection since it originated here. +9ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +3ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +2s
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +3ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":15,"ev":true},{"aid":1,"iid":22,"ev":true}] +8ms
  Accessory [Node Camera] Registering Characteristic "Streaming Status" for events +3ms
  Accessory [Node Camera] Registering Characteristic "Streaming Status" for events +5ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics?id=1.11,1.18 +329ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /characteristics?id=1.11,1.18 +3ms
  Accessory [Node Camera] Getting value for Characteristic "Supported Video Stream Configuration" +6ms
  Accessory [Node Camera] Got Characteristic "Supported Video Stream Configuration" value: AakBAQACFQMBAAEBAAEBAQEBAgIBAAIBAQIBAgMLAQKABwICOAQDAR4DCwECQAECAvAAAwEPAwsBAgAFAgLAAwMBHgMLAQIABQIC0AIDAR4DCwECAAQCAgADAwEeAwsBAoACAgLgAQMBHgMLAQKAAgICaAEDAR4DCwEC4AECAmgBAwEeAwsBAuABAgIOAQMBHgMLAQJAAQIC8AADAR4DCwECQAECArQAAwEe +4ms
  Accessory [Node Camera] Getting value for Characteristic "Supported Video Stream Configuration" +4ms
  Accessory [Node Camera] Got Characteristic "Supported Video Stream Configuration" value: AakBAQACFQMBAAEBAAEBAQEBAgIBAAIBAQIBAgMLAQKABwICOAQDAR4DCwECQAECAvAAAwEPAwsBAgAFAgLAAwMBHgMLAQIABQIC0AIDAR4DCwECAAQCAgADAwEeAwsBAoACAgLgAQMBHgMLAQKAAgICaAEDAR4DCwEC4AECAmgBAwEeAwsBAuABAgIOAQMBHgMLAQJAAQIC8AADAR4DCwECQAECArQAAwEe +2ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /resource +18ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: POST /resource +2ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +1s
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics?id=1.20,1.18,1.19 +4s
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /characteristics?id=1.20,1.18,1.19 +2ms
  Accessory [Node Camera] Getting value for Characteristic "Supported RTP Configuration" +10ms
  Accessory [Node Camera] Got Characteristic "Supported RTP Configuration" value: AgEA +6ms
  Accessory [Node Camera] Getting value for Characteristic "Supported Video Stream Configuration" +5ms
  Accessory [Node Camera] Got Characteristic "Supported Video Stream Configuration" value: AakBAQACFQMBAAEBAAEBAQEBAgIBAAIBAQIBAgMLAQKABwICOAQDAR4DCwECQAECAvAAAwEPAwsBAgAFAgLAAwMBHgMLAQIABQIC0AIDAR4DCwECAAQCAgADAwEeAwsBAoACAgLgAQMBHgMLAQKAAgICaAEDAR4DCwEC4AECAmgBAwEeAwsBAuABAgIOAQMBHgMLAQJAAQIC8AADAR4DCwECQAECArQAAwEe +4ms
  Accessory [Node Camera] Getting value for Characteristic "Supported Audio Stream Configuration" +6ms
  Accessory [Node Camera] Got Characteristic "Supported Audio Stream Configuration" value: AQ4BAQMCCQEBAQIBAAMBAgEOAQECAgkBAQECAQADAQECAQA= +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +79ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +3ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":23,"value":"ARB7Rs3hdkBLEJlnJ3bHeBfcAxsBAQACDjE5Mi4xNjguMTc4LjM3AwKI5AQCmdYEJQIQN7oMKWwxJRoFsp3AnorThQMOVPEcDKV6PH2q+KeVWnUBAQAFJQIQmi/hjvT5tGmQemJKqyne0AMOHJUqMjpD2OCtlUmCvJIBAQA="}] +7ms
  Accessory [Node Camera] Setting Characteristic "Setup Endpoints" to value ARB7Rs3hdkBLEJlnJ3bHeBfcAxsBAQACDjE5Mi4xNjguMTc4LjM3AwKI5AQCmdYEJQIQN7oMKWwxJRoFsp3AnorThQMOVPEcDKV6PH2q+KeVWnUBAQAFJQIQmi/hjvT5tGmQemJKqyne0AMOHJUqMjpD2OCtlUmCvJIBAQA= +4ms
  StreamController 
  StreamController Session:  <Buffer 7b 46 cd e1 76 40 4b 10 99 67 27 76 c7 78 17 dc> 
ControllerAddress:  192.168.178.37 
VideoPort:  58504 
AudioPort:  54937 
Video Crypto:  0 
Video Master Key:  <Buffer 37 ba 0c 29 6c 31 25 1a 05 b2 9d c0 9e 8a d3 85> 
Video Master Salt:  <Buffer 54 f1 1c 0c a5 7a 3c 7d aa f8 a7 95 5a 75> 
Audio Crypto:  0 
Audio Master Key:  <Buffer 9a 2f e1 8e f4 f9 b4 69 90 7a 62 4a ab 29 de d0> 
Audio Master Salt:  <Buffer 1c 95 2a 32 3a 43 d8 e0 ad 95 49 82 bc 92> +20ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +95ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics?id=1.23 +26ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: GET /characteristics?id=1.23 +2ms
  Accessory [Node Camera] Getting value for Characteristic "Setup Endpoints" +6ms
  StreamController Setup Read +5ms
  Accessory [Node Camera] Got Characteristic "Setup Endpoints" value: ARB7Rs3hdkBLEJlnJ3bHeBfcAgEAAxsBAQACDjE5Mi4xNjguMTc4LjQyAwKI5AQCmdYEJQEBAAIQN7oMKWwxJRoFsp3AnorThQMOVPEcDKV6PH2q+KeVWnUFJQEBAAIQmi/hjvT5tGmQemJKqyne0AMOHJUqMjpD2OCtlUmCvJIGBAEAAAAHBAEAAAA= +8ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +7ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +101ms
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +2ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":21,"value":"ARUCAQEBEHtGzeF2QEsQmWcndsd4F9wCNAEBAAIJAQECAgECAwEAAwsBAgAFAgLQAgMBHgQXAQFjAgQ49u2yAwIrAQQEAAAAPwUCYgUDLAEBAgIMAQEBAgEAAwEBBAEeAxYBAW4CBDtrQnwDAhgABAQAAKBABgENBAEA"}] +6ms
  Accessory [Node Camera] Setting Characteristic "Selected RTP Stream Configuration" to value ARUCAQEBEHtGzeF2QEsQmWcndsd4F9wCNAEBAAIJAQECAgECAwEAAwsBAgAFAgLQAgMBHgQXAQFjAgQ49u2yAwIrAQQEAAAAPwUCYgUDLAEBAgIMAQEBAgEAAwEBBAEeAxYBAW4CBDtrQnwDAhgABAQAAKBABgENBAEA +3ms
  StreamController Write SelectedStreamConfiguration +6ms
bitrate:  299
avconv stream:  -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params N7oMKWwxJRoFsp3AnorThVTxHAylejx9qvinlVp1 srtp://192.168.178.37:58504?rtcpport=58504&localrtcpport=58504&pkt_size=1378
  EventedHTTPServer [::ffff:192.168.178.37] Sending HTTP event '1.22' with data: {"characteristics":[{"aid":1,"iid":22,"value":"AQEB"}]} +100ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +21ms
  EventedHTTPServer [::ffff:192.168.178.37] Writing pending HTTP event data +3ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP request: /characteristics +30s
  HAPServer [EC:22:3D:D3:CE:CE] HAP Request: PUT /characteristics +4ms
  Accessory [Node Camera] Processing characteristic set: [{"aid":1,"iid":21,"value":"ARUCAQABEHtGzeF2QEsQmWcndsd4F9w="}] +40ms
  Accessory [Node Camera] Setting Characteristic "Selected RTP Stream Configuration" to value ARUCAQABEHtGzeF2QEsQmWcndsd4F9w= +4ms
  StreamController Write SelectedStreamConfiguration +2ms
  EventedHTTPServer [::ffff:192.168.178.37] Sending HTTP event '1.22' with data: {"characteristics":[{"aid":1,"iid":22,"value":"AQEA"}]} +16ms
  EventedHTTPServer [::ffff:192.168.178.37] HTTP Response is finished +12ms
  EventedHTTPServer [::ffff:192.168.178.37] Writing pending HTTP event data +3ms
theopoon commented 7 years ago

Cannot see much err with it, what do you have on running it via terminal: $ avconv -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params N7oMKWwxJRoFsp3AnorThVTxHAylejx9qvinlVp1 srtp://192.168.178.37:58504?rtcpport=58504&localrtcpport=58504&pkt_size=1378

pawelrup commented 7 years ago
pi@raspberrypi:~ $ avconv -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params N7oMKWwxJRoFsp3AnorThVTxHAylejx9qvinlVp1 srtp://192.168.178.37:58504?rtcpport=58504&localrtcpport=58504&pkt_size=1378
[1] 548
[2] 549
pi@raspberrypi:~ $ ffmpeg version 3.2.5-1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1) 20170516
  configuration: --prefix=/usr --extra-version=1 --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-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --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
zrzut ekranu 2017-10-03 o 16 50 00
theopoon commented 7 years ago

that looks normal, I am out of idea then, any chance firewall settings?

pawelrup commented 7 years ago

I did not install / enable firewall. I will try with raspbian jessie instead of stretch now.

diarmuidie commented 6 years ago

I had a similar issue and it turned out that /dev/video0 wasn't present.

I was able to enable it with:

sudo rpi-update # to make sure the v4L2 drive is available.
sudo modprobe bcm2835-v4l2 # to load it and create /dev/video0

Once that was enabled the video stream worked. Hope this helps!

diarmuidie commented 6 years ago

FYI @pawelrup you have to escape the & characters in the avconv command (in the srtp URL), by adding a backslash (\) before them, when executing it directly on the command line:

pi@raspberrypi:~ $ avconv -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params N7oMKWwxJRoFsp3AnorThVTxHAylejx9qvinlVp1 srtp://192.168.178.37:58504?rtcpport=58504\&localrtcpport=58504\&pkt_size=1378

Found that out from here: https://github.com/KhaosT/homebridge-camera-ffmpeg/issues/62#issuecomment-285962457

matsekberg commented 6 years ago

I have a similar issue, runs this:

avconv stream: -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params UlLbSiTG/4jbMCXpX9CMva/LkVHBcXg9Bb3J8fJw srtp://10.0.1.16:55677?rtcpport=55677&localrtcpport=55677&pkt_size=1378

Gets "/dev/video0" not found, runs "sudo modprobe bcm2835-v4l2". Tehn it gets better but not without errors:

pi@rpicam:~/HomeKitCam $ avconv version 11.11-6:11.11-1~deb8u1+rpi1, Copyright (c) 2000-2017 the Libav developers
  built on Nov  2 2017 13:07:45 with gcc 4.9.2 (Raspbian 4.9.2-10)
[video4linux2 @ 0xc8ae40] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video0':
  Duration: N/A, start: 38779.076657, bitrate: 283115 kb/s
    Stream #0.0: Video: rawvideo, yuv420p, 1024x768, 283115 kb/s, 30 fps, 1000k tbn
Unable to find a suitable output format for 'stream:'

Any ideas?

matsekberg commented 6 years ago

But it seems to work on the Home-app :) Streaming but slow. And it seems to halt after a wile. Though it says "Live". Guess it is raspberry pi zero that is too weak to stream properly.

jonerikandersen commented 5 years ago

Yes. In your comment you need to remove "stream :"

avconv -f video4linux2 -i /dev/video0 -s 640:480 -threads auto -vcodec h264 -an -pix_fmt yuv420p -f rawvideo -tune zerolatency -vf scale=w=640:h=480 -b:v 100k -bufsize 200k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params UlLbSiTG/4jbMCXpX9CMva/LkVHBcXg9Bb3J8fJw srtp://10.0.1.16:55677?rtcpport=55677&localrtcpport=55677&pkt_size=1378

Try to post then. I have the same issue.