From c7f518509876eea713f05250541493fa072e2923 Mon Sep 17 00:00:00 2001 From: Arnaud_Cayrol Date: Sun, 13 Apr 2025 13:03:23 +0200 Subject: [PATCH] Fix ffmpeg and logging --- compile_timelapse.py | 33 +++++++++++++++------------------ main.py | 6 +----- requirements.txt | Bin 180 -> 238 bytes 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/compile_timelapse.py b/compile_timelapse.py index e602ca1..990dab8 100644 --- a/compile_timelapse.py +++ b/compile_timelapse.py @@ -6,7 +6,14 @@ import shutil from typing import Callable from pathlib import Path +# Configure logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + datefmt='%H:%M:%S' +) logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) def compile_timelapse( image_folder: str, @@ -40,29 +47,17 @@ def compile_timelapse( return False logger.info(f"Found {total_frames} images to process") - - # Create a temporary directory to hold sequential files. - temp_dir = tempfile.mkdtemp() - logger.info(f"Created temporary directory: {temp_dir}") - + try: - for idx, img in enumerate(image_files): - src = os.path.join(image_folder, img) - dst = os.path.join(temp_dir, f"{idx:06d}.jpg") - try: - os.symlink(src, dst) - except (AttributeError, NotImplementedError, OSError): - # Fallback to copying if symlinking is not supported. - shutil.copy2(src, dst) - - input_pattern = os.path.join(temp_dir, "%06d.jpg") + input_pattern = os.path.join(image_folder, "*.jpg") cmd = [ "ffmpeg", + "-pattern_type", "glob", "-framerate", str(framerate), "-i", input_pattern, "-c:v", "libx264", "-pix_fmt", "yuv420p", - "-y", # Overwrite output file if it exists + "-y", output_path ] logger.info("Running ffmpeg command: " + " ".join(cmd)) @@ -77,6 +72,9 @@ def compile_timelapse( frame_count = 0 for line in process.stderr: + if not line: + break + print(line, end='') # Output the line to the console. if "frame=" in line: try: frame = int(line.split("frame=")[1].split()[0]) @@ -97,8 +95,7 @@ def compile_timelapse( return False finally: - shutil.rmtree(temp_dir) - logger.info(f"Removed temporary directory: {temp_dir}") + logger.info(f"Video created successfully") except Exception as e: logger.error(f"Error compiling timelapse: {str(e)}") diff --git a/main.py b/main.py index 9528c02..3b1c52c 100644 --- a/main.py +++ b/main.py @@ -10,9 +10,6 @@ from image_processing import process_faces from immich_api import validate_immich_connection from compile_timelapse import compile_timelapse -# Configure logging -logger = logging.getLogger(__name__) -logger.setLevel(logging.INFO) # Filter out progress route logs class ProgressRouteFilter(logging.Filter): @@ -112,7 +109,6 @@ def background_process( progress_info["status"] = "video_done" if success else "error:Video compilation failed" except Exception as e: - logger.error(f"Error in background process: {str(e)}") raise @app.route("/progress") @@ -205,4 +201,4 @@ def index() -> str: max_workers_options=list(range(1, AVAILABLE_CORES + 1))) if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=5000, debug=False) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1e45cf3c7183398c98daef63e45775600662444b..84a793d20bd23217f403c38bcd2a7900e7296dae 100644 GIT binary patch delta 65 zcmdnO_>OVH7OOOd9EL=OVuox6TOc%M&|@$JVgm+V1}=sapj;+H5?IEN!4fEL#9#s> H&A_q%x0nh; delta 6 NcmaFIxP@`T761xH0_gw%