Skip to content

Commit

Permalink
Added animated GIF support
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinfrlch committed Aug 28, 2024
1 parent 1f59170 commit 8f8d996
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<p align=center>
<img src=https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badg>
<img src=https://img.shields.io/badge/version-1.1.0-blue>
<img src=https://img.shields.io/badge/version-1.1.1-blue>
<a href="https://github.com/valentinfrlch/ha-llmvision/issues">
<img src="https://img.shields.io/maintenance/yes/2024.svg">
<img alt="Issues" src="https://img.shields.io/github/issues/valentinfrlch/ha-llmvision?color=0088ff"/>
Expand Down
2 changes: 1 addition & 1 deletion custom_components/llmvision/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
11 changes: 9 additions & 2 deletions custom_components/llmvision/media_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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(
Expand Down

0 comments on commit 8f8d996

Please sign in to comment.