Has anybody got access to a H264-stream of an IP-Cam over SimpleCV?
SimpleCV has an Image
class which you can use to process image files (instead of telling it to grab an image from hardware) so your actual problem is extracting an image from the current stream.
There are a number of ways of doing this but I would probably keep this out of band (in Ubuntu, not Python) and just constantly update the same image file all the time (and loop that in Python/SimpleCV).
First you need the streaming address. There's a list of Hikvision ones here but it's going to look something like: rtsp://IPADDRESS:554/h264
We can then run avconv
(from the libav-tools
package, or ffmpeg
from any reputable PPA you can find) to capture and keep capturing once a second (based on this):
avconv -i rtsp://IPADDRESS:554/h264 -f image2 -r 1 -updatefirst 1 /path/to/img.jpg
That pulls us back around to the SimpleCV. To vastly simplify their example:
import time
from SimpleCV import *
while True:
img = Image('/path/to/img.jpg')
img.show()
time.sleep(1) #wait for 1 second
Alternatively, the camera specs claims it provides FTP access (amongst other things). Anything that will get you an image file is a viable option here.
empedokles
Updated on September 18, 2022Comments
-
empedokles over 1 year
I wonder if it's possible to get access of the H264-encoded mainstream of my Hikvision IP-cam DS-2CD2032-I over SimpleCV.
The H264-stream I got in the browser is
rtsp://192.168.1.199:554/ISAPI/streaming/channels/101?auth=YWRtaW46MTIzNDU=
SimpleCV is a python wrapper for OpenCV (a computer-vision package).
-
empedokles over 9 yearsHi. H264-stream is "rtsp://192.168.1.199:554/ISAPI/streaming/channels/101?auth=YWRtaW46MTIzNDU=" I'm not familiar with avconv or ffmpeg. I remember I had to install a libav library for Motion. Is it a deamon-process like motion saving 25 frames a second at a certain path?
-
Oli over 9 years
avconv
is a fairly powerful toolkit for converting videos. The example above will save one frame per second (you can crank it up using the-r
argument, and reduce the sleep in Python). How you keep it running is up to you. You could launch it from within your Python code or have it running all the time with Upstart (et al). -
empedokles over 9 yearsCould you add some instruction on how to install it? In your link with streams I see only FFMPEG or VLC, will avconv handle it? And how would you start the deamon-process from python?
-
Oli over 9 years
avconv
is a fork offfmpeg
and is what we ship in Ubuntu repos. It lives in thelibav-tools
package. And it's not a daemon, it's just a blocking application so you'll need to fork it out into the background with something like subprocess or it'll block your Python application. -
Oli over 9 yearsIt might be easier to bypass RTSP and look at the other protocols it provides. It sounds like FTP could give you image file access. I could spend hours enumerating the different options but (frankly) you're not paying me enough for me to write you the entire thing :)
-
empedokles over 9 yearsMaybe I should use motion then to do the job, it won't interfere with python. I'm not sure if ab FTP access could handle 25 fps, but I will ask the good guys on CCTV-forums. Thanks a lot, Oli.
-
empedokles over 9 years
-updatefirst
won't work:nuc@nuc:~$ avconv -i rtsp://192.168.1.199:554/h264 -f image2 -r 1 -updatefirst 1 /home/nuc/Bilder/test.jpg avconv version 9.16-6:9.16-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers built on Aug 10 2014 18:16:02 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1) Unrecognized option 'updatefirst'. Error splitting the argument list: Option not found