Fix ffmpeg and logging
This commit is contained in:
parent
e11af67668
commit
c7f5185098
3 changed files with 16 additions and 23 deletions
|
|
@ -6,7 +6,14 @@ import shutil
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from pathlib import Path
|
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 = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
def compile_timelapse(
|
def compile_timelapse(
|
||||||
image_folder: str,
|
image_folder: str,
|
||||||
|
|
@ -40,29 +47,17 @@ def compile_timelapse(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.info(f"Found {total_frames} images to process")
|
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:
|
try:
|
||||||
for idx, img in enumerate(image_files):
|
input_pattern = os.path.join(image_folder, "*.jpg")
|
||||||
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")
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
|
"-pattern_type", "glob",
|
||||||
"-framerate", str(framerate),
|
"-framerate", str(framerate),
|
||||||
"-i", input_pattern,
|
"-i", input_pattern,
|
||||||
"-c:v", "libx264",
|
"-c:v", "libx264",
|
||||||
"-pix_fmt", "yuv420p",
|
"-pix_fmt", "yuv420p",
|
||||||
"-y", # Overwrite output file if it exists
|
"-y",
|
||||||
output_path
|
output_path
|
||||||
]
|
]
|
||||||
logger.info("Running ffmpeg command: " + " ".join(cmd))
|
logger.info("Running ffmpeg command: " + " ".join(cmd))
|
||||||
|
|
@ -77,6 +72,9 @@ def compile_timelapse(
|
||||||
|
|
||||||
frame_count = 0
|
frame_count = 0
|
||||||
for line in process.stderr:
|
for line in process.stderr:
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
print(line, end='') # Output the line to the console.
|
||||||
if "frame=" in line:
|
if "frame=" in line:
|
||||||
try:
|
try:
|
||||||
frame = int(line.split("frame=")[1].split()[0])
|
frame = int(line.split("frame=")[1].split()[0])
|
||||||
|
|
@ -97,8 +95,7 @@ def compile_timelapse(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(temp_dir)
|
logger.info(f"Video created successfully")
|
||||||
logger.info(f"Removed temporary directory: {temp_dir}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error compiling timelapse: {str(e)}")
|
logger.error(f"Error compiling timelapse: {str(e)}")
|
||||||
|
|
|
||||||
6
main.py
6
main.py
|
|
@ -10,9 +10,6 @@ from image_processing import process_faces
|
||||||
from immich_api import validate_immich_connection
|
from immich_api import validate_immich_connection
|
||||||
from compile_timelapse import compile_timelapse
|
from compile_timelapse import compile_timelapse
|
||||||
|
|
||||||
# Configure logging
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
# Filter out progress route logs
|
# Filter out progress route logs
|
||||||
class ProgressRouteFilter(logging.Filter):
|
class ProgressRouteFilter(logging.Filter):
|
||||||
|
|
@ -112,7 +109,6 @@ def background_process(
|
||||||
progress_info["status"] = "video_done" if success else "error:Video compilation failed"
|
progress_info["status"] = "video_done" if success else "error:Video compilation failed"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in background process: {str(e)}")
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@app.route("/progress")
|
@app.route("/progress")
|
||||||
|
|
@ -205,4 +201,4 @@ def index() -> str:
|
||||||
max_workers_options=list(range(1, AVAILABLE_CORES + 1)))
|
max_workers_options=list(range(1, AVAILABLE_CORES + 1)))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(host='0.0.0.0', port=5000, debug=False)
|
||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in a new issue