Stream State across browser
This commit is contained in:
1 parent
391fc9ecd9
commit
2d98ea2d17
2 files changed
+85
-11
No files matched your search
+26
-1
@@ -42,6 +42,7 @@ _FILENAME_RE = re.compile(r"batch[_-](\d+)[_-](\d{8})[_-]\d{6}\.mp4", re.IGNOREC
|
||||
_streaming_mp4 = None
|
||||
_streaming_lock = threading.Lock()
|
||||
_streaming_proc = None
|
||||
_current_file = None
|
||||
|
||||
|
||||
def _parse_filename(filename):
|
||||
@@ -115,7 +116,7 @@ def api_mp4_files():
|
||||
|
||||
@app.route("/api/start-recount", methods=["POST"])
|
||||
def start_recount():
|
||||
global _streaming_mp4, _streaming_proc
|
||||
global _streaming_mp4, _streaming_proc, _current_file
|
||||
data = request.get_json(force=True) or {}
|
||||
mp4_path = data.get("path", "")
|
||||
if not mp4_path:
|
||||
@@ -125,6 +126,7 @@ def start_recount():
|
||||
|
||||
with _streaming_lock:
|
||||
_stop_ffmpeg_locked()
|
||||
_current_file = mp4_path
|
||||
cmd = [
|
||||
"ffmpeg", "-re", "-i", mp4_path,
|
||||
"-vf", "scale=640:480",
|
||||
@@ -139,16 +141,39 @@ def start_recount():
|
||||
"success": True,
|
||||
"stream_url": f"{RECOUNT_API_URL}/api/live-video",
|
||||
"file": Path(mp4_path).name,
|
||||
"path": mp4_path,
|
||||
})
|
||||
|
||||
|
||||
@app.route("/api/stop-recount", methods=["POST"])
|
||||
def stop_recount():
|
||||
global _current_file
|
||||
with _streaming_lock:
|
||||
_stop_ffmpeg_locked()
|
||||
_current_file = None
|
||||
return jsonify({"success": True})
|
||||
|
||||
|
||||
@app.route("/api/state")
|
||||
def api_state():
|
||||
with _streaming_lock:
|
||||
streaming = _streaming_proc is not None and _streaming_proc.poll() is None
|
||||
mp4 = _streaming_mp4
|
||||
current_file = _current_file
|
||||
result = {
|
||||
"streaming": streaming,
|
||||
}
|
||||
if current_file:
|
||||
result["file"] = current_file
|
||||
result["file_name"] = Path(current_file).name
|
||||
result["stream_url"] = f"{RECOUNT_API_URL}/api/live-video"
|
||||
batch_num, date_str = _parse_filename(Path(current_file).name)
|
||||
if batch_num is not None:
|
||||
result["batch_number"] = batch_num
|
||||
result["batch_date"] = date_str
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@app.route("/api/download-mp4")
|
||||
def api_download_mp4():
|
||||
fpath = request.args.get("file", "")
|
||||
|
||||
Reference in new issue
Block a user