|
|
@ -1,4 +1,5 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from moviepy.editor import (
|
|
|
|
from moviepy.editor import (
|
|
|
@ -11,6 +12,7 @@ from moviepy.editor import (
|
|
|
|
CompositeVideoClip,
|
|
|
|
CompositeVideoClip,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import reddit.subreddit
|
|
|
|
from utils.console import print_step
|
|
|
|
from utils.console import print_step
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -18,11 +20,11 @@ W, H = 1080, 1920
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_final_video(number_of_clips):
|
|
|
|
def make_final_video(number_of_clips):
|
|
|
|
|
|
|
|
|
|
|
|
# Calls opacity from the .env
|
|
|
|
# Calls opacity from the .env
|
|
|
|
load_dotenv()
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
@ -34,7 +36,7 @@ def make_final_video(number_of_clips):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
float(os.getenv("OPACITY"))
|
|
|
|
opacity = float(os.getenv("OPACITY"))
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file")
|
|
|
|
print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file")
|
|
|
|
configured = False
|
|
|
|
configured = False
|
|
|
@ -56,7 +58,7 @@ def make_final_video(number_of_clips):
|
|
|
|
.set_duration(audio_clips[i + 1].duration)
|
|
|
|
.set_duration(audio_clips[i + 1].duration)
|
|
|
|
.set_position("center")
|
|
|
|
.set_position("center")
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
.set_opacity(opacity),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
image_clips.insert(
|
|
|
|
image_clips.insert(
|
|
|
@ -65,16 +67,16 @@ def make_final_video(number_of_clips):
|
|
|
|
.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)),
|
|
|
|
.set_opacity(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 = (
|
|
|
|
"assets/final_video.mp4", fps=30, audio_codec="aac", audio_bitrate="192k"
|
|
|
|
re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|