import subprocess import requests import os import json import threading from utilities.render_worker import RenderStatus from utilities.ffmpeg_presets import generate_fast_preview, save_first_frame def post_job_to_server(input_path, job_list, client, server_port=8080): # Pack job data and submit to server job_files = {'file': (os.path.basename(input_path), open(input_path, 'rb'), 'application/octet-stream'), 'json': (None, json.dumps(job_list), 'application/json')} req = requests.post(f'http://{client}:{server_port}/api/add_job', files=job_files) return req def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_width=320): # Simple thread to generate thumbs in background def generate_thumb_thread(source): in_progress_path = thumb_video_path + '_IN-PROGRESS' subprocess.run(['touch', in_progress_path]) generate_fast_preview(source_path=source, dest_path=thumb_video_path, max_width=max_width) os.remove(in_progress_path) # Determine best source file to use for thumbs if job.render_status() == RenderStatus.COMPLETED: # use finished file for thumb source_path = job.file_list() elif len(job.file_list()) > 1: # if image sequence, use second to last file (last may be in use) source_path = [job.file_list()[-2]] else: source_path = [job.worker.input_path] # use source if nothing else # 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): save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width) x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],)) x.start()