Compare commits
2 commits
eec8482df3
...
af5a7a4b17
Author | SHA1 | Date | |
---|---|---|---|
af5a7a4b17 | |||
b421cb3e32 |
1 changed files with 55 additions and 48 deletions
|
@ -179,57 +179,64 @@ def exec_recorder(stream_id, stream_name, stream_hls_url):
|
||||||
video_output = f'{rec_path}/live/{video_file}'
|
video_output = f'{rec_path}/live/{video_file}'
|
||||||
thumb_output = f'{rec_path}/live/{thumb_file}'
|
thumb_output = f'{rec_path}/live/{thumb_file}'
|
||||||
|
|
||||||
# Record a mp4 file
|
try:
|
||||||
ffmpeg = (
|
# Record a mp4 file
|
||||||
FFmpeg()
|
ffmpeg = (
|
||||||
.option("y")
|
FFmpeg()
|
||||||
.input(stream_hls_url)
|
.option("y")
|
||||||
.output(video_output,
|
.input(stream_hls_url)
|
||||||
{"codec:v": "copy", "codec:a": "copy", "bsf:a": "aac_adtstoasc"},
|
.output(video_output,
|
||||||
))
|
{"codec:v": "copy", "codec:a": "copy", "bsf:a": "aac_adtstoasc"},
|
||||||
@ffmpeg.on("progress")
|
))
|
||||||
def on_progress(progress: Progress):
|
@ffmpeg.on("progress")
|
||||||
print(progress)
|
def on_progress(progress: Progress):
|
||||||
ffmpeg.execute()
|
print(progress)
|
||||||
logger_job.warning(f'Recording {video_file} finished.')
|
ffmpeg.execute()
|
||||||
|
logger_job.warning(f'Recording of {video_file} finished.')
|
||||||
|
|
||||||
# Show Metadata
|
except Exception as joberror:
|
||||||
ffmpeg_metadata = (
|
logger_job.error(f'Recording of {video_file} failed!')
|
||||||
FFmpeg(executable="ffprobe")
|
logger_job.error(joberror)
|
||||||
.input(video_output,
|
|
||||||
print_format="json",
|
|
||||||
show_streams=None,)
|
|
||||||
)
|
|
||||||
media = json.loads(ffmpeg_metadata.execute())
|
|
||||||
logger_job.warning(f"# Video")
|
|
||||||
logger_job.warning(f"- Codec: {media['streams'][0]['codec_name']}")
|
|
||||||
logger_job.warning(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}")
|
|
||||||
logger_job.warning(f"- Duration: {media['streams'][0]['duration']}")
|
|
||||||
logger_job.warning(f"# Audio")
|
|
||||||
logger_job.warning(f"- Codec: {media['streams'][1]['codec_name']}")
|
|
||||||
logger_job.warning(f"- Sample Rate: {media['streams'][1]['sample_rate']}")
|
|
||||||
logger_job.warning(f"- Duration: {media['streams'][1]['duration']}")
|
|
||||||
|
|
||||||
thumb_skip_time = float(media['streams'][0]['duration']) // 2
|
else:
|
||||||
thumb_width = media['streams'][0]['width']
|
# Show Metadata
|
||||||
|
ffmpeg_metadata = (
|
||||||
|
FFmpeg(executable="ffprobe")
|
||||||
|
.input(video_output,
|
||||||
|
print_format="json",
|
||||||
|
show_streams=None,)
|
||||||
|
)
|
||||||
|
media = json.loads(ffmpeg_metadata.execute())
|
||||||
|
logger_job.warning(f"# Video")
|
||||||
|
logger_job.warning(f"- Codec: {media['streams'][0]['codec_name']}")
|
||||||
|
logger_job.warning(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}")
|
||||||
|
logger_job.warning(f"- Duration: {media['streams'][0]['duration']}")
|
||||||
|
logger_job.warning(f"# Audio")
|
||||||
|
logger_job.warning(f"- Codec: {media['streams'][1]['codec_name']}")
|
||||||
|
logger_job.warning(f"- Sample Rate: {media['streams'][1]['sample_rate']}")
|
||||||
|
logger_job.warning(f"- Duration: {media['streams'][1]['duration']}")
|
||||||
|
|
||||||
# Generate thumbnail image from the recorded mp4 file
|
thumb_skip_time = float(media['streams'][0]['duration']) // 2
|
||||||
ffmpeg_thumb = (
|
thumb_width = media['streams'][0]['width']
|
||||||
FFmpeg()
|
|
||||||
.input(video_output, ss=thumb_skip_time)
|
|
||||||
.output(thumb_output, vf='scale={}:{}'.format(thumb_width, -1), vframes=1)
|
|
||||||
)
|
|
||||||
ffmpeg_thumb.execute()
|
|
||||||
logger_job.warning(f'Thumbnail {thumb_file} created.')
|
|
||||||
|
|
||||||
# When ready, move the recorded from the live dir to the archives and reset the rec head
|
# Generate thumbnail image from the recorded mp4 file
|
||||||
os.rename(f'{video_output}', f'{rec_path}/vod/{video_file}')
|
ffmpeg_thumb = (
|
||||||
os.rename(f'{thumb_output}', f'{rec_path}/thumb/{thumb_file}')
|
FFmpeg()
|
||||||
|
.input(video_output, ss=thumb_skip_time)
|
||||||
|
.output(thumb_output, vf='scale={}:{}'.format(thumb_width, -1), vframes=1)
|
||||||
|
)
|
||||||
|
ffmpeg_thumb.execute()
|
||||||
|
logger_job.warning(f'Thumbnail {thumb_file} created.')
|
||||||
|
|
||||||
# Reset the rechead
|
# When ready, move the recorded from the live dir to the archives and reset the rec head
|
||||||
time.sleep(5)
|
os.rename(f'{video_output}', f'{rec_path}/vod/{video_file}')
|
||||||
rechead = {}
|
os.rename(f'{thumb_output}', f'{rec_path}/thumb/{thumb_file}')
|
||||||
logger_job.warning(f'Rechead reset.')
|
|
||||||
|
finally:
|
||||||
|
# Reset the rechead
|
||||||
|
time.sleep(5)
|
||||||
|
rechead = {}
|
||||||
|
logger_job.warning(f'Rechead reset.')
|
||||||
|
|
||||||
# Datarhei CORE API sync
|
# Datarhei CORE API sync
|
||||||
def core_api_sync():
|
def core_api_sync():
|
||||||
|
|
Loading…
Reference in a new issue