diff --git a/modules/core.py b/modules/core.py index 663d742..67eece1 100644 --- a/modules/core.py +++ b/modules/core.py @@ -251,11 +251,15 @@ def start() -> None: update_status('Detecting fps...') fps = detect_fps(modules.globals.target_path) update_status(f'Creating video with {fps} fps...') - create_video(modules.globals.target_path, fps) + video_created = create_video(modules.globals.target_path, fps) else: update_status('Creating video with 30.0 fps...') - create_video(modules.globals.target_path) + video_created = create_video(modules.globals.target_path) encoding_time = time.time() - encoding_start + if not video_created: + update_status('Video encoding failed. No temporary output video was created.') + clean_temp(modules.globals.target_path) + return update_status(f'Video encoding completed in {encoding_time:.2f}s') # handle audio @@ -272,8 +276,8 @@ def start() -> None: clean_temp(modules.globals.target_path) total_time = time.time() - start_time - if is_video(modules.globals.target_path): - update_status(f'Processing to video succeed! Total time: {total_time:.2f}s') + if is_video(modules.globals.target_path) and modules.globals.output_path and os.path.isfile(modules.globals.output_path): + update_status(f'Video processing succeeded! Total time: {total_time:.2f}s') else: update_status('Processing to video failed!') diff --git a/modules/utilities.py b/modules/utilities.py index 2638465..d99e74d 100644 --- a/modules/utilities.py +++ b/modules/utilities.py @@ -30,8 +30,12 @@ def run_ffmpeg(args: List[str]) -> bool: try: subprocess.check_output(commands, stderr=subprocess.STDOUT) return True - except Exception: - pass + except subprocess.CalledProcessError as error: + output = error.output.decode(errors="ignore").strip() + if output: + print(output) + except Exception as error: + print(f"ffmpeg execution failed: {error}") return False @@ -61,19 +65,19 @@ def extract_frames(target_path: str) -> None: """Extract frames with hardware acceleration and optimized settings.""" temp_directory_path = get_temp_directory_path(target_path) - # Use hardware-accelerated decoding and optimized pixel format + # Write a contiguous image sequence so the later "%04d.png" input pattern + # used during encoding can consume every frame reliably. run_ffmpeg( [ "-i", target_path, "-vf", "format=rgb24", # Use video filter for format conversion (faster) "-vsync", "0", # Prevent frame duplication - "-frame_pts", "1", # Preserve frame timing os.path.join(temp_directory_path, "%04d.png"), ] ) -def create_video(target_path: str, fps: float = 30.0) -> None: +def create_video(target_path: str, fps: float = 30.0) -> bool: """Create video with hardware-accelerated encoding and optimized settings.""" temp_output_path = get_temp_output_path(target_path) temp_directory_path = get_temp_directory_path(target_path) @@ -182,7 +186,8 @@ def create_video(target_path: str, fps: float = 30.0) -> None: "-y", temp_output_path, ] - run_ffmpeg(ffmpeg_args_fallback) + success = run_ffmpeg(ffmpeg_args_fallback) + return success and os.path.isfile(temp_output_path) def restore_audio(target_path: str, output_path: str) -> None: