Overlay Update

Add multiple overlays to choose from
pull/1174/head
RapidStoned 3 years ago
parent 02d3598d70
commit a466d4196d

@ -23,6 +23,7 @@ opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets
transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" } transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" }
storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, not yet implemented" } storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, not yet implemented" }
sub_overlay = { optional = true, type = "bool", default = false, example = false, options = [true, false], explanation = "This will add a subscribe animation overlay to the end of the video" } sub_overlay = { optional = true, type = "bool", default = false, example = false, options = [true, false], explanation = "This will add a subscribe animation overlay to the end of the video" }
sub_overlay_name = { optional = true, default = "youtube", options = ["youtube", "tiktok", "instagram"], explanation = "Choose which overlay you would like"}
[settings.background] [settings.background]

@ -1,11 +1,16 @@
from __future__ import annotations from __future__ import annotations
from ast import Str
import re import re
import math
from typing import Tuple from typing import Tuple
from utils import settings
from PIL import ImageFont, Image, ImageDraw, ImageEnhance from PIL import ImageFont, Image, ImageDraw, ImageEnhance
from moviepy.video.VideoClip import VideoClip, ImageClip from moviepy.video.VideoClip import VideoClip, ImageClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.io.VideoFileClip import VideoFileClip
class Video: class Video:
@ -36,7 +41,9 @@ class Video:
im.save(path) im.save(path)
return ImageClip(path) return ImageClip(path)
def add_watermark(self, text, redditid, opacity=0.5, duration: int | float = 5, position: Tuple = (0.7, 0.9), fontsize=15): def add_watermark(
self, text, redditid, opacity=0.5, duration: int | float = 5, position: Tuple = (0.7, 0.9), fontsize=15
):
compensation = round( compensation = round(
(position[0] / ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])), (position[0] / ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])),
ndigits=2, ndigits=2,
@ -53,3 +60,18 @@ class Video:
# Overlay the img clip on the first video clip # Overlay the img clip on the first video clip
self.video = CompositeVideoClip([self.video, img_clip]) self.video = CompositeVideoClip([self.video, img_clip])
return self.video return self.video
def add_overlay(self):
# Get duration for the entire video to place the overlay at the correct time
video_duration = self.video.duration
overlayName = settings.config["settings"]["sub_overlay_name"]
subOverlayClip = VideoFileClip((f"assets/subOverlay/{overlayName}.mov"), has_mask=True)
subOverlayClip.set_pos('center')
placeTime = math.floor(video_duration - subOverlayClip.duration) - 3
self.video = CompositeVideoClip([self.video, subOverlayClip.set_start(placeTime)])
return self.video

@ -4,7 +4,6 @@ import os
import re import re
from os.path import exists from os.path import exists
from typing import Tuple, Any from typing import Tuple, Any
from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip
from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.VideoClip import ImageClip from moviepy.video.VideoClip import ImageClip
@ -14,11 +13,11 @@ from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from rich.console import Console from rich.console import Console
from utils import settings
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.video import Video from utils.video import Video
from utils.videos import save_data from utils.videos import save_data
from utils import settings
console = Console() console = Console()
W, H = 1080, 1920 W, H = 1080, 1920
@ -108,11 +107,6 @@ def make_final_video(
.crossfadeout(new_transition) .crossfadeout(new_transition)
) )
#Subscribe Overlay
if settings.config["settings"]["sub_overlay"]:
subOverlayClip = VideoFileClip((f"assets/subOverlay/subOverlayClip.mov"), has_mask=True)
subOverlayClip.set_pos('center')
# if os.path.exists("assets/mp3/posttext.mp3"): # if os.path.exists("assets/mp3/posttext.mp3"):
# image_clips.insert( # image_clips.insert(
# 0, # 0,
@ -125,14 +119,13 @@ def make_final_video(
# else: story mode stuff # else: story mode stuff
img_clip_pos = background_config[3] img_clip_pos = background_config[3]
image_concat = concatenate_videoclips(image_clips).set_position(img_clip_pos) # note transition kwarg for delay in imgs image_concat = concatenate_videoclips(image_clips).set_position(
img_clip_pos
) # note transition kwarg for delay in imgs
image_concat.audio = audio_composite image_concat.audio = audio_composite
if settings.config["settings"]["sub_overlay"]: final = CompositeVideoClip([background_clip, image_concat])
final = CompositeVideoClip([background_clip, image_concat, subOverlayClip.set_start(background_clip.duration - subOverlayClip.duration)])
else:
final = CompositeVideoClip([background_clip, image_concat])
title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"])
idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"]) idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
@ -151,7 +144,14 @@ def make_final_video(
# # lowered_audio = audio_background.multiply_volume( # todo get this to work # # lowered_audio = audio_background.multiply_volume( # todo get this to work
# # 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(text=f"Background credit: {background_config[2]}", opacity=0.4, redditid=reddit_obj) final = Video(final).add_watermark(
text=f"Background credit: {background_config[2]}", opacity=0.4, redditid=reddit_obj
)
# Add an overlay
if settings.config["settings"]["sub_overlay"]:
final = Video(final).add_overlay()
final.write_videofile( final.write_videofile(
f"assets/temp/{id}/temp.mp4", f"assets/temp/{id}/temp.mp4",
fps=30, fps=30,
@ -172,4 +172,6 @@ def make_final_video(
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!")
print_step(f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}') print_step(
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}'
)

@ -1,6 +1,7 @@
import requests import requests
from os import makedirs from os import makedirs
from os import path
from fileinput import filename from fileinput import filename
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils import settings from utils import settings
@ -8,21 +9,30 @@ from pathlib import Path
# Checks if suboverlay is a thing, if not it downloads the file # Checks if suboverlay is a thing, if not it downloads the file
# Uses Google Drive Direct Link to store the file # Uses Google Drive Direct Link to store the file
# Source of the animation https://fortatelier.com/free-youtube-subscribe-animation-overlays/
def download_suboverlay(): def download_suboverlay():
if settings.config["settings"]["sub_overlay"]: if settings.config["settings"]["sub_overlay"]:
if Path(f"assets/subOverlay/subOverlayClip.mov").is_file(): URL = "https://drive.google.com/u/0/uc?id=16ajH0maciiWgWNgA-PNh29GZe9xqZmZR&export=download"
fileName = "youtube"
if settings.config["settings"]["sub_overlay_name"] == "tiktok":
URL = "https://drive.google.com/u/0/uc?id=1N7tmEacL5GSUpVukxwza7OL7ihfAdShq&export=download"
fileName = "tiktok"
if settings.config["settings"]["sub_overlay_name"] == "instagram":
URL = "https://drive.google.com/u/0/uc?id=19Yvuuojba8ixIP8whs0QEqw9gTer4T20&export=download"
fileName = "instagram"
if Path(f"assets/subOverlay/{fileName}.mov").is_file():
return return
#Generate path and folders #Generate path and folders
makedirs(f'assets/subOverlay') if not path.isdir(f'assets/subOverlay'):
makedirs(f'assets/subOverlay')
URL = "https://drive.google.com/u/0/uc?id=16ajH0maciiWgWNgA-PNh29GZe9xqZmZR&export=download"
print_step("We need to download the subscribe overlay, this only needs to be done once!") print_step("We need to download the subscribe overlay, this only needs to be done once!")
print_substep("Downloading subscribe overlay please wait....") print_substep("Downloading subscribe overlay please wait....")
subOverlayFile = requests.get(URL, verify=False) subOverlayFile = requests.get(URL, verify=False)
open(f'assets/subOverlay/subOverlayClip.mov', 'wb').write(subOverlayFile.content) open(f'assets/subOverlay/{fileName}.mov', 'wb').write(subOverlayFile.content)
print_substep("Subscribe overlay has been downloaded!", style="bold green") print_substep("Subscribe overlay has been downloaded!", style="bold green")

Loading…
Cancel
Save