Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webcam stream (as option) #223

Closed
Swiftnesses opened this issue Dec 4, 2018 · 82 comments
Closed

Webcam stream (as option) #223

Swiftnesses opened this issue Dec 4, 2018 · 82 comments

Comments

@Swiftnesses
Copy link

Hey @theyosh,

Loving this controller, mega work my friend - thank you.

I'm currently using MJPG Streamer (available here on Github) to stream my Duck COOP webcam, rather than use static images. On my Pi 3 (A+ with only 512MB RAM), I can stream and use the controller while only using around 15% CPU (which is amazing tbh!). I doubt this is even an effective method of streaming - likely modern browsers support much better alternatives (H264/265?).

I'd love to have the stream inside Terrarium Pi rather than running via another application. Could you please add streaming as an option, given the low CPU utilisation, it seems a real possibility which would hugely improve the options available to people wanting live updates (I need them, as there's a small chance a Duck could get caught in the door, sure this applies to reptiles too?).

Many thanks,

Mark

@Swiftnesses
Copy link
Author

Seems like UV4L offers amazing streaming with low CPU usage and Pi cameras 👍

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

The low cpu is due to low quality streaming. Both is motion JPEG And that is only supported in Firefox and Chrome. I think Safari can't handle it. So on iPhone it does not work well.. Also, the bitrate will be very high, and works well on a LAN. But going over the internet, you need a rather steady and fast upload speed.

So there is H264 and H265. H265 is not mature enough, so that is out of the picture. H264 is currently industry standard. But converting a stream to H264 cost a lot of CPU power. The Pi is able to do it... but will eat all CPU cores. So that is not an option.

I found a solution to use the Pi GPU for H264 encoding. You can mannully compile FFMPEG with --enable-mmal --enable-omx --enable-omx-rpi and then you can use the hardware encoder of the Pi. Which works pretty well. I have a Wifi webcam in a (birdhouse)[https://vogelhuisje.theyosh.nl/]. It is producing a multibitrate HLS stream. This takes about 1 CPU due to ffmpeg keyframe alignment and creating HLS chunks. But compiling ffmpeg takes about 1.5 hours. So not an option for normal users.

So it is a bit more complicated. And I do know, as my job is video transcoding and streaming for a company. So I have more then 10+ years experience in video encoding.

So, it is not that easy. Also both uv4l and mjpeg streamer have there own webserver and different ports that also needs to be forwarded.

And currently, I tile the webcam images for zooming like Google Maps. That is not possible with a live stream. And therefore the webcam controls should be changed...

What I can support is this: https://medium.com/@jaredtoddpetersen/home-security-live-streaming-with-raspberry-pi-f9293efca7ba

This will produce the same type of stream as my birdhouse. And that can be added as a webcam so that you have a livestream in my interface. But this will also need some more linux experience in compiling the software you selfs.

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

Ah, all browsers support motion jpeg now a days

@Swiftnesses
Copy link
Author

Thanks for the explanations, really helps me understand. Keeping it light, with as little extra bloat as possible would be the best solution, I'm streaming now at 1296x972 @ 30FPS in H264 on my Pi 3 and it's not using much CPU at all...

I'm not bad with Linux, but it would be awesome to have an option built in to activate streaming... the last link you posted sounds interested, fairly lightweight and compatible...

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

How are you currently watching? Using vlc? Or using the WebRTC option?

@Swiftnesses
Copy link
Author

Right now I'm using http://raspberrypi:8080/stream/video.h264

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

that does not work in a browser right? That is playing in VLC?

@Swiftnesses
Copy link
Author

Works in a browser ;-)

I'm using UV4L...

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

Ok... cool... but I think I will try another way. I am currently compiling ffmpeg manually with the right codecs. And will test if that will produce HLS. That can be added to my software then...

But this will take some time to develop. And it will involve some manual work ;)

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

And with an usb audio device and a mic you should be able to hear them also!

@Swiftnesses
Copy link
Author

Hearing them would be very cool :-)

I'd like to add another camera in addition to the Pi V1 camera I use, any suggestions?

@theyosh
Copy link
Owner

theyosh commented Dec 4, 2018

Following: https://github.com/jaredpetersen/raspi-live#ffmpeg (so, manually compile ffmpeg)

created a ffmpeg with HLs support and H264 hardware. Now testing full Hd from the rpi cam to hls. cpu load 1% of 1 core :) This looks promising..

running:

raspivid -b 1000000 -o - -t 0 -w 1920 -h 1080 -fps 30 -g 30 | ./ffmpeg -nostdin -re -i - -vcodec copy -f hls -hls_time 1 -hls_list_size 3 -hls_delete_threshold 5 -hls_flags split_by_time+delete_segments+second_level_segment_index -strftime 1 -hls_segment_filename '/home/pi/TerrariumPI/static/hls/file%s-%%d.ts' /home/pi/TerrariumPI/static/hls/stream.m3u8

watch url: http://pi:8080/static/hls/stream.m3u8 (vlc or safari/iphone) Will add a hls player to the webcam part. This has only a 3 seconds delay :D

@Swiftnesses
Copy link
Author

Nice! 👍

@Swiftnesses
Copy link
Author

How did you get on, I'd like to try your stream method and check out utilisation....

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

Ok, turns out... it is pretty easy to have a live stream now... Here we go!

And that should give you a live webcam in the webcam sections. It is currently missing all zoom controls. Also archiving and rotation is not yet working.

And it is still alpha. But I got it working with 1.0% CPU usage :)

@Swiftnesses
Copy link
Author

Testing now... :)

@Swiftnesses
Copy link
Author

Swiftnesses commented Dec 5, 2018

Okay, got the live stream... 2 issues I can see here:

  1. My ducks are sideways, which looks uncomfortable (they need rotating!) :-)
  2. I normally use 1296x972 on my V1 camera (Full FOV and fast FPS) - https://picamera.readthedocs.io/en/release-1.12/fov.html

For some reason changing the resolution has no effect, currently it's cropped their heads off...

Thanks for getting this working though, superb!

Edit: noticed you said rotation wasn't working yet, whoops.

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

Yeah, that should be possible. But somehow my camera just stopped working ... :( And it is getting late here.. so tomorrow is another day.

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

Ok, found the issue... it is getting late so stupid errors...
Anyway, resolutions and rotations should work now

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

Only the FPS is currently locked at 30 fps....

@Swiftnesses
Copy link
Author

At this rate, my ducks will be getting more sleep than us :-)

I'll give it a test now and report back, get some sleep! :-)

@Swiftnesses
Copy link
Author

To confirm, do I just do a pull, and then restart?

@Swiftnesses
Copy link
Author

Hmmm, not working here, it now only plays for 5 seconds when I go to webcam (seems to be the same clip), no rotation or resolution change either?

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

Just wait... do a new pull now. Just made an error..
and yesh. Do a git pull and restart.... that should do it

@Swiftnesses
Copy link
Author

Did a pull, rotation / resolution still not playing here dude - sorry :-(

@theyosh
Copy link
Owner

theyosh commented Dec 5, 2018

hmmm... crap.. I have it working at the moment. Sorry for now... tomorrow I will try again

@Swiftnesses
Copy link
Author

Hang on, one final cache clear and reboot of the app, and it's working! Good work.

@Swiftnesses
Copy link
Author

@theyosh I'm on it... wish me luck ;-)

@Swiftnesses
Copy link
Author

Swiftnesses commented Dec 17, 2018

@theyosh Up and running will configure now and test (btw you have some default wemo plugs in switches), any idea when you'll try and take a first shot at HLS?

EDIT: They are my Wemo's, I'm dumb. Can I avoid them being added?

@theyosh
Copy link
Owner

theyosh commented Dec 17, 2018

@Swiftnesses HLS is already working... maybe clear browser cache?

@theyosh
Copy link
Owner

theyosh commented Dec 17, 2018

Else just add the full HLS url as source for the webcam. Other settings like resolution will be ignored

@Swiftnesses
Copy link
Author

Swiftnesses commented Dec 17, 2018

No luck with HLS, even tried this test stream:

http://www.streambox.fr/playlists/test_001/stream.m3u8

The error is HLS:4

Edit: restarted and it's working, super!

@Swiftnesses
Copy link
Author

Swiftnesses commented Dec 17, 2018

It seems to stop after some time with errors like:

2018-12-17 19:50:47,451 - WARNING - terrariumEngine - Webcam update(s) took to much time. Needed 38.20912 seconds which is 8.20912 more then the limit 30

The link above is a good test...

Edit: Holy s*** the archive has taken 32GB, couldn't even restart the app, connected via SSH and wiped the webcam folders on both my stable and dev release!

@Swiftnesses
Copy link
Author

Swiftnesses commented Dec 17, 2018

Streaming seems to fill the SD card ultra fast, even with archive etc off the webcam folder fills FAST...

Also seems to save about 8 seconds of the stream and then stop, retrying just plays the same clip over and over again...

@Swiftnesses
Copy link
Author

I guess you're using clappr, I tried adding a RTSP link of one of my Ubiquiti cameras for fun hoping it also worked, locked out, luckily I wiped it from the settings.cfg and it allowed me back in :-D

@theyosh
Copy link
Owner

theyosh commented Dec 17, 2018

It is not made to stream multibitrate FULLHD TV channels. Use proper source like a webcam at 1Mpbs.

Without actually errors, I can't help... so development branch is at own risk...

@theyosh
Copy link
Owner

theyosh commented Dec 17, 2018

RTSP is NOT supported

@Swiftnesses
Copy link
Author

Come on, who doesn't want to watch Full HD movies while watching our pets? 👍

Joking aside, it seems to be working okay, the only issue is the flakey feed from the camera I put inside the duck coop, will need to rethink the placement.

@theyosh
Copy link
Owner

theyosh commented Dec 19, 2018

@Swiftnesses Is the new development version working well for you? If so, we are close to a new release.

@Swiftnesses
Copy link
Author

Hey @theyosh... development branch seems to be working for me, setup and working fine (or at least as far as I can see!).

@Swiftnesses
Copy link
Author

BTW, I'm using the websockets to update my smart home and trigger actions - it's now all fully automated!

@Swiftnesses
Copy link
Author

As a note, it would be nice long term if you can add some webcam controls, I struggle a little with contrast during the night, manually adjusting this offers improvements but it would be good from the UI. I use DRC and adjust the white balance normally...

@Swiftnesses
Copy link
Author

@theyosh the only bug I found is trying to save a RAW photo and view it gives me a 404.

theyosh added a commit that referenced this issue Dec 19, 2018
@ghost
Copy link

ghost commented Dec 27, 2018

BTW, I'm using the websockets to update my smart home and trigger actions - it's now all fully automated!

Would you be willing to explain to me how you set up web sockets? I am so lost.

@theyosh
Copy link
Owner

theyosh commented Dec 28, 2018

Euh, I would like to close this issue. So maybe you should exchange email addresses somehow? So you can discuss the websockets option?

@theyosh
Copy link
Owner

theyosh commented Jan 8, 2019

For now, I am closing this issue, as live streaming is now possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants