2 samples with backgroundMusic and without it

pull/1590/head
Lucas 2 years ago
parent 5a103e76cd
commit 1abfc4b321

@ -34,7 +34,7 @@ resolution_h = { optional = false, default = 1920, example = 2560, explantation
[settings.background] [settings.background]
background_video = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } background_video = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" }
background_audio = { optional = true, type = "bool", default = false, example = false, options = ["minecraft","lofi"], explanation = "Sets a audio to play in the background (put a background.mp3 file in the assets/backgrounds directory for it to be used.)" } background_audio = { optional = true, default = "lofi", example = "minecraft", options = ["minecraft","lofi","undertale"], explanation = "Sets a audio to play in the background (put a background.mp3 file in the assets/backgrounds directory for it to be used.)" }
background_audio_volume = { optional = true, type = "float", default = 0.1, example = 0.05, explanation="Sets the volume of the background audio. Warning: if you set more than 1.0, the volume will be increased" } background_audio_volume = { optional = true, type = "float", default = 0.1, example = 0.05, explanation="Sets the volume of the background audio. Warning: if you set more than 1.0, the volume will be increased" }
background_thumbnail = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Generate a thumbnail for the video (put a thumbnail.png file in the assets/backgrounds directory.)" } background_thumbnail = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Generate a thumbnail for the video (put a thumbnail.png file in the assets/backgrounds directory.)" }
background_thumbnail_font_family = { optional = true, default = "arial", example = "arial", explanation = "Font family for the thumbnail text" } background_thumbnail_font_family = { optional = true, default = "arial", example = "arial", explanation = "Font family for the thumbnail text" }

@ -98,16 +98,18 @@ def download_background_audio(background_config: Tuple[str, str, str]):
) )
print_substep("Downloading the backgrounds audio... please be patient 🙏 ") print_substep("Downloading the backgrounds audio... please be patient 🙏 ")
print_substep(f"Downloading {filename} from {uri}") print_substep(f"Downloading {filename} from {uri}")
YouTube(uri, on_progress_callback=on_progress).streams.filter(only_audio=True).first().download("assets/backgrounds/audio", filename=f"{credit}-{filename}") YouTube(uri, on_progress_callback=on_progress).streams.filter(
only_audio=True
).first().download("assets/backgrounds/audio", filename=f"{credit}-{filename}")
print_substep("Background audio downloaded successfully! 🎉", style="bold green") print_substep("Background audio downloaded successfully! 🎉", style="bold green")
def chop_background( def chop_background(
background_config: Dict[str,Tuple[str, str, str, Any]], video_length: int, reddit_object: dict background_config: Dict[str,Tuple], video_length: int, reddit_object: dict
): ):
"""Generates the background footage to be used in the video and writes it to assets/temp/background.mp4 """Generates the background audio and footage to be used in the video and writes it to assets/temp/background.mp3 and assets/temp/background.mp4
Args: Args:
background_config (Tuple[str, str, str, Any]) : Current background configuration background_config (Dict[str,Tuple]]) : Current background configuration
video_length (int): Length of the clip where the background footage is to be taken out of video_length (int): Length of the clip where the background footage is to be taken out of
""" """
@ -119,10 +121,12 @@ def chop_background(
background_audio = AudioFileClip(f"assets/backgrounds/audio/{audio_choice}") background_audio = AudioFileClip(f"assets/backgrounds/audio/{audio_choice}")
start_time_video, end_time_video = get_start_and_end_times(video_length, background_video.duration) start_time_video, end_time_video = get_start_and_end_times(video_length, background_video.duration)
start_time_audio, end_time_audio = get_start_and_end_times(video_length, background_audio.duration) start_time_audio, end_time_audio = get_start_and_end_times(video_length, background_audio.duration)
background_audio = background_audio.fx(afx.volumex,0.07) # Create a audio clip
background_audio_volume = settings.config["settings"]["background"][f"background_audio_volume"]
background_audio = background_audio.fx(afx.volumex,background_audio_volume)
background_audio = background_audio.subclip(start_time_audio,end_time_audio) background_audio = background_audio.subclip(start_time_audio,end_time_audio)
background_audio.write_audiofile(f"assets/temp/{id}/background.mp3") background_audio.write_audiofile(f"assets/temp/{id}/background.mp3")
background_video.set_audio(background_audio) #background_video.set_audio(background_audio)
try: try:

@ -108,7 +108,7 @@ def make_final_video(
number_of_clips: int, number_of_clips: int,
length: int, length: int,
reddit_obj: dict, reddit_obj: dict,
background_config: Dict[str,Tuple[str, str, str, Any]], background_config: Dict[str,Tuple],
): ):
"""Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp
Args: Args:
@ -263,6 +263,10 @@ def make_final_video(
print_substep("The results folder didn't exist so I made it") print_substep("The results folder didn't exist so I made it")
os.makedirs(f"./results/{subreddit}") os.makedirs(f"./results/{subreddit}")
if not exists(f"./results/{subreddit}/{filename}"):
print_substep("The results folder didn't exist so I made it")
os.makedirs(f"./results/{subreddit}/{filename}")
# create a thumbnail for the video # create a thumbnail for the video
settingsbackground = settings.config["settings"]["background"] settingsbackground = settings.config["settings"]["background"]
@ -324,13 +328,32 @@ def make_final_video(
path = f"results/{subreddit}/{filename}" path = f"results/{subreddit}/{filename}"
path = path[:251] path = path[:251]
path = path + ".mp4" #path = path + ".mp4"
with ProgressFfmpeg(length, on_update_example) as progress: with ProgressFfmpeg(length, on_update_example) as progress:
ffmpeg.output( ffmpeg.output(
background_clip, background_clip,
final_audio, final_audio,
path, path+f"/{filename}.mp4",
f="mp4",
**{
"c:v": "h264",
"b:v": "20M",
"b:a": "192k",
"threads": multiprocessing.cpu_count(),
},
).overwrite_output().global_args("-progress", progress.output_file.name).run(
quiet=True,
overwrite_output=True,
capture_stdout=False,
capture_stderr=False,
)
with ProgressFfmpeg(length, on_update_example) as progress:
ffmpeg.output(
background_clip,
audio,
path+"/NoBackgroundAudio.mp4",
f="mp4", f="mp4",
**{ **{
"c:v": "h264", "c:v": "h264",

Loading…
Cancel
Save