Skip to content

Commit

Permalink
feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush0054 committed Dec 30, 2024
1 parent 7a96e9b commit e8f5c5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
7 changes: 1 addition & 6 deletions cookbook/agents/48_video_caption_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@
)


# Create temp directory if it doesn't exist
temp_dir = Path("/tmp/video_captions")
temp_dir.mkdir(parents=True, exist_ok=True)


video_caption_agent.print_response(
"Generate captions for cookbook/examples/caption_video_tool/trump.mp4 and embed them in the video"
"Generate captions for cookbook/examples/caption_video_tool/React in 100 Seconds.mp4 and embed them in the video"
)
# video_caption_agent.print_response(
# "read the captions for /Users/ayushjha/Downloads/videoplayback (1).mp4 and summarize them"
Expand Down
Binary file not shown.
Binary file removed cookbook/examples/caption_video_tool/trump.mp4
Binary file not shown.
19 changes: 13 additions & 6 deletions phi/tools/moviepy_video_tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from phi.tools import Toolkit
from phi.utils.log import logger
from typing import List, Dict
from typing import List, Dict, Optional

try:
from moviepy import VideoFileClip, TextClip, CompositeVideoClip, ColorClip # type: ignore
except ImportError:
raise ImportError(
"`moviepy` not installed. Please install using `pip install moviepy`"
)
raise ImportError("`moviepy` not installed. Please install using `pip install moviepy ffmpeg`")


class MoviePyVideoTools(Toolkit):
Expand Down Expand Up @@ -237,14 +235,23 @@ def create_srt(self, transcription: str, output_path: str) -> str:
logger.error(f"Failed to create SRT file: {str(e)}")
return f"Failed to create SRT file: {str(e)}"

def embed_captions(self, video_path: str, caption_path: str, output_path: str) -> str:
def embed_captions(
self,
video_path: str,
srt_path: str,
output_path: Optional[str] = None,
font_size: int = 24,
font_color: str = "white",
stroke_color: str = "black",
stroke_width: int = 1,
) -> str:
"""Embed scrolling captions with word-level highlighting into video"""
try:
# Load video
video = VideoFileClip(video_path)

# Read caption file and parse SRT
with open(caption_path, "r", encoding="utf-8") as f:
with open(srt_path, "r", encoding="utf-8") as f:
srt_content = f.read()

# Parse SRT and get word timing
Expand Down

0 comments on commit e8f5c5c

Please sign in to comment.