3

code in which cameafeedview is defined in the url section please help where i am wrong .Tired this code also but no help Opencv Live Stream from camera in Django Webpage

    def camerafeedView(request):
        return render(request,'camerafeed.html')

    def gen(camera):
        video = cv2.VideoCapture()
        video.open("rtsp://user:pass@IP")
        video.release()
        ret,image =  self.video.read()
        ret,jpeg = cv2.imencode('.jpg',image)
        while True:
            frame = jpeg.tobytes()
            yield(b'--frame\r\n'
            b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')

        def camerafeed(request): 
            return StreamingHttpResponse(gen(),content_type="multipart/x-mixed-replace;boundary=frame")

Template code:

   <html>
       <head>
           <title>Video Streaming Demonstration</title>
           <h1>test</h1>
       </head>
       <body>
           <h1>Video Streaming Demonstration</h1>
           <img src="{% url 'camerafeed' % }}">
       </body>
   </html>

it show only html page but no live camaera feed ..please help where i am wrong here

Milad Hatami
  • 1,494
  • 13
  • 18
nikole martin
  • 31
  • 1
  • 2

1 Answers1

0

The issue might be with you using the RTSP stream. As per my research RTSP streams isn't playable directly in the browser you have to convert it first to play in the browser supported format. For more information you can check the following link.

Aniket Maithani
  • 845
  • 1
  • 10
  • 24