@ -7,14 +7,24 @@ from moviepy.editor import (
CompositeAudioClip ,
CompositeAudioClip ,
CompositeVideoClip ,
CompositeVideoClip ,
)
)
import reddit . subreddit
import re
from utils . console import print_step
from utils . console import print_step
from dotenv import load_dotenv
import os
W , H = 1080 , 1920
W , H = 1080 , 1920
def make_final_video ( number_of_clips ) :
def make_final_video ( number_of_clips ) :
# Calls opacity from the .env
load_dotenv ( )
opacity = os . getenv ( ' OPACITY ' )
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 )
@ -25,6 +35,7 @@ def make_final_video(number_of_clips):
. 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/mp3/ { i } .mp3 " ) for i in range ( 0 , number_of_clips ) ]
audio_clips = [ AudioFileClip ( f " assets/mp3/ { i } .mp3 " ) for i in range ( 0 , number_of_clips ) ]
audio_clips . insert ( 0 , AudioFileClip ( f " assets/mp3/title.mp3 " ) )
audio_clips . insert ( 0 , AudioFileClip ( f " assets/mp3/title.mp3 " ) )
@ -35,23 +46,23 @@ def make_final_video(number_of_clips):
image_clips = [ ImageClip ( f " assets/png/comment_ { i } .png " )
image_clips = [ ImageClip ( f " assets/png/comment_ { i } .png " )
. set_duration ( audio_clips [ i + 1 ] . duration )
. set_duration ( audio_clips [ i + 1 ] . duration )
. set_position ( " center " )
. set_position ( " center " )
. resize ( width = W - 100 ) for i in range ( 0 , number_of_clips ) ]
. resize ( width = W - 100 )
. set_opacity ( float ( opacity ) ) ,
]
image_clips . insert (
image_clips . insert (
0 ,
0 ,
ImageClip ( f " assets/png/title.png " )
ImageClip ( f " assets/png/title.png " )
. set_duration ( audio_clips [ 0 ] . duration )
. set_duration ( audio_clips [ 0 ] . duration )
. set_position ( " center " )
. set_position ( " center " )
. resize ( width = W - 100 ) ,
. resize ( width = W - 100 )
. set_opacity ( float ( opacity ) ) ,
)
)
image_concat = concatenate_videoclips ( image_clips ) . set_position (
image_concat = concatenate_videoclips ( image_clips ) . set_position (
( " center " , " center " )
( " center " , " center " )
)
)
image_concat . audio = audio_composite
image_concat . audio = audio_composite
final = CompositeVideoClip ( [ background_clip , image_concat ] )
final = CompositeVideoClip ( [ background_clip , image_concat ] )
final . write_videofile (
filename = ( re . sub ( ' [? \" % *:|<>] ' , ' ' , ( " assets/ " + reddit . subreddit . submission . title + " .mp4 " ) ) )
" assets/final_video.mp4 " , fps = 30 , audio_codec = " aac " , audio_bitrate = " 192k "
final . write_videofile ( filename , fps = 30 , audio_codec = " aac " , audio_bitrate = " 192k " )
)
for i in range ( 0 , number_of_clips ) :
for i in range ( 0 , number_of_clips ) :
pass
pass