Created
May 24, 2017 07:32
-
-
Save benaisc/b89a8e6f1b3e74218ba8ceeb3240a508 to your computer and use it in GitHub Desktop.
python opencv mpeg streamer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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