Multicast video in control pages

Posted on
Fri Feb 13, 2015 2:03 pm
lochnesz offline
Posts: 370
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Multicast video in control pages

It would be nice to be able to join multicast video/audio in a control page. When having many control pages running showing security cameras, the cameras are flooded with http requests getting the jpeg image. If Indigo could present the multicast stream from the cameras on the control pages, it would take much load of of the cameras, but it would require a video format like h264/mpeg4 and preferably audio too. It would be a smooth, compressed video/audio where the cameras would have the same load regardless of the number of viewers.

Posted on
Fri Feb 13, 2015 2:11 pm
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Multicast video in control pages

This doesn't specificaly answer your question but I have a script on indigo that constantly gets the images from all cameras and stores them locally. The CPs then just displays the most recent image from the ones stored on the Indigo server, that keeps the loads on the cameras to a minimum.

Terry

Posted on
Fri Feb 13, 2015 2:16 pm
lochnesz offline
Posts: 370
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: Multicast video in control pages

Sounds like a nice feature too, it would take the load of of the cameras until a multicast feature is implemented. Feel free to share your script if you'd like :-)

Posted on
Fri Feb 13, 2015 5:25 pm
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Multicast video in control pages

Sure, this is an external python script that I run at startup. It's external to Indigo and you'll need to change the URLs, names, file paths, etc. to match your situation. I dump the images into a path on the computer's web server directory ("/Library/WebServer/Documents/Cameras/Images" in my case). Then for my refreshing image URLs on the CPs I point to the appropriate image on the local web server (http://webserver/Cameras/Images/West.jpg in this example). I've got a threaded example that I can dig up if you have a lot of cameras or the updates are too slow, but this worked fine for my needs so I just use this now.

Code: Select all
import urllib
import time

while True:

   cameras= {
      
      "Front" : "http://URL/to/Camera",
      "Rear"   : "http://URL/to/Camera",
      "Pool"   : "http://URL/to/Camera",
      "East"   : "http://URL/to/Camera",
      "West"   : "http://URL/to/Camera"
   }


   for location, url in cameras.iteritems():
      resource = urllib.urlopen(url)
      output = open("Images/" + str(location) + ".jpg", "wb")
      output.write(resource.read())
      output.close()

time.sleep(5)


Posted on
Sat Feb 14, 2015 11:32 am
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Multicast video in control pages

I couldn't find my original threaded version of the script to poll multiple cameras, but below is a quick rewrite. It's essentially the same as the one above, except that each url is fetched and saved using it's own thread. The script creates a separate thread for each camera so adding cameras to the list automatically increases the number of threads used. As shown it loops every 5 seconds (the time.sleep line at the bottom) and you can adjust that value as needed but take care not to lower that number below the threshold that your slowest camera takes to return an image, otherwise the script will throw an error as a thread tries to open a file while it is already open from a previous thread for that camera. I didn't add any error checking since I just threw this together for your example, but it does work as shown. Good luck with it!

Terry

Code: Select all
import time
import urllib
import Queue
import threading

while True:

   cameras = {
      
      "Front" : "http://URL/to/Camera",
      "Rear"   : "http://URL/to/Camera",
      "Pool"   : "http://URL/to/Camera",
      "East"   : "http://URL/to/Camera",
      "West"   : "http://URL/to/Camera"
   }

   q = Queue.Queue()
   for location, url in cameras.iteritems():
      q.put((location, url),False)

   def imageGrab(q):
      qFull = True
      while qFull:
         try:
            camera = q.get(False)
            output = open("images/" + str(camera[0]) + ".jpg", "wb")
            output.write(urllib.urlopen(camera[1]).read())
            output.close()
         except Queue.Empty:
            qFull = False

   for location, url in cameras.iteritems():
       t = threading.Thread(target=imageGrab, args = (q,))
       t.start()

   time.sleep(5)

Posted on
Sat Feb 14, 2015 11:56 am
lochnesz offline
Posts: 370
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: Multicast video in control pages

Thanks! I will give it a try! :-)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests