revert(video): back to simple send_file for video serving (RPi3 can't transcode)
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from flask import Flask, render_template, make_response, json, jsonify, request, send_file, Response
|
from flask import Flask, render_template, make_response, json, jsonify, request, send_file, Response
|
||||||
from modules import app_gps, app_events, app_car, app_account, app_gps,app_obd, app_sql, app_dash, app_upload, app_video, app_health, app_alerts, app_settings, app_network
|
from modules import app_gps, app_events, app_car, app_account, app_gps,app_obd, app_sql, app_dash, app_upload, app_video, app_health, app_alerts, app_settings, app_network
|
||||||
import os, time, subprocess
|
import os, time
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
|
|
||||||
|
|
||||||
@@ -149,33 +149,7 @@ def local_video_file():
|
|||||||
return jsonify(error=str(error)), 400
|
return jsonify(error=str(error)), 400
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return jsonify(error=f"Local video not found: {relative_path}"), 404
|
return jsonify(error=f"Local video not found: {relative_path}"), 404
|
||||||
|
return send_file(path, conditional=True, as_attachment=False)
|
||||||
# Stream via ffmpeg: copy video, transcode audio to AAC (PCM not supported
|
|
||||||
# in MP4), output as fragmented MP4 so browser plays without full download.
|
|
||||||
def generate_stream():
|
|
||||||
cmd = [
|
|
||||||
"ffmpeg", "-nostdin", "-loglevel", "error",
|
|
||||||
"-i", path,
|
|
||||||
"-c:v", "copy",
|
|
||||||
"-c:a", "aac",
|
|
||||||
"-movflags", "frag_keyframe+empty_moov",
|
|
||||||
"-f", "mp4",
|
|
||||||
"pipe:1",
|
|
||||||
]
|
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
chunk = proc.stdout.read(65536)
|
|
||||||
if not chunk:
|
|
||||||
break
|
|
||||||
yield chunk
|
|
||||||
finally:
|
|
||||||
proc.stdout.close()
|
|
||||||
proc.wait()
|
|
||||||
|
|
||||||
resp = Response(generate_stream(), 200, mimetype="video/mp4", direct_passthrough=True)
|
|
||||||
resp.headers["Cache-Control"] = "no-cache"
|
|
||||||
return resp
|
|
||||||
|
|
||||||
@app.route('/api/local-video/thumbnail')
|
@app.route('/api/local-video/thumbnail')
|
||||||
def local_video_thumbnail():
|
def local_video_thumbnail():
|
||||||
|
|||||||
Reference in New Issue
Block a user