Я пытаюсь транслировать видео поток rtsp на веб-страницу, используя Python3 и Ubuntu, однако, когда я запускаю свою программу, веб-страница иногда выглядит поврежденной, и я получаю много ошибок. Я попытался добавить '? Tcp' к URL, который не работал. Однако сам поток RTSP не поврежден, так как я могу просмотреть его в медиаплеере vl c, и он выглядит нормально.
Вывод программы:
* Serving Flask app "test" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with inotify reloader
* Debugger is active!
* Debugger PIN: ***-***-***
192.168.***.*** - - [DD/MMM/YYYY HH:MM:SS] "GET / HTTP/1.1" 200 -
192.168.***.*** - - [DD/MMM/YYYY HH:MM:SS] "GET /video_feed HTTP/1.1" 200 -
[h264 @ 0x1d0c680] Invalid level prefix
[h264 @ 0x1d0c680] error while decoding MB 15 36
[h264 @ 0x1cc3d00] negative number of zero coeffs at 17 25
[h264 @ 0x1cc3d00] error while decoding MB 17 25
[h264 @ 0x1d0c680] corrupted macroblock 2 42 (total_coeff=-1)
[h264 @ 0x1d0c680] error while decoding MB 2 42
[h264 @ 0x1d0c680] corrupted macroblock 20 36 (total_coeff=-1)
[h264 @ 0x1d0c680] error while decoding MB 20 36
[h264 @ 0x1d0c680] Invalid level prefix
[h264 @ 0x1d0c680] error while decoding MB 28 42
Invalid UE golomb code
[h264 @ 0x1cc3d00] cbp too large (3199971767) at 16 43
[h264 @ 0x1cc3d00] error while decoding MB 16 43
[rtsp @ 0x1c53c80] Too short data for FU-A H.264 RTP packet
[h264 @ 0x1cc3d00] corrupted macroblock 17 41 (total_coeff=-1)
[h264 @ 0x1cc3d00] error while decoding MB 17 41
[h264 @ 0x1d0c680] corrupted macroblock 21 36 (total_coeff=-1)
[h264 @ 0x1d0c680] error while decoding MB 21 36
Моя программа (Python3)
#!/usr/bin/env python
from flask import Flask, render_template, Response
import io
import cv2
import os
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
app = Flask(__name__)
vc = cv2.VideoCapture("rtsp://192.168.1.14/onvif1")
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
def gen():
"""Video streaming generator function."""
while True:
read_return_code, frame = vc.read()
encode_return_code, image_buffer = cv2.imencode('.jpg', frame)
io_buf = io.BytesIO(image_buffer)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + io_buf.read() + b'\r\n')
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(
gen(),
mimetype='multipart/x-mixed-replace; boundary=frame'
)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, threaded=True)