22-1 web传输视频 Opencv+usb摄像头 树莓派+Flask实现视频流媒体WEB服务器

实用

https://blog.csdn.net/u012675539/article/details/53306335

第一篇 讲解原理

https://blog.miguelgrinberg.com/post/video-streaming-with-flask

第二篇 加入多线程可以直接用

https://github.com/xitu/gold-miner/blob/master/TODO1/flask-video-streaming-revisited.md

https://zhuanlan.zhihu.com/p/54292646

链接:https://pan.baidu.com/s/16iyO_XR_JhhHn184RVH6Hw
提取码:6dq6

http://shumeipai.nxez.com/2018/07/17/raspberry-pi-cam-pan-tilt-control-over-local-inter.html

树莓派+Flask实现视频流媒体WEB服务器

 http://shumeipai.nxez.com/2018/07/03/video-streaming-web-server-with-flask.html

1最简单的模式

opencv

单线程

 

# main.py
from flask import Flask, render_template, Response
from camera import VideoCamera

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

def gen(camera):
    while True:
        frame = camera.get_frame()
        yield (b'--frame
'
               b'Content-Type: image/jpeg

' + frame + b'

')

@app.route('/video_feed')
def video_feed():
    return Response(gen(VideoCamera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)

  

# camera.py
import cv2

class VideoCamera(object):
    def __init__(self):
        # Using OpenCV to capture from device 0. If you have trouble capturing
        # from a webcam, comment the line below out and use a video file
        # instead.
        self.video = cv2.VideoCapture(0)
        # If you decide to use video.mp4, you must have this file in the folder
        # as the main.py.
        # self.video = cv2.VideoCapture('video.mp4')

    def __del__(self):
        self.video.release()

    def get_frame(self):
        success, image = self.video.read()
        # We are using Motion JPEG, but OpenCV defaults to capture raw images,
        # so we must encode it into JPEG in order to correctly display the
        # video stream.
        ret, jpeg = cv2.imencode('.jpg', image)
        # 对于 python2.7 或者低版本的 numpy 请使用 jpeg.tostring()
        return jpeg.tobytes()

  

<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
    <h1>Video Streaming Demonstration</h1>
    <img src="{{ url_for('video_feed') }}">
  </body>
</html>

  

简单几步实现RTMP直播

 https://blog.csdn.net/steveyg/article/details/86488706?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

原文地址:https://www.cnblogs.com/kekeoutlook/p/11271910.html