首页 > 解决方案 > 捕获视频流烧瓶

问题描述

我从覆盆子相机创建了一个简单的实时视频流。看起来像这样


服务器.py

from flask import Flask
from flask import render_template
from flask import Response

import cv2

app = Flask(__name__)

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

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

def gen():
    camera = cv2.VideoCapture(0)

    while True:
        ret, img = camera.read()

        if ret:
            frame = cv2.imencode('.jpg', img)[1].tobytes()
            yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
        else:
            break

app.run(host='192.168.0.241', port=7070, debug=True)


索引.html

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


一切正常,我http://<raspberry_ip>:<port>在浏览器中输入,我可以看到视频。


现在我需要创建用于观看此视频的移动应用程序,但是我正在努力做到这一点。有没有办法在 iOS 应用程序中捕获视频流?

标签: pythonswiftflaskraspberry-pivideo-streaming

解决方案


您的视频正在播放

http://<raspberry_ip>:<port>/video_feed

推荐阅读