commit
a63dc9b695
Binary file not shown.
@ -0,0 +1,84 @@
|
||||
import requests
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def ffmpeg_install_windows():
|
||||
try:
|
||||
zip = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
|
||||
r = requests.get(zip)
|
||||
with open("ffmpeg.zip", "wb") as f:
|
||||
f.write(r.content)
|
||||
import zipfile
|
||||
|
||||
with zipfile.ZipFile("ffmpeg.zip", "r") as zip_ref:
|
||||
zip_ref.extractall()
|
||||
os.remove("ffmpeg.zip")
|
||||
os.rename("ffmpeg-master-latest-win64-gpl", "ffmpeg")
|
||||
# Move the files inside bin to the root
|
||||
for file in os.listdir("ffmpeg/bin"):
|
||||
os.rename(f"ffmpeg/bin/{file}", f"ffmpeg/{file}")
|
||||
os.rmdir("ffmpeg/bin")
|
||||
for file in os.listdir("ffmpeg/doc"):
|
||||
os.remove(f"ffmpeg/doc/{file}")
|
||||
os.rmdir("ffmpeg/doc")
|
||||
# Add to the path
|
||||
subprocess.run("setx /M PATH \"%PATH%;%CD%\\ffmpeg\"", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
print("FFmpeg installed successfully! Please restart your computer and then re-run the program.")
|
||||
exit()
|
||||
except Exception as e:
|
||||
print(
|
||||
"An error occurred while trying to install FFmpeg. Please try again. Otherwise, please install FFmpeg manually and try again.")
|
||||
print(e)
|
||||
exit()
|
||||
|
||||
|
||||
def ffmpeg_install_linux():
|
||||
try:
|
||||
subprocess.run("sudo apt install ffmpeg", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except Exception as e:
|
||||
print(
|
||||
"An error occurred while trying to install FFmpeg. Please try again. Otherwise, please install FFmpeg manually and try again.")
|
||||
print(e)
|
||||
exit()
|
||||
print("FFmpeg installed successfully! Please re-run the program.")
|
||||
exit()
|
||||
|
||||
|
||||
def ffmpeg_install_mac():
|
||||
try:
|
||||
subprocess.run("brew install ffmpeg", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except FileNotFoundError:
|
||||
print(
|
||||
"Homebrew is not installed. Please install it and try again. Otherwise, please install FFmpeg manually and try again.")
|
||||
exit()
|
||||
print("FFmpeg installed successfully! Please re-run the program.")
|
||||
exit()
|
||||
|
||||
|
||||
def ffmpeg_install():
|
||||
try:
|
||||
# Try to run the FFmpeg command
|
||||
subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
print('FFmpeg is installed on this system! If you are seeing this error for the second time, restart your computer.')
|
||||
except FileNotFoundError as e:
|
||||
print('FFmpeg is not installed on this system.')
|
||||
resp = input("We can try to automatically install it for you. Would you like to do that? (y/n): ")
|
||||
if resp.lower() == "y":
|
||||
print("Installing FFmpeg...")
|
||||
if os.name == "nt":
|
||||
ffmpeg_install_windows()
|
||||
elif os.name == "posix":
|
||||
ffmpeg_install_linux()
|
||||
elif os.name == "mac":
|
||||
ffmpeg_install_mac()
|
||||
else:
|
||||
print("Your OS is not supported. Please install FFmpeg manually and try again.")
|
||||
exit()
|
||||
else:
|
||||
print("Please install FFmpeg manually and try again.")
|
||||
exit()
|
||||
except Exception as e:
|
||||
print("Welcome fellow traveler! You're one of the few who have made it this far. We have no idea how you got at this error, but we're glad you're here. Please report this error to the developer, and we'll try to fix it as soon as possible. Thank you for your patience!")
|
||||
print(e)
|
||||
return None
|
@ -1,68 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Tuple
|
||||
|
||||
from PIL import ImageFont, Image, ImageDraw, ImageEnhance
|
||||
from moviepy.video.VideoClip import VideoClip, ImageClip
|
||||
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
||||
|
||||
|
||||
class Video:
|
||||
def __init__(self, video: VideoClip, *args, **kwargs):
|
||||
self.video: VideoClip = video
|
||||
self.fps = self.video.fps
|
||||
self.duration = self.video.duration
|
||||
|
||||
@staticmethod
|
||||
def _create_watermark(text, redditid, fontsize, opacity=0.5):
|
||||
id = re.sub(r"[^\w\s-]", "", redditid["thread_id"])
|
||||
path = f"./assets/temp/{id}/png/watermark.png"
|
||||
width = int(fontsize * len(text))
|
||||
height = int(fontsize * len(text) / 2)
|
||||
white = (255, 255, 255)
|
||||
transparent = (0, 0, 0, 0)
|
||||
|
||||
font = ImageFont.load_default()
|
||||
wm = Image.new("RGBA", (width, height), transparent)
|
||||
im = Image.new("RGBA", (width, height), transparent) # Change this line too.
|
||||
|
||||
draw = ImageDraw.Draw(wm)
|
||||
w, h = draw.textsize(text, font)
|
||||
draw.text(((width - w) / 2, (height - h) / 2), text, white, font)
|
||||
en = ImageEnhance.Brightness(wm) # todo allow it to use the fontsize
|
||||
mask = en.enhance(1 - opacity)
|
||||
im.paste(wm, (25, 25), mask)
|
||||
im.save(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,
|
||||
):
|
||||
compensation = round(
|
||||
(
|
||||
position[0]
|
||||
/ ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])
|
||||
),
|
||||
ndigits=2,
|
||||
)
|
||||
position = (compensation, position[1])
|
||||
# print(f'{compensation=}')
|
||||
# print(f'{position=}')
|
||||
img_clip = self._create_watermark(
|
||||
text, redditid, fontsize=fontsize, opacity=opacity
|
||||
)
|
||||
img_clip = img_clip.set_opacity(opacity).set_duration(duration)
|
||||
img_clip = img_clip.set_position(
|
||||
position, relative=True
|
||||
) # todo get dara from utils/CONSTANTS.py and adapt position accordingly
|
||||
|
||||
# Overlay the img clip on the first video clip
|
||||
self.video = CompositeVideoClip([self.video, img_clip])
|
||||
return self.video
|
Loading…
Reference in new issue