Answer the question
In order to leave comments, you need to log in
How to display the received camera in html page?
Hello. I need to display a stream on a page. Here is the code:
views.py:
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture('rtsp://x.x.x.x:554/user=x&password=x&channel=1&stream=0.sdp?real_stream--rtp-caching=100')
(self.grabbed, self.frame) = self.video.read()
threading.Thread(target=self.update, args=()).start()
def __del__(self):
self.video.release()
def get_frame(self):
image = self.frame
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
def update(self):
while True:
(self.grabbed, self.frame) = self.video.read()
cam = VideoCamera()
def gen(camera):
while True:
frame = cam.get_frame()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
def livefe(request):
try:
return StreamingHttpResponse(gen(VideoCamera()), content_type="multipart/x-mixed-replace;boundary=frame")
except: # This is bad! replace it with proper handling
pass
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question