Skip to content

Commit

Permalink
Add subtitles position option to video generation
Browse files Browse the repository at this point in the history
  • Loading branch information
FujiwaraChoki committed Feb 11, 2024
1 parent 2a9bc2c commit a45dd8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def generate():
paragraph_number = int(data.get('paragraphNumber', 1)) # Default to 1 if not provided
ai_model = data.get('aiModel') # Get the AI model selected by the user
n_threads = data.get('threads') # Amount of threads to use for video generation
subtitles_position = data.get('subtitlesPosition') # Position of the subtitles in the video

# Get 'useMusic' from the request data and default to False if not provided
use_music = data.get('useMusic', False)
Expand Down Expand Up @@ -216,7 +217,7 @@ def generate():

# Put everything together
try:
final_video_path = generate_video(combined_video_path, tts_path, subtitles_path, n_threads or 2)
final_video_path = generate_video(combined_video_path, tts_path, subtitles_path, n_threads or 2, subtitles_position)
except Exception as e:
print(colored(f"[-] Error generating final video: {e}", "red"))
final_video_path = None
Expand Down
8 changes: 6 additions & 2 deletions Backend/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def combine_videos(video_paths: List[str], max_duration: int, max_clip_duration:
return combined_video_path


def generate_video(combined_video_path: str, tts_path: str, subtitles_path: str, threads: int) -> str:
def generate_video(combined_video_path: str, tts_path: str, subtitles_path: str, threads: int, subtitles_position: str) -> str:
"""
This function creates the final video, with subtitles and audio.
Expand All @@ -203,6 +203,7 @@ def generate_video(combined_video_path: str, tts_path: str, subtitles_path: str,
tts_path (str): The path to the text-to-speech audio.
subtitles_path (str): The path to the subtitles.
threads (int): The number of threads to use for the video processing.
subtitles_position (str): The position of the subtitles.
Returns:
str: The path to the final video.
Expand All @@ -217,11 +218,14 @@ def generate_video(combined_video_path: str, tts_path: str, subtitles_path: str,
stroke_width=5,
)

# Split the subtitles position into horizontal and vertical
horizontal_subtitles_position, vertical_subtitles_position = subtitles_position.split(",")

# Burn the subtitles into the video
subtitles = SubtitlesClip(subtitles_path, generator)
result = CompositeVideoClip([
VideoFileClip(combined_video_path),
subtitles.set_pos(("center", "center"))
subtitles.set_pos((horizontal_subtitles_position, vertical_subtitles_position))
])

# Add the audio
Expand Down
2 changes: 2 additions & 0 deletions Frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const generateVideo = () => {
const useMusicToggleState = useMusicToggle.checked;
const threads = document.querySelector("#threads").value;
const zipUrlValue = zipUrl.value;
const subtitlesPosition = document.querySelector("#subtitlesPosition").value;

const url = "http://localhost:8080/api/generate";

Expand All @@ -79,6 +80,7 @@ const generateVideo = () => {
useMusic: useMusicToggleState,
zipUrl: zipUrlValue,
threads: threads,
subtitlesPosition: subtitlesPosition,
};

// Send the actual request to the server
Expand Down
16 changes: 16 additions & 0 deletions Frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ <h1 class="text-4xl text-center mb-4">MoneyPrinter</h1>
<option value="en_male_funny">wacky</option>
<option value="en_female_emotional">peaceful</option>
</select>
<label for="subtitlesPosition" class="text-blue-600"
>Subtitles Position</label
>
<select
name="subtitlesPosition"
id="subtitlesPosition"
class="w-min border-2 border-blue-300 p-2 rounded-md focus:outline-none focus:border-blue-500"
>
<option value="center,top">Center - Top</option>
<option value="center,bottom">Center - Bottom</option>
<option value="center,center">Center - Center</option>
<option value="left,center">Left - Center</option>
<option value="left,bottom">Left - Bottom</option>
<option value="right,center">Right - Center</option>
<option value="right,bottom">Right - Bottom</option>
</select>
<label for="zipUrl" class="text-blue-600"
>Zip URL (Leave empty for default)</label
>
Expand Down

0 comments on commit a45dd8a

Please sign in to comment.