Skip to content

Commit

Permalink
Fix video clip duration in combine_videos function
Browse files Browse the repository at this point in the history
  • Loading branch information
FujiwaraChoki committed Feb 9, 2024
1 parent a4b89eb commit 059a8e9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ def generate():
"data": [],
}
)
found_url = search_for_stock_videos(
found_urls = search_for_stock_videos(
search_term, os.getenv("PEXELS_API_KEY"), it, min_dur
)
# Check for duplicates
for url in found_url:
for url in found_urls:
if url not in video_urls:
video_urls.append(url)
break

# Define video_paths
video_paths = []
Expand Down Expand Up @@ -199,7 +198,8 @@ def generate():

# Concatenate videos
temp_audio = AudioFileClip(tts_path)
combined_video_path = combine_videos(video_paths, temp_audio.duration)
print(video_paths)
combined_video_path = combine_videos(video_paths, temp_audio.duration, 5)

# Put everything together
try:
Expand Down
10 changes: 7 additions & 3 deletions Backend/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ def equalize_subtitles(srt_path: str, max_chars: int = 10) -> None:
return subtitles_path


def combine_videos(video_paths: List[str], max_duration: int) -> str:
def combine_videos(video_paths: List[str], max_duration: int, max_clip_duration: int) -> str:
"""
Combines a list of videos into one video and returns the path to the combined video.
Args:
video_paths (List): A list of paths to the videos to combine.
max_duration (int): The maximum duration of the combined video.
max_clip_duration (int): The maximum duration of each clip.
Returns:
str: The path to the combined video.
Expand Down Expand Up @@ -177,10 +178,13 @@ def combine_videos(video_paths: List[str], max_duration: int) -> str:
y_center=clip.h / 2)
clip = clip.resize((1080, 1920))

if clip.duration > max_clip_duration:
clip = clip.subclip(0, max_clip_duration)

clips.append(clip)
tot_dur += clip.duration
if tot_dur >= max_duration:
break
#if tot_dur >= max_duration:
# break

final_clip = concatenate_videoclips(clips)
final_clip = final_clip.set_fps(30)
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ assemblyai
brotli
google-api-python-client
oauth2client
edge-tts
openai
openai==0.28

0 comments on commit 059a8e9

Please sign in to comment.