Skip to content

Instantly share code, notes, and snippets.

@benaisc
Created May 24, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaisc/b89a8e6f1b3e74218ba8ceeb3240a508 to your computer and use it in GitHub Desktop.
Save benaisc/b89a8e6f1b3e74218ba8ceeb3240a508 to your computer and use it in GitHub Desktop.
python opencv mpeg streamer
#!/bin/python
#coding : utf-8
import sys, os
import numpy as np
import urllib
import cv2
from datetime import datetime
streamURL = 'http://72.240.51.213/mjpg/video.mjpg'
# Simple printer of a video-stream
def affiche_stream(url):
stream=urllib.urlopen(url)
bytes=''
while True:
bytes += stream.read(1024)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes = bytes[b+2:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
cv2.imshow('Stream',i)
if cv2.waitKey(1)==27:
exit(0)
# i.e :
affiche_stream(streamURL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment