Skip to content

Commit

Permalink
Fix event_ids for video paths
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinfrlch committed Dec 26, 2024
1 parent 63eda03 commit 38973c8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/llmvision/media_handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import io
import os
import uuid
import shutil
import logging
import time
Expand Down Expand Up @@ -322,10 +323,10 @@ async def add_videos(self, video_paths, event_ids, max_frames, target_width, inc
"""Wrapper for client.add_frame for videos"""
tmp_clips_dir = f"/config/custom_components/{DOMAIN}/tmp_clips"
tmp_frames_dir = f"/config/custom_components/{DOMAIN}/tmp_frames"
processed_event_ids = []

if not video_paths:
video_paths = []
processed_event_ids = []
if event_ids:
for event_id in event_ids:
try:
Expand Down Expand Up @@ -356,10 +357,10 @@ async def add_videos(self, video_paths, event_ids, max_frames, target_width, inc
f"Failed to fetch frigate clip {event_id}: {e}")
if video_paths:
_LOGGER.debug(f"Processing videos: {video_paths}")
video_count = 0
for video_path in video_paths:
try:
current_event_id = processed_event_ids[video_count]
current_event_id = str(uuid.uuid4())
processed_event_ids.append(current_event_id)
video_path = video_path.strip()
if os.path.exists(video_path):
# create tmp dir to store extracted frames
Expand Down Expand Up @@ -421,8 +422,7 @@ async def add_videos(self, video_paths, event_ids, max_frames, target_width, inc
sorted_frames.append(frames[0])

# Add frames to client
counter = 1
for frame_path, _ in sorted_frames:
for counter, frame_path, _ in enumerate(sorted_frames, start=1):
resized_image = await self.resize_image(image_path=frame_path, target_width=target_width)
if expose_images:
persist_filename = f"/config/www/llmvision/" + frame_path.split("/")[-1]
Expand All @@ -433,7 +433,6 @@ async def add_videos(self, video_paths, event_ids, max_frames, target_width, inc
base64_image=resized_image,
filename=video_path.split('/')[-1].split('.')[-2] + " (frame " + str(counter) + ")" if include_filename else "Video frame " + str(counter)
)
counter += 1

else:
raise ServiceValidationError(
Expand Down

0 comments on commit 38973c8

Please sign in to comment.