From 769611ba269c046edf32bdc21986b0e164b434ea Mon Sep 17 00:00:00 2001 From: Brett Williams Date: Tue, 30 May 2023 15:19:14 -0500 Subject: [PATCH] Fix server issue with purple / green thumbnails --- lib/utilities/ffmpeg_helper.py | 2 +- lib/utilities/server_helper.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/utilities/ffmpeg_helper.py b/lib/utilities/ffmpeg_helper.py index 080af66..03e3ce6 100644 --- a/lib/utilities/ffmpeg_helper.py +++ b/lib/utilities/ffmpeg_helper.py @@ -32,7 +32,7 @@ def generate_fast_preview(source_path, dest_path, max_width=1280, run_async=Fals def generate_thumbnail(source_path, dest_path, max_width=240, run_async=False): stream = ffmpeg.input(source_path).video - stream = ffmpeg.output(stream, dest_path, **{'vf': f'scale={max_width}:trunc(ow/a/2)*2', + stream = ffmpeg.output(stream, dest_path, **{'vf': f'scale={max_width}:trunc(ow/a/2)*2,format=yuv420p', 'preset': 'veryfast', 'r': '15', 'c:v': 'libx265', diff --git a/lib/utilities/server_helper.py b/lib/utilities/server_helper.py index 05c7399..1215af5 100644 --- a/lib/utilities/server_helper.py +++ b/lib/utilities/server_helper.py @@ -28,6 +28,7 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt in_progress_path = thumb_video_path + '_IN-PROGRESS' subprocess.run(['touch', in_progress_path]) try: + logger.debug(f"Generating video thumbnail for {source}") generate_thumbnail(source_path=source, dest_path=thumb_video_path, max_width=max_width) except Exception as e: logger.error(f"Error generating thumbnail for {source}: {e}") @@ -43,13 +44,19 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt source_path = [job.input_path] # use source if nothing else if source_path: - # Todo: convert image sequence to animated movie - valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf'] - is_valid_file_type = any(ele in source_path[0] for ele in valid_formats) - if is_valid_file_type and not os.path.exists(thumb_video_path): + video_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.mxf', '.m4v', 'mkv'] + image_formats = ['.jpg', '.png', '.exr'] + + is_image_file = any(ele in source_path[0] for ele in image_formats) + is_video_file = any(ele in source_path[0] for ele in video_formats) + + if (is_image_file or is_video_file) and not os.path.exists(thumb_image_path): try: + logger.debug(f"Generating image thumbnail for {source_path[0]}") save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width) except Exception as e: logger.error(f"Exception saving first frame: {e}") + + if is_video_file and not os.path.exists(thumb_video_path): x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],)) x.start()