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