diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 75c5e4e..b4074d7 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -34,7 +34,7 @@ resolution_h = { optional = false, default = 1920, example = 2560, explantation [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_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_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" } diff --git a/video_creation/background.py b/video_creation/background.py index 4919519..36400b2 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -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(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") 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: - 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 """ @@ -119,10 +121,12 @@ def chop_background( 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_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.write_audiofile(f"assets/temp/{id}/background.mp3") - background_video.set_audio(background_audio) + #background_video.set_audio(background_audio) try: diff --git a/video_creation/final_video.py b/video_creation/final_video.py index c0e7ad7..89187ca 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -108,7 +108,7 @@ def make_final_video( number_of_clips: int, length: int, 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 Args: @@ -262,6 +262,10 @@ def make_final_video( if not exists(f"./results/{subreddit}"): print_substep("The results folder didn't exist so I made it") 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 settingsbackground = settings.config["settings"]["background"] @@ -324,13 +328,32 @@ def make_final_video( path = f"results/{subreddit}/{filename}" path = path[:251] - path = path + ".mp4" + #path = path + ".mp4" with ProgressFfmpeg(length, on_update_example) as progress: ffmpeg.output( background_clip, 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", **{ "c:v": "h264",