Fix failing thumbnail generation

This commit is contained in:
Brett Williams
2023-06-15 11:26:52 -05:00
parent 69715e8afa
commit cae5dbb41c
2 changed files with 11 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
import subprocess
import ffmpeg # todo: remove all references to ffmpeg library and instead use direct subprocesses
from ..engines.ffmpeg_engine import FFMPEG
from lib.engines.ffmpeg_engine import FFMPEG
def file_info(path):

View File

@@ -30,25 +30,22 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt
pass
# Determine best source file to use for thumbs
if job.status == RenderStatus.COMPLETED: # use finished file for thumb
source_path = job.file_list()
else:
source_path = [job.input_path] # use source if nothing else
if source_path:
source_files = job.file_list() or [job.input_path]
if source_files:
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)
image_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in image_formats]
video_files = [f for f in source_files if os.path.splitext(f)[-1].lower() in video_formats]
if (is_image_file or is_video_file) and not os.path.exists(thumb_image_path):
if (video_files or image_files) 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)
path_of_source = image_files[0] if image_files else video_files[0]
logger.debug(f"Generating image thumbnail for {path_of_source}")
save_first_frame(source_path=path_of_source, 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],))
if video_files and not os.path.exists(thumb_video_path):
x = threading.Thread(target=generate_thumb_thread, args=(video_files[0],))
x.start()