Thumbnail generation error handling

This commit is contained in:
Brett Williams
2023-05-24 15:41:27 -05:00
parent 9ac1c44ba3
commit 4d620d0ea6

View File

@@ -1,4 +1,5 @@
import json import json
import logging
import os import os
import subprocess import subprocess
import threading import threading
@@ -8,6 +9,7 @@ import requests
from .ffmpeg_helper import generate_thumbnail, save_first_frame from .ffmpeg_helper import generate_thumbnail, save_first_frame
from lib.render_workers.render_worker import RenderStatus from lib.render_workers.render_worker import RenderStatus
logger = logging.getLogger()
def post_job_to_server(input_path, job_list, hostname, server_port=8080): def post_job_to_server(input_path, job_list, hostname, server_port=8080):
@@ -25,8 +27,12 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt
def generate_thumb_thread(source): def generate_thumb_thread(source):
in_progress_path = thumb_video_path + '_IN-PROGRESS' in_progress_path = thumb_video_path + '_IN-PROGRESS'
subprocess.run(['touch', in_progress_path]) subprocess.run(['touch', in_progress_path])
generate_thumbnail(source_path=source, dest_path=thumb_video_path, max_width=max_width) try:
os.remove(in_progress_path) 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}")
finally:
os.remove(in_progress_path)
# Determine best source file to use for thumbs # Determine best source file to use for thumbs
if job.render_status() == RenderStatus.COMPLETED: # use finished file for thumb if job.render_status() == RenderStatus.COMPLETED: # use finished file for thumb
@@ -41,6 +47,9 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt
valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf'] 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) 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): if is_valid_file_type and not os.path.exists(thumb_video_path):
save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width) try:
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}")
x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],)) x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],))
x.start() x.start()