日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python如何将视频流实时传输到手机?(有问题,一次只能被一台访问)

發布時間:2025/3/20 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何将视频流实时传输到手机?(有问题,一次只能被一台访问) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • 蔣工優化后

基于python實現高速視頻傳輸程序
好像沒啥用

基于OpenCV的網絡實時視頻流傳輸

樹莓派:基于flask的遠程視頻監控

flask 放置圖片 然后瀏覽器訪問圖片的方法

AJAX - 服務器響應

# -*- coding: utf-8 -*- """ @File : app.py @Time : 2020/11/20 11:53 @Author : Dontla_stream @Email : sxana@qq.com @Software: PyCharm """ # Import necessary libraries from flask import Flask, render_template, Response import cv2 import pyrealsense2 as rs import numpy as np# Initialize the Flask app app = Flask(__name__)camera = cv2.VideoCapture('mda-kgtgu5v2zakst4s8.mp4')def gen_frames():# ctx = rs.context()# pipeline = rs.pipeline(ctx)# cfg = rs.config()# cfg.enable_device('011422071925')# cfg.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)# cfg.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)# pipeline.start(cfg)while True:# frames = pipeline.wait_for_frames()# color_frame = frames.get_color_frame()# color_image = np.asanyarray(color_frame.get_data())# if not color_frame:success, frame = camera.read() # read the camera frameif not success:breakelse:# cv2.imshow('win', color_image)# cv2.waitKey(1)# ret, buffer = cv2.imencode('.jpg', color_image)ret, buffer = cv2.imencode('.jpg', frame)frame = buffer.tobytes()yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result# 為網絡應用的默認頁面定義應用路由? @app.route('/') def index():return render_template('index.html')# 定義視頻供稿的應用路由? @app.route('/video_feed') def video_feed():return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')if __name__ == "__main__":app.run(host='0.0.0.0', port=80, debug=True)# app.run(debug=True)

host需要’0.0.0.0’,其他不行,端口可以改成其他的,沒被占用就可

<body> <div class="container"><div class="row"><div class="col-lg-8 offset-lg-2"><h3 class="mt-5">Live Streaming</h3><!-- <img src="{{ url_for('video_feed') }}" width="100%">--><video src="/static/mda-kgtgu5v2zakst4s8.mp4" controls="controls"></video></div></div> </div> </body>

本機瀏覽器打開http://127.0.0.1/(本機地址?訪問查看)

使用localhost也可以

局域網其他電腦打開服務端主機ip查看192.168.1.161查看
結果:
(以太網連接的本機)

(無線網筆記本)

蔣工優化后


app.py

from flask import Flask, render_template, Response, make_responseimport cv2 import base64 import pyrealsense2 as rs import numpy as npapp = Flask(__name__)# 測試模板 @app.route('/mb') def test_mb():return render_template('t_mb.html', sjk="jjj")@app.route('/image/<id>') def image(id):# frames = pipeline.wait_for_frames()while True:# frames = pipeline.poll_for_frames()frames = pipeline.wait_for_frames()if frames:breakelse:print('幀丟失')color_frame = frames.get_color_frame()color_image = np.asanyarray(color_frame.get_data())flag, encoded_image = cv2.imencode(".jpg", color_image)base64_str = base64.b64encode(encoded_image)return base64_str@app.route('/') def hello_world():return render_template('index.html')if __name__ == '__main__':ctx = rs.context()pipeline = rs.pipeline(ctx)cfg = rs.config()cfg.enable_device('037522250019')cfg.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)cfg.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)# print('aaaaaa')pipeline.start(cfg)app.run(host='0.0.0.0', port=5000, debug=False)

index.html

<!DOCTYPE html> <html><head><meta charset="utf-8"><title>實時視頻</title><script>function myFunction() {var xhr = new XMLHttpRequest();xhr.open('GET','/image/1',true);xhr.onload = function (e) {if (this.status == 200) {var blob = this.response;console.log(blob);var img = document.getElementById("img");// img.onload = function (e) {// window.URL.revokeObjectURL(img.src);// };// img.src = window.URL.createObjectURL(blob);// img.attr("src", "data:" + "image/jpg" + ";base64," + blob)img.src = "data:" + "image/jpg" + ";base64," + blob;// document.body.appendChild(img);}}xhr.send();// var img = document.getElementById("img");// img.src = '/image/' + parseInt(Math.random()*500000);// console.log(img.src);}var intervalId = window.setInterval(myFunction, 30);function xxx() {alert("xxx")}</script> </head><body><image id='img' src='/image/1'></image> </body></html> 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的python如何将视频流实时传输到手机?(有问题,一次只能被一台访问)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。