rxseger / homebridge-camera-motion

Motion detector camera plugin for Homebridge
MIT License
48 stars 9 forks source link

Fix video streaming based on homebridge-camera-ffmpeg #7

Closed Minims closed 6 years ago

Minims commented 7 years ago

Fix video streaming based on homebridge-camera-ffmpeg Update Readme. It works for me.

sascha-seyfert commented 7 years ago

You need to change the packages.json for ip requirements.

Minims commented 7 years ago

update done :-)

cbarratt commented 7 years ago

I've been trying to test this and can't seem to get it working. It's somehow started to manage to show old "snapshots" on the camera, but attempting to start a video stream times out. I can see it launching the ffmpeg command in the console.

I'm not sure if it's just me but, this plugin seems to block all the other requests to other accessories on homebridge. Maybe because it's slow on an old Model B

Minims commented 7 years ago

I'm using homeassistant-homebrige with homebridge-camera-motion on my side and both are working together. I'm on a RPi2. Do you use a basic auth on your motion stream ?

cbarratt commented 7 years ago

I did originally but I've recently reinstalled motion and set it up from fresh and i'm no longer using basic auth. When i did i provided the URL as http://user:pass@1....

I'm on a Model B with 128/128 GPU/MEM split, using motion-mmal.

Heres both my motion.conf and the syslog showing the homebridge console.logs while it tries to launch ffmpeg

https://gist.github.com/cbarratt/13f08e36c79d45625132c7ba0db587a7

in the syslog you can see that it looks like it times out maybe and logs:

Apr  7 09:44:36 DietPi homebridge[8836]: received handleStreamRequest { sessionID: <Buffer f5 08 88 f7 05 30 4b 42 ba 95 32 a0 ba 33 f9 42>,
Apr  7 09:44:36 DietPi homebridge[8836]: type: 'stop' }
Minims commented 7 years ago

It's quite strange, are you using the versoin i pushed ? I've got the behaviour when i run the master branch.

Minims commented 7 years ago

I saw you've answered to an issue on the master branch about "notification with picture". It works too for me.

To install my branch : npm install -g Minims/homebridge-camera-motion#fix/streaming To revert : npm install homebridge-camera-motion

About permissions, look at https://github.com/rxseger/homebridge-camera-motion/issues/4

cbarratt commented 7 years ago

I've recently just redone my setup and I'm about to test it again later today. I've now got a rPi 3 and I'm not using MotionEye which is running smoothly. I'm just looking into configuring it to write to the fifo pipe and then should be on my way fingers crossed!

cbarratt commented 7 years ago

@Minims - I seem to have got it working, though it sometimes fails to launch FFMPEG by the looks of it, and then the process times out. I do now also get notifications from Home app, but I find it seems to only give me them when I'm at home on Wifi (I have my ATV4 as my homehub, streaming the camera seems to work)

EDIT: I've just found this and I wonder if it's worth a try! https://www.reddit.com/r/raspberry_pi/comments/5677qw/hardware_accelerated_x264_encoding_with_ffmpeg/

mecrip commented 7 years ago

I'm having the same issue as @cbarratt

Aug 26 16:39:59 myberry homebridge[18197]: received handleStreamRequest { sessionID: <Buffer 1f 4f af a2 48 27 4d 4e 8b 74 8b cd 8a 9d a5 4b>,
Aug 26 16:39:59 myberry homebridge[18197]: type: 'stop' }

basically it seems that it never receive a 'start' request..

any idea?

rxseger commented 6 years ago

Sorry everyone for the trouble with this plugin, unfortunately I've stopped using it since the I was using camera stopped working (the Raspberry Pi camera module, apparently it is very sensitive to static electricity) so I won't be able to easily test any changes or continue developing it... @Minims I've invited you as a collaborator to this repository if you want to pick it up

ayman commented 6 years ago

Trying to get this going too using @Minims pull. Is there an example config on how to set the ffmpeg vars? (also happy to pick up the repo assuming I can get it working).

Minims commented 6 years ago

Hello,

Here is my configuration for the camera, hope that helps :

"platforms": [ { "platform": "CameraMotion", "name": "Camera", "name_motion": "Living Motion Detector", "motion_pipe": "/tmp/motion-pipe", "motion_timeout": 2000, "snapshot_path": "/home/pi/WebCam/lastsnap.jpg", "ffmpeg_path": "/usr/local/bin/ffmpeg", "ffmpeg_source": "-re -i http://192.168.1.10:8081/" },

Minims commented 6 years ago

I've add the fifo script in order to fix fifo on motion detection. Look at my README File Tell me if it's Ok with my Branch and I will merge my PR.

To install my branch : npm install -g Minims/homebridge-camera-motion#fix/streaming To revert : npm install homebridge-camera-motion

ayman commented 6 years ago

So I got nothing. I pulled your branch. Made the fifo edit (and ran it manually). Matched the config.

    {
        "platform": "CameraMotion",
        "name": "Camera",
        "name_motion": "Motion Sensor",
        "motion_pipe": "/tmp/motion-pipe",
        "motion_timeout": 2000,
        "snapshot_path": "/home/pi/security/lastsnap.jpg",
        "ffmpeg_path": "/usr/local/bin/ffmpeg",
        "ffmpeg_source": "-re -i http://10.0.1.111:8081/"
    }

I'm on a PiZero, npm v4.6.1 and I've compiled ffmpeg on it following @cbarratt's url.

$ ffmpeg -encoders | grep 264
ffmpeg version git-2017-11-12-a38b14a Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1) 20170516
  configuration: --enable-gpl --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi
  libavutil      56.  0.100 / 56.  0.100
  libavcodec     58.  3.100 / 58.  3.100
  libavformat    58.  2.100 / 58.  2.100
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  0.101 /  7.  0.101
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V..... h264_vaapi           H.264/AVC (VAAPI) (codec h264)

Stream looks empty (picture broken)

img_1bd864aebaaf-1

Clicking on it gives a blank screen and this output:

currentAddress 10.0.1.111
addressResp { address: '10.0.1.111' }
received handleStreamRequest { sessionID: <Buffer a4 5c 16 c0 37 19 4e 15 a5 89 4b e3 88 48 70 ee>,
  type: 'start',
  video:
   { profile: 2,
     level: 2,
     width: 1280,
     height: 720,
     fps: 30,
     ssrc: 3027839570,
     pt: 99,
     max_bit_rate: 299,
     rtcp_interval: 1056964608,
     mtu: 1378 },
  audio:
   { codec: 'AAC-eld',
     channel: 1,
     bit_rate: 0,
     sample_rate: 16,
     packet_time: 30,
     pt: 110,
     ssrc: 284038824,
     max_bit_rate: 24,
     rtcp_interval: 1084227584,
     comfort_pt: 13 } }
starting { address: '10.0.1.103',
  video_port: 52024,
  video_srtp: <Buffer fc dd 8c 4b 08 f0 24 ad 28 ac 89 d4 59 93 22 a0 8f a4 70 c2 7f 90 2c 4a 07 d8 de c7 2a 00>,
  video_ssrc: 1,
  audio_port: 51449,
  audio_srtp: <Buffer d5 42 b8 51 d4 b6 14 40 c0 95 e5 ed 60 67 6d 69 f4 4a c8 17 2a a3 9d b2 70 36 23 33 60 ba>,
  audio_ssrc: 1 }
about to spawn ffmpeg
-re -i http://10.0.1.111:8081/ -threads 0 -vcodec libx264 -an -pix_fmt yuv420p -r 30 -f rawvideo -tune zerolatency -vf scale=1280:720 -b:v 299k -bufsize 299k -payload_type 99 -ssrc 1 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params /N2MSwjwJK0orInUWZMioI+kcMJ/kCxKB9jexyoA srtp://10.0.1.103:52024?rtcpport=52024&localrtcpport=52024&pkt_size=1378

Then finally: img_729ea0ca3fa1-1

received handleStreamRequest { sessionID: <Buffer 58 86 8d 20 a2 26 4f 29 b6 22 43 9d 19 96 76 15>,
  type: 'stop' }

I should note I get motion notifications (without images), http://10.0.1.111:8081/ shows me live video, and no file ever shows up at /home/pi/security/lastsnap.jpg.

I'll dig in further but if something pops out as wrong, let me know.

ayman commented 6 years ago

Update

Two issues both with the ffmpeg command.

  1. My version doesn't know the -tune argument (its a pram for libx264 afaik. So I removed it.
  2. I changed the codec to h264_omx because ffmpeg didn't know libx264.

Now, after the spawn I get:

received handleStreamRequest { sessionID: <Buffer 8e 2c 4e 5f 39 29 4e 59 a6 7d 37 28 ee 32 e1 ef>,
  type: 'reconfigure',
  video:
   { width: 640,
     height: 360,
     fps: 30,
     max_bit_rate: 132,
     rtcp_interval: 0 } }

And a live stream! img_8650901efc1c-1

So, I wonder about the various versions/variants of ffmpeg and perhaps we should make a custom arg in the module conf.

Maybe add a codec-options to the config to insert your default of -vcodec libx264 -tune zerolatency but would give others to set it accordingly. Along the way i fixed the snapshot + photo notification in #10.

ayman commented 6 years ago

I have a local version with new config args that adds ffmpeg_args to fix the codec issue and adds ffmpeg_debug so the spawned process can be monitored and debugged (which really removes the mystery when a problem occurs). I'm not sure how to fold it in here, but if the README.md can be resolved and this merged I can issue a second PR for it.

slcc2c commented 6 years ago

@Minims can you commit this?

Minims commented 6 years ago

@slcc2c PR merged :-)