[Solved] Feature Request - IP Camera/Network Camera Stream
Wondering if it would be possible to add a network stream/IP camera to the cameras page?
I'm thinking of using mycodo as the frontend/backend of a home thermostat and I thought it would be nice to be able to switch to a camera stream (maybe door camera) through the flask web page. In terms of extensibility, IP camera streams would none-the-less be a great addition to the whole package (versus a local camera capture).
I like the idea, but I have no experience with this. Are you familiar with any methods or libraries to do this? Do you have an IP camera to test with?
I do have a few IP cameras to test with; however, I don't have any experience on implementing this in a browser.
The protocol that IP cams use to stream their input is called RTSP, but after some googling, it looks like that stream needs to be re-encoded into another video format in order to display it in a browser. The simplest application that comes up is using ffmpeg, but I don't think a pi has adequate processing power to perform the conversion locally without severely limiting resources available for other processes.
How does the current Pi Camera implementation work in mycodo? Is it refreshing frame captures or something?
The current implementation of the camera streaming code basically pulls images from the cam and serves them to the browser (see https://github.com/kizniche/Mycodo/tree/ab369c4e03ff81a83896a421b9cd64dfebc8261a/mycodo/mycodo_flask/camera) using picamera for the Raspberry Pi cameras and opencv for USB cameras. Since I don't have an IP Camera to experiment with, I can't really develop any code reliably myself. If you can find any resources demonstrating how to pull images/streams from IP cameras and serve them to a web browser, or through a Python library ( https://pypi.org/) I could potentially write some code that you could test. If you tell me your IP Cam makes/models, I might be able to do some research as well.
Kyle, I can get you the IP Cam model info, but IP cameras that comply with ONVIF standard have a still image (JPEG, MJPEG, etc) that can be accessed via an HTTP link. This website http://www.crazypixels.com/support has a list of the format for some common ones... but basically it's usually a local ip address based HTTP link, and usually with credentials in the form of the USER:PASS@ prefix, similar to FTP.
I think if you just add the ability to do an HTTP GET request for a JPG, that would work.
Here's a flask implementation of using the still image stream: https://blog.miguelgrinberg.com/post/video-streaming-with-flask
As a proof of concept, I added a new camera, HTTP Address, which pulls an image from an HTTP/HTTPS address and treats it as an image capture for still or time-lapse use in Mycodo. I've disabled streaming with this module, as that functionality doesn't exist, but I think this is a good base to expand into streaming using a URL, which can be a local webcam or any other remote image (such as the current weather radar image in the screenshots, below).
Works with current dashboard widget.
Awesome! Let me test this out with my ip can setup and I'll report back with some findings.
Really appreciate the implementation!
I will give a test with a few ONVIF I have. Have a couple models sitting around in the garage spare.
Bit strange of an issue I have. One of the camera models I have produces an xml page that displays the JPG. The link looks like http://user:pass@ip/stream/channel1/image and therefore doesn't have an extension on the link. I think this is tripping up opencv
Can you access it via RTSP, with an address such as rtsp://username:email@example.com/1?
@kylegabriel Yes. RTSP streaming works beautifully with the cameras through the new feature.
Still trying to work through the still imaging.
Opencv is only used for the stream URL. urllib.request.urlretrieve is used for still URL. If you have the ability to make your IP cam publically accessible so I can test, I should be able to get it working.