added delays defore/after TTS, before first picture and end delay

pull/958/head
Drugsosos 3 years ago
parent dd19a79ecd
commit f7dc9363d5
No known key found for this signature in database
GPG Key ID: 8E35176FE617E28D

@ -33,7 +33,9 @@ print_markdown(
print_step(f"You are using V{VERSION} of the bot") print_step(f"You are using V{VERSION} of the bot")
async def main(POST_ID=None): async def main(
POST_ID=None
):
cleanup() cleanup()
reddit_object = get_subreddit_threads(POST_ID) reddit_object = get_subreddit_threads(POST_ID)
comments_created = await save_text_to_mp3(reddit_object) comments_created = await save_text_to_mp3(reddit_object)

@ -9,7 +9,9 @@ from utils.subreddit import get_subreddit_undone
from utils.videos import check_done from utils.videos import check_done
def get_subreddit_threads(POST_ID: str): def get_subreddit_threads(
POST_ID: str
):
""" """
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
""" """
@ -87,6 +89,7 @@ def get_subreddit_threads(POST_ID: str):
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["thread_post"] = submission.selftext content["thread_post"] = submission.selftext
content["thread_id"] = submission.id content["thread_id"] = submission.id
content["is_nsfw"] = 'nsfw' in submission.whitelist_status
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:

@ -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,12 +174,34 @@ 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])
title = re.sub(r'[^\w\s-]', '', reddit_obj['thread_title']) title = re.sub(r'[^\w\s-]', '', reddit_obj['thread_title'])
idx = re.sub(r'[^\w\s-]', '', reddit_obj['thread_id']) idx = re.sub(r'[^\w\s-]', '', reddit_obj['thread_id'])

Loading…
Cancel
Save