|
|
488
|
+ '''
|
|
|
489
|
+ cameras = ['rtsp://username:password@ip_address:554/user=username_password='password'_channel=channel_number_stream=0.sdp',
|
|
|
490
|
+ 'rtsp://username:password@ip_address:554/user=username_password='password'_channel=channel_number_stream=0.sdp']
|
|
|
491
|
+ '''
|
|
|
492
|
+ cameras = ['rtsp://admin:@Unv123456@192.168.10.252:554/unicast/c1/s1/live']
|
|
|
493
|
+ return cameras[int(id)]
|
|
|
494
|
+# for cctv camera use rtsp://username:password@ip_address:554/user=username_password='password'_channel=channel_number_stream=0.sdp' instead of camera
|
|
|
495
|
+# for webcam use zero(0)
|
|
|
496
|
+
|
|
|
497
|
+
|
|
|
498
|
+def gen_frames(camera_id):
|
|
|
499
|
+
|
|
|
500
|
+ cam = find_camera(camera_id)
|
|
|
501
|
+ cap= cv2.VideoCapture(cam)
|
|
|
502
|
+
|
|
|
503
|
+ while True:
|
|
|
504
|
+ # for cap in caps:
|
|
|
505
|
+ # # Capture frame-by-frame
|
|
|
506
|
+ success, frame = cap.read() # read the camera frame
|
|
|
507
|
+ if not success:
|
|
|
508
|
+ break
|
|
|
509
|
+ else:
|
|
|
510
|
+ ret, buffer = cv2.imencode('.jpg', frame)
|
|
|
511
|
+ frame = buffer.tobytes()
|
|
|
512
|
+ yield (b'--frame\r\n'
|
|
|
513
|
+ b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
|
|
|
514
|
+@app.route('/video_feed/<string:id>/', methods=["GET"])
|
|
|
515
|
+def video_feed(id):
|
|
|
516
|
+
|
|
|
517
|
+ """Video streaming route. Put this in the src attribute of an img tag."""
|
|
|
518
|
+ '''
|
|
|
519
|
+ return Response(gen_frames(id),
|
|
|
520
|
+ mimetype='multipart/x-mixed-replace; boundary=frame')
|
|
|
521
|
+ '''
|
|
|
522
|
+ return Response(process_video(),
|
|
|
523
|
+ mimetype='multipart/x-mixed-replace; boundary=frame')
|
|
|
524
|
+
|
|
|
525
|
+@app.route('/', methods=["GET"])
|
|
|
526
|
+def index():
|
|
|
527
|
+ return render_template('index.html')
|
|
|
528
|
+
|
|
|
529
|
+
|
|
|
530
|
+if __name__ == '__main__':
|
|
|
531
|
+ app.run(debug=True, port=9099)
|