@ -62,21 +62,22 @@ def make_final_video(
# except (TypeError, KeyError):
# print('No background audio volume found in config.toml. Using default value of 1.')
# VOLUME_MULTIPLIER = 1
id = re . sub ( r " [^ \ w \ s-] " , " " , reddit_obj [ " thread_id " ] )
print_step ( " Creating the final video 🎥 " )
VideoFileClip . reW = lambda clip : clip . resize ( width = W )
VideoFileClip . reH = lambda clip : clip . resize ( width = H )
opacity = settings . config [ " settings " ] [ " opacity " ]
transition = settings . config [ " settings " ] [ " transition " ]
background_clip = (
VideoFileClip ( " assets/temp /background.mp4" )
VideoFileClip ( f " assets/temp /{ id } /background.mp4" )
. without_audio ( )
. resize ( height = H )
. crop ( x1 = 1166.6 , y1 = 0 , x2 = 2246.6 , y2 = 1920 )
)
# Gather all audio clips
audio_clips = [ AudioFileClip ( f " assets/temp/ mp3/{ i } .mp3 " ) for i in range ( number_of_clips ) ]
audio_clips . insert ( 0 , AudioFileClip ( " assets/temp /mp3/title.mp3" ) )
audio_clips = [ AudioFileClip ( f " assets/temp/ { id } / mp3/{ i } .mp3 " ) for i in range ( number_of_clips ) ]
audio_clips . insert ( 0 , AudioFileClip ( f " assets/temp /{ id } /mp3/title.mp3" ) )
audio_concat = concatenate_audioclips ( audio_clips )
audio_composite = CompositeAudioClip ( [ audio_concat ] )
@ -88,7 +89,7 @@ def make_final_video(
new_transition = 0 if transition is None or float ( transition ) > 2 else float ( transition )
image_clips . insert (
0 ,
ImageClip ( " assets/temp /png/title.png" )
ImageClip ( f " assets/temp /{ id } /png/title.png" )
. set_duration ( audio_clips [ 0 ] . duration )
. resize ( width = W - 100 )
. set_opacity ( new_opacity )
@ -98,7 +99,7 @@ def make_final_video(
for i in range ( 0 , number_of_clips ) :
image_clips . append (
ImageClip ( f " assets/temp/ png/comment_{ i } .png " )
ImageClip ( f " assets/temp/ { id } / png/comment_{ i } .png " )
. set_duration ( audio_clips [ i + 1 ] . duration )
. resize ( width = W - 100 )
. set_opacity ( new_opacity )
@ -140,10 +141,10 @@ def make_final_video(
# # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx
# final.set_audio(final_audio)
final = Video ( final ) . add_watermark (
text = f " Background credit: { background_config [ 2 ] } " , opacity = 0.4
text = f " Background credit: { background_config [ 2 ] } " , opacity = 0.4 , redditid = reddit_obj
)
final . write_videofile (
" assets/temp /temp.mp4" ,
f " assets/temp /{ id } /temp.mp4" ,
fps = 30 ,
audio_codec = " aac " ,
audio_bitrate = " 192k " ,
@ -151,14 +152,14 @@ def make_final_video(
threads = multiprocessing . cpu_count ( ) ,
)
ffmpeg_extract_subclip (
" assets/temp /temp.mp4" ,
f " assets/temp /{ id } /temp.mp4" ,
0 ,
length ,
targetname = f " results/ { subreddit } / { filename } " ,
)
save_data ( subreddit , filename , title , idx , background_config [ 2 ] )
print_step ( " Removing temporary files 🗑 " )
cleanups = cleanup ( )
cleanups = cleanup ( id )
print_substep ( f " Removed { cleanups } temporary files 🗑 " )
print_substep ( " See result in the results folder! " )