check if stream_hls_url exists before we exec the recording
This commit is contained in:
parent
18bb202796
commit
39ab8c23d2
2 changed files with 18 additions and 10 deletions
|
@ -1,7 +1,8 @@
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import time
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import Flask, render_template, jsonify, request
|
from flask import Flask, render_template, jsonify, request
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
|
@ -154,17 +155,23 @@ def exec_recorder(stream_id, stream_hls_url):
|
||||||
output_file = current_datetime + ".mp4"
|
output_file = current_datetime + ".mp4"
|
||||||
if rechead != "":
|
if rechead != "":
|
||||||
logger_job.error('Recorder is already started. Refusing to start another rec job.')
|
logger_job.error('Recorder is already started. Refusing to start another rec job.')
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
|
# Check if the stream_hls_url returns 200
|
||||||
|
req_counter = 0
|
||||||
|
while True:
|
||||||
|
req_counter += 1
|
||||||
|
if requests.get(stream_hls_url).status_code == 200:
|
||||||
|
logger_job.warning(f'{stream_hls_url} accessible after {req_counter} attempts.')
|
||||||
|
break
|
||||||
logger_job.warning(f'Starting recording job for {output_file}')
|
logger_job.warning(f'Starting recording job for {output_file}')
|
||||||
rechead = stream_id
|
rechead = stream_id
|
||||||
ffmpeg = (
|
ffmpeg = (
|
||||||
FFmpeg()
|
FFmpeg()
|
||||||
.option("y")
|
.option("y")
|
||||||
.input(stream_hls_url)
|
.input(stream_hls_url)
|
||||||
.output(output_file, vcodec="copy")
|
.output(output_file, vcodec="copy")
|
||||||
)
|
)
|
||||||
ffmpeg.execute()
|
ffmpeg.execute()
|
||||||
|
|
||||||
def core_api_sync():
|
def core_api_sync():
|
||||||
global database
|
global database
|
||||||
|
|
|
@ -8,3 +8,4 @@ waitress==2.1.2
|
||||||
Werkzeug==3.0.1
|
Werkzeug==3.0.1
|
||||||
APScheduler==3.10.4
|
APScheduler==3.10.4
|
||||||
python-ffmpeg==2.0.10
|
python-ffmpeg==2.0.10
|
||||||
|
requests==2.31.0
|
Loading…
Reference in a new issue