From bd2ef69a7dab4a3d2e16fecd91c8c68b08976368 Mon Sep 17 00:00:00 2001 From: deflax Date: Wed, 17 Jan 2024 23:11:39 +0200 Subject: [PATCH] generate thumbnail of the recorder file --- init.sh | 1 + src/discordbot/discordbot.py | 10 +++++----- src/scheduler/scheduler.py | 27 ++++++++++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/init.sh b/init.sh index 5ab41bf..aa5c093 100755 --- a/init.sh +++ b/init.sh @@ -6,6 +6,7 @@ mkdir -v -p data/restreamer/data mkdir -v -p data/recorder/vod mkdir -v -p data/recorder/live +mkdir -v -p data/recorder/thumb mkdir -v -p data/archive diff --git a/src/discordbot/discordbot.py b/src/discordbot/discordbot.py index 80012a1..66d0fd5 100644 --- a/src/discordbot/discordbot.py +++ b/src/discordbot/discordbot.py @@ -47,7 +47,7 @@ async def on_ready(): @bot.command(name='hello', help='Say hello to the bot') async def hello(ctx): author_name = ctx.author.name - await ctx.channel.send(f'```hi, {author_name} >^.^<```') + await ctx.channel.send(f'hi, `{author_name}` :blush:') @bot.command(name='epg', help='Lists scheduled streams') async def epg(ctx): @@ -70,7 +70,7 @@ async def epg(ctx): @bot.command(name='time', help='Show current time') async def time(ctx): - await ctx.channel.send(f'```The time is: {datetime.now()} UTC```') + await ctx.channel.send(f'The time is: `{datetime.now()} UTC`') @bot.command(name='now', help='Displays whats playing right now') async def now(ctx): @@ -88,7 +88,7 @@ async def query_playhead(): logger_discord.error('Cannot connect to the playhead!') head_name = playhead['name'] head_prio = playhead['prio'] - return f'```Now playing {head_name}. priority={head_prio}```' + return f'Now playing {head_name}' async def query_database(): global database @@ -138,9 +138,9 @@ async def query_database(): vod_filename = rechead['file'] rechead = {} vod_url = f'https://{vod_hostname}/storage/{vod_filename}' - offline_msg = f'Live stream is offline. VOD: {vod_url}' + offline_msg = f'Live stream is now offline. [Download VoD recording]({vod_url})' else: - offline_msg = f'Live stream is offline.' + offline_msg = f'Live stream is now offline.' logger_discord.info(offline_msg) if live_channel_id != 0: live_channel = bot.get_channel(int(live_channel_id)) diff --git a/src/scheduler/scheduler.py b/src/scheduler/scheduler.py index 1cd336f..05aefb3 100644 --- a/src/scheduler/scheduler.py +++ b/src/scheduler/scheduler.py @@ -164,29 +164,42 @@ def exec_stream(stream_id, stream_name, stream_prio, stream_hls_url): def exec_recorder(stream_id, stream_hls_url): global rechead current_datetime = datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f") - output_file = current_datetime + ".mp4" + video_file = current_datetime + ".mp4" + thumb_file = current_datetime + ".png" if rechead != {}: logger_job.error('Recorder is already started. Refusing to start another job.') else: logger_job.warning(f'Recording {output_file} started.') rechead = { 'id': stream_id, - 'file': output_file } - output = f'{rec_path}/live/{output_file}' + 'video': video_file, + 'thumb': thumb_file } + video_output = f'{rec_path}/live/{video_file}' + thumb_output = f'{rec_path}/live/{thumb_file}' ffmpeg = ( FFmpeg() .option("y") .input(stream_hls_url) - .output(output, + .output(video_output, {"codec:v": "copy", "codec:a": "copy", "bsf:a": "aac_adtstoasc"}, )) @ffmpeg.on("progress") def on_progress(progress: Progress): print(progress) - ffmpeg.execute() - logger_job.warning(f'Recording {output_file} finished. Moving file to {rec_path}/vod') - os.rename(f'{rec_path}/live/{output_file}', f'{rec_path}/vod/{output_file}') + + ffmpeg = ( + FFmpeg() + .input(video_output) + .output(thumb_output, + {"vf": "thumbnail", "frames:v": "1"}) + ) + ffmpeg.execute() + + logger_job.warning(f'Recording {video_file} finished.') + os.rename(f'{video_output}', f'{rec_path}/vod/{video_file}') + os.rename(f'{thumb_output}', f'{rec_path}/thumb/{thumb_file}}') + rechead = {} # Datarhei CORE API sync