From 8f8d9963af5b90aadc7fa4ad312ac9a7c20f0f0e Mon Sep 17 00:00:00 2001
From: valentinfrlch
Date: Wed, 28 Aug 2024 08:16:16 +0200
Subject: [PATCH] Added animated GIF support
---
README.md | 2 +-
custom_components/llmvision/manifest.json | 2 +-
custom_components/llmvision/media_handlers.py | 11 +++++++++--
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 4e8f137..9cbe092 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
-
+
diff --git a/custom_components/llmvision/manifest.json b/custom_components/llmvision/manifest.json
index 220c447..f8461b5 100644
--- a/custom_components/llmvision/manifest.json
+++ b/custom_components/llmvision/manifest.json
@@ -6,5 +6,5 @@
"documentation": "https://github.com/valentinfrlch/ha-llmvision",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/valentinfrlch/ha-llmvision/issues",
- "version": "1.1.0"
+ "version": "1.1.1"
}
\ No newline at end of file
diff --git a/custom_components/llmvision/media_handlers.py b/custom_components/llmvision/media_handlers.py
index 9cb8bc3..5faff5c 100644
--- a/custom_components/llmvision/media_handlers.py
+++ b/custom_components/llmvision/media_handlers.py
@@ -175,8 +175,8 @@ async def add_videos(self, video_paths, event_ids, interval, target_width, inclu
ffmpeg_cmd = [
"ffmpeg",
"-i", video_path,
- "-vf", f"fps=1/{interval},select='eq(n\\,0)+not(mod(n\\,{interval}))'",
- os.path.join(tmp_frames_dir, "frame%04d.png")
+ "-vf", f"fps=1/{interval},select='eq(n\\,0)+not(mod(n\\,{interval}))'", os.path.join(
+ tmp_frames_dir, "frame%04d.jpg")
]
# Run ffmpeg command
await self.hass.loop.run_in_executor(None, os.system, " ".join(ffmpeg_cmd))
@@ -186,6 +186,13 @@ async def add_videos(self, video_paths, event_ids, interval, target_width, inclu
_LOGGER.debug(f"Adding frame {frame_file}")
frame_counter = 0
frame_path = os.path.join(tmp_frames_dir, frame_file)
+
+ # Remove transparency for compatibility
+ with Image.open(frame_path) as img:
+ if img.mode == 'RGBA':
+ img = img.convert('RGB')
+ img.save(frame_path)
+
self.client.add_frame(
base64_image=await self.resize_image(image_path=frame_path, target_width=target_width),
filename=video_path.split(