pull/262/head
Lewis Menelaws 3 years ago
parent 5336c35ae8
commit 94bf8ef1b4

BIN
.DS_Store vendored

Binary file not shown.

@ -2,3 +2,5 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
GOOGLE_APPLICATION_CREDENTIALS=""

@ -18,10 +18,10 @@ reddit_object = get_askreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background() video_id = download_background()
chop_background_video(length) chop_background_video(length, video_id)
final_video = make_final_video(number_of_comments) final_video = make_final_video(number_of_comments)
cleanup() # cleanup()
print_markdown( print_markdown(
"### File saved at assets/final_video.mp4 🎉. If you enjoyed this, make sure to give us a star on GitHub! 🌟" "### File saved at assets/final_video.mp4 🎉. If you enjoyed this, make sure to give us a star on GitHub! 🌟"

@ -1,9 +1,10 @@
from random import randrange from random import randrange, choice
from pytube import YouTube from pytube import YouTube
from pathlib import Path from pathlib import Path
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from urllib import parse
def get_start_and_end_times(video_length, length_of_clip): def get_start_and_end_times(video_length, length_of_clip):
@ -18,29 +19,36 @@ def download_background():
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8) Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
""" """
# List of choices for the background video # List of choices for the background video
background_choices = ["https://www.youtube.com/watch?v=n_Dv4JMiwK8"] background_choices = [
"https://www.youtube.com/watch?v=n_Dv4JMiwK8",
"https://www.youtube.com/watch?v=oCtokDlLbCU",
]
if not Path("assets/mp4/background.mp4").is_file(): video_id = parse.parse_qs(parse.urlsplit(choice(background_choices)).query)["v"][0]
if not Path(f"assets/mp4/{video_id}.mp4").is_file():
print_step( print_step(
"We need to download the Minecraft background video. This is fairly large but it's only done once. 😎" "We need to download the Minecraft background video. This is fairly large but it's only done once. 😎"
) )
print_substep("Downloading the background video... please be patient 🙏") print_substep("Downloading the background video... please be patient 🙏")
YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8").streams.filter( YouTube(f"https://www.youtube.com/watch?v={video_id}").streams.filter(
res="720p" res="720p"
).first().download( ).first().download(
"assets/mp4", "assets/mp4",
filename="background.mp4", filename=f"{video_id}.mp4",
) )
print_substep("Background video downloaded successfully! 🎉", style="bold green") print_substep("Background video downloaded successfully! 🎉", style="bold green")
return video_id
def chop_background_video(video_length): def chop_background_video(video_length, video_id):
print_step("Finding a spot in the background video to chop...✂️") print_step("Finding a spot in the background video to chop...✂️")
background = VideoFileClip("assets/mp4/background.mp4") background = VideoFileClip(f"assets/mp4/{video_id}.mp4")
start_time, end_time = get_start_and_end_times(video_length, background.duration) start_time, end_time = get_start_and_end_times(video_length, background.duration)
ffmpeg_extract_subclip( ffmpeg_extract_subclip(
"assets/mp4/background.mp4", f"assets/mp4/{video_id}.mp4",
start_time, start_time,
end_time, end_time,
targetname="assets/mp4/clip.mp4", targetname="assets/mp4/clip.mp4",

@ -14,50 +14,52 @@ W, H = 1080, 1920
def make_final_video(number_of_clips): def make_final_video(number_of_clips):
print_step("Creating the final video 🎥") try:
VideoFileClip.reW = lambda clip: clip.resize(width=W) print_step("Creating the final video 🎥")
VideoFileClip.reH = lambda clip: clip.resize(width=H) VideoFileClip.reW = lambda clip: clip.resize(width=W)
VideoFileClip.reH = lambda clip: clip.resize(width=H)
background_clip = (
VideoFileClip("assets/mp4/clip.mp4") background_clip = VideoFileClip("assets/mp4/clip.mp4").without_audio()
.without_audio()
.resize(height=H) if background_clip.w > background_clip.h:
.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) background_clip.resize(height=H).crop(x1=1166.6, y1=0, x2=2246.6, y2=1920)
)
# Gather all audio clips # Gather all audio clips
audio_clips = [] audio_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3"))
audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3"))
audio_concat = concatenate_audioclips(audio_clips) audio_concat = concatenate_audioclips(audio_clips)
audio_composite = CompositeAudioClip([audio_concat]) audio_composite = CompositeAudioClip([audio_concat])
# Gather all images # Gather all images
image_clips = [] image_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
image_clips.append( image_clips.append(
ImageClip(f"assets/png/comment_{i}.png") ImageClip(f"assets/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration) .set_duration(audio_clips[i + 1].duration)
.set_position("center")
.resize(width=background_clip.w - (background_clip.w * 0.05)),
)
image_clips.insert(
0,
ImageClip(f"assets/png/title.png")
.set_duration(audio_clips[0].duration)
.set_position("center") .set_position("center")
.resize(width=W - 100), .resize(width=background_clip.w - (background_clip.w * 0.05)),
)
image_concat = concatenate_videoclips(
image_clips, method="compose"
).set_position(("center", 0.3), relative=True)
image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat])
final.write_videofile(
"assets/final_video.mp4",
fps=30,
audio_codec="aac",
audio_bitrate="192k",
preset="ultrafast",
) )
image_clips.insert( print_substep("WOOHOO! Video is saved at assets/final_video.mp4 🎉")
0, except Exception as e:
ImageClip(f"assets/png/title.png") print(e)
.set_duration(audio_clips[0].duration)
.set_position("center")
.resize(width=W - 100),
)
image_concat = concatenate_videoclips(image_clips, method="compose").set_position(
("center", 0.3), relative=True
)
image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat])
final.write_videofile(
"assets/final_video.mp4",
fps=30,
audio_codec="aac",
audio_bitrate="192k",
preset="ultrafast",
)
print_substep("WOOHOO! Video is saved at assets/final_video.mp4 🎉")

Loading…
Cancel
Save