def generate_frames(rtsp_url):
cap = cv2.VideoCapture(rtsp_url)
while True:
success, frame = cap.read()
if not success:
break
ret, buffer = cv2.imencode('.mp4', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: video/mp4\r\n\r\n' + frame + b'\r\n')
#стрим jpeg-ов по запросу
def video_feed(request):
rtsp_url = request.GET.get('rtspurl', None)
if rtsp_url:
print(request.method)
return StreamingHttpResponse(generate_frames(rtsp_url), content_type='multipart/x-mixed-replace; boundary=frame')
else:
return HttpResponse("RTSP URL не предоставлен", status=400)