From 059a8e9c513df8db7d6ea461c92a5436f927f899 Mon Sep 17 00:00:00 2001 From: FujiwaraChoki Date: Fri, 9 Feb 2024 21:10:23 +0100 Subject: [PATCH] Fix video clip duration in combine_videos function --- Backend/main.py | 8 ++++---- Backend/video.py | 10 +++++++--- requirements.txt | 3 +-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Backend/main.py b/Backend/main.py index 64880e29..cbae90cd 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -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 = [] @@ -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: diff --git a/Backend/video.py b/Backend/video.py index 9959c511..3be70a0a 100644 --- a/Backend/video.py +++ b/Backend/video.py @@ -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. @@ -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) diff --git a/requirements.txt b/requirements.txt index 3446c122..5577252e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,4 @@ assemblyai brotli google-api-python-client oauth2client -edge-tts -openai \ No newline at end of file +openai==0.28 \ No newline at end of file