相关内容

摄像头视频流

示例

传输一个mp4流,使游览器播放:

from flask import Flask,Response
app = Flask(__name__)
def Video_stream(file):
        with open(file,'rb') as f:
                data = f.read(5120) #每次读取5120字节
                while data:
                        print len(data),'-',
                        yield data
                        data = f.read(5120)
@app.route('/')
def index():
        return Response(Video_stream('./test.mp4'),mimetype='video/mp4') #Content-Type:video/mp4
if __name__ == '__main__':
        app.run(host='0.0.0.0',port='80',debug=True)

常用流媒体标头

mp3 = "audio/mpeg"
mp4 = "video/mp4"
mp4v = "video/mp4"
mpeg = "video/mpeg"
mpg = "video/mpeg"
wav  = "audio/x-wav"
webm = "video/webm"
wma = "audio/x-ms-wma"
wmv = "video/x-ms-wmv"
wmx = "video/x-ms-wmx"

部署指南

为了适应高并发,https支持(比如gevent就不支持)等条件时,往往会加入中间件,比如Nginx,把这些流媒体交给Nginx处理,可以减轻Flask应用应用的压力,提高效率。

文章版权:若小叶 Blog - 人的一生当然要靠自我奋斗,当然也要考虑历史的行程

本文链接:https://chutian.bid/archives/51.html

转载请注明文章原始出处 !

添加新评论

返回顶部
Typecho 强力驱动. © Powered by Zhangtinghui. Theme by Postbird.