From c6df98abeb9e402ec6ec604863e80da85ef924fc Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 6 Jun 2022 17:48:43 -0400 Subject: [PATCH] added image transparency closes #39 --- .env.template | 2 ++ video_creation/final_video.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.env.template b/.env.template index 280b7c3..ae59b09 100644 --- a/.env.template +++ b/.env.template @@ -14,3 +14,5 @@ THEME="LIGHT" # set to an int e.g. 1 or 29 and leave blank for once TIMES_TO_RUN="" MAX_COMMENT_LENGTH="500" +# Range is 0 -> 1 recommended around 0.8-1 +OPACITY="" diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e94dd9e..a41c862 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -3,7 +3,8 @@ import os import time from os.path import exists -from moviepy.editor import VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, CompositeAudioClip, CompositeVideoClip +from moviepy.editor import VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, \ + CompositeAudioClip, CompositeVideoClip from moviepy.video.io import ffmpeg_tools from reddit import subreddit @@ -17,10 +18,10 @@ def make_final_video(number_of_clips, length): print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) - + opacity = os.getenv('OPACITY') background_clip = ( VideoFileClip("assets/temp/background.mp4").without_audio().resize(height=H).crop(x1=1166.6, y1=0, x2=2246.6, - y2=1920)) + y2=1920)) # Gather all audio clips audio_clips = [] for i in range(0, number_of_clips): @@ -34,9 +35,10 @@ def make_final_video(number_of_clips, length): for i in range(0, number_of_clips): image_clips.append( ImageClip(f"assets/temp/png/comment_{i}.png").set_duration(audio_clips[i + 1].duration).set_position( - "center").resize(width=W - 100), ) + "center").resize(width=W - 100).set_opacity(float(opacity)), ) image_clips.insert(0, ImageClip(f"assets/temp/png/title.png").set_duration(audio_clips[0].duration).set_position( - "center").resize(width=W - 100), ) + "center").resize(width=W - 100).set_opacity(float(opacity)), + ) image_concat = concatenate_videoclips(image_clips).set_position(("center", "center")) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) @@ -69,7 +71,7 @@ def make_final_video(number_of_clips, length): final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k") ffmpeg_tools.ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}") - #os.remove("assets/temp/temp.mp4") + # os.remove("assets/temp/temp.mp4") print_step("Removing temporary files 🗑") cleanups = cleanup()