|
|
@ -28,7 +28,12 @@ from video_creation.background import download_background, chop_background_video
|
|
|
|
console = Console()
|
|
|
|
console = Console()
|
|
|
|
|
|
|
|
|
|
|
|
W, H = 1080, 1920 # TODO move to config
|
|
|
|
W, H = 1080, 1920 # TODO move to config
|
|
|
|
|
|
|
|
|
|
|
|
max_length: int = 50 # TODO move to config
|
|
|
|
max_length: int = 50 # TODO move to config
|
|
|
|
|
|
|
|
time_before_first_picture: float = 1 # TODO move to config
|
|
|
|
|
|
|
|
time_before_tts: float = 0.5 # TODO move to config
|
|
|
|
|
|
|
|
time_between_pictures: float = 1 # TODO move to config
|
|
|
|
|
|
|
|
delay_before_end: int = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def name_normalize(
|
|
|
|
def name_normalize(
|
|
|
@ -82,12 +87,13 @@ def make_final_video(
|
|
|
|
|
|
|
|
|
|
|
|
# Gather all audio clips
|
|
|
|
# Gather all audio clips
|
|
|
|
audio_clips = list()
|
|
|
|
audio_clips = list()
|
|
|
|
|
|
|
|
correct_audio_offset = time_before_tts * 2 + time_between_pictures
|
|
|
|
|
|
|
|
|
|
|
|
audio_title = create_audio_clip(
|
|
|
|
audio_title = create_audio_clip(
|
|
|
|
'title',
|
|
|
|
'title',
|
|
|
|
0,
|
|
|
|
time_before_first_picture + time_before_tts,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
video_duration += audio_title.duration
|
|
|
|
video_duration += audio_title.duration + time_before_first_picture + time_before_tts
|
|
|
|
audio_clips.append(audio_title)
|
|
|
|
audio_clips.append(audio_title)
|
|
|
|
indexes_for_videos = list()
|
|
|
|
indexes_for_videos = list()
|
|
|
|
|
|
|
|
|
|
|
@ -97,16 +103,18 @@ def make_final_video(
|
|
|
|
):
|
|
|
|
):
|
|
|
|
temp_audio_clip = create_audio_clip(
|
|
|
|
temp_audio_clip = create_audio_clip(
|
|
|
|
idx,
|
|
|
|
idx,
|
|
|
|
video_duration,
|
|
|
|
correct_audio_offset + video_duration,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if video_duration + temp_audio_clip.duration <= max_length:
|
|
|
|
if video_duration + temp_audio_clip.duration + correct_audio_offset + delay_before_end <= max_length:
|
|
|
|
video_duration += temp_audio_clip.duration
|
|
|
|
video_duration += temp_audio_clip.duration + correct_audio_offset
|
|
|
|
audio_clips.append(temp_audio_clip)
|
|
|
|
audio_clips.append(temp_audio_clip)
|
|
|
|
indexes_for_videos.append(idx)
|
|
|
|
indexes_for_videos.append(idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
video_duration += delay_before_end
|
|
|
|
|
|
|
|
|
|
|
|
audio_composite = concatenate_audioclips(audio_clips)
|
|
|
|
audio_composite = concatenate_audioclips(audio_clips)
|
|
|
|
|
|
|
|
|
|
|
|
console.log('[bold green] Video Will Be: %.2f Seconds Long' % audio_composite.end)
|
|
|
|
console.log('[bold green] Video Will Be: %.2f Seconds Long' % video_duration)
|
|
|
|
# Gather all images
|
|
|
|
# Gather all images
|
|
|
|
new_opacity = 1 if opacity is None or float(opacity) >= 1 else float(opacity) # TODO move to pydentic and percents
|
|
|
|
new_opacity = 1 if opacity is None or float(opacity) >= 1 else float(opacity) # TODO move to pydentic and percents
|
|
|
|
|
|
|
|
|
|
|
@ -118,9 +126,9 @@ def make_final_video(
|
|
|
|
) -> 'ImageClip':
|
|
|
|
) -> 'ImageClip':
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
ImageClip(f'assets/temp/png/{image_title}.png')
|
|
|
|
ImageClip(f'assets/temp/png/{image_title}.png')
|
|
|
|
.set_start(audio_start)
|
|
|
|
.set_start(audio_start - time_before_tts)
|
|
|
|
.set_end(audio_end)
|
|
|
|
.set_end(audio_end + time_before_tts)
|
|
|
|
.set_duration(audio_duration, change_end=False)
|
|
|
|
.set_duration(time_before_tts * 2 + audio_duration, change_end=False)
|
|
|
|
.set_opacity(new_opacity)
|
|
|
|
.set_opacity(new_opacity)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -166,10 +174,32 @@ def make_final_video(
|
|
|
|
background_clip = (
|
|
|
|
background_clip = (
|
|
|
|
VideoFileClip('assets/temp/background.mp4')
|
|
|
|
VideoFileClip('assets/temp/background.mp4')
|
|
|
|
.set_start(0)
|
|
|
|
.set_start(0)
|
|
|
|
.set_end(video_duration)
|
|
|
|
.set_end(video_duration + delay_before_end)
|
|
|
|
.without_audio()
|
|
|
|
.without_audio()
|
|
|
|
.resize(height=H)
|
|
|
|
.resize(height=H)
|
|
|
|
.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
back_video_width, back_video_height = background_clip.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fix for crop with vertical videos
|
|
|
|
|
|
|
|
if back_video_width < H:
|
|
|
|
|
|
|
|
background_clip = (
|
|
|
|
|
|
|
|
background_clip
|
|
|
|
|
|
|
|
.resize(width=W)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
back_video_width, back_video_height = background_clip.size
|
|
|
|
|
|
|
|
background_clip = background_clip.crop(
|
|
|
|
|
|
|
|
x1=0,
|
|
|
|
|
|
|
|
x2=back_video_width,
|
|
|
|
|
|
|
|
y1=back_video_height / 2 - H / 2,
|
|
|
|
|
|
|
|
y2=back_video_height / 2 + H / 2
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
background_clip = background_clip.crop(
|
|
|
|
|
|
|
|
x1=back_video_width / 2 - W / 2,
|
|
|
|
|
|
|
|
x2=back_video_width / 2 + W / 2,
|
|
|
|
|
|
|
|
y1=0,
|
|
|
|
|
|
|
|
y2=back_video_height
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
final = CompositeVideoClip([background_clip, image_concat])
|
|
|
|
final = CompositeVideoClip([background_clip, image_concat])
|
|
|
|