@ -46,8 +46,12 @@ class ProgressFfmpeg(threading.Thread):
if lines :
for line in lines :
if " out_time_ms " in line :
out_time_ms = line . split ( " = " ) [ 1 ]
return int ( out_time_ms ) / 1000000.0
out_time_ms_str = line . split ( " = " ) [ 1 ] . strip ( )
if out_time_ms_str . isnumeric ( ) :
return float ( out_time_ms_str ) / 1000000.0
else :
# Handle the case when "N/A" is encountered
return None
return None
def stop ( self ) :
@ -72,7 +76,7 @@ def name_normalize(name: str) -> str:
lang = settings . config [ " reddit " ] [ " thread " ] [ " post_lang " ]
if lang :
print_substep ( " Translating filename... " )
translated_name = translators . google( name , to_language = lang )
translated_name = translators . translate_text( name , translator = " google " , to_language = lang )
return translated_name
else :
return name
@ -109,9 +113,7 @@ def merge_background_audio(audio: ffmpeg, reddit_id: str):
audio ( ffmpeg ) : The TTS final audio but without background .
reddit_id ( str ) : The ID of subreddit
"""
background_audio_volume = settings . config [ " settings " ] [ " background " ] [
" background_audio_volume "
]
background_audio_volume = settings . config [ " settings " ] [ " background " ] [ " background_audio_volume " ]
if background_audio_volume == 0 :
return audio # Return the original audio
else :
@ -165,42 +167,27 @@ def make_final_video(
if settings . config [ " settings " ] [ " storymode " ] :
if settings . config [ " settings " ] [ " storymodemethod " ] == 0 :
audio_clips = [ ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) ]
audio_clips . insert (
1 , ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/postaudio.mp3 " )
)
audio_clips . insert ( 1 , ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/postaudio.mp3 " ) )
elif settings . config [ " settings " ] [ " storymodemethod " ] == 1 :
audio_clips = [
ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/postaudio- { i } .mp3 " )
for i in track (
range ( number_of_clips + 1 ) , " Collecting the audio files... "
)
for i in track ( range ( number_of_clips + 1 ) , " Collecting the audio files... " )
]
audio_clips . insert (
0 , ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " )
)
audio_clips . insert ( 0 , ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) )
else :
audio_clips = [
ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/ { i } .mp3 " )
for i in range ( number_of_clips )
ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/ { i } .mp3 " ) for i in range ( number_of_clips )
]
audio_clips . insert ( 0 , ffmpeg . input ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) )
audio_clips_durations = [
float (
ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/ { i } .mp3 " ) [ " format " ] [
" duration "
]
)
float ( ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/ { i } .mp3 " ) [ " format " ] [ " duration " ] )
for i in range ( number_of_clips )
]
audio_clips_durations . insert (
0 ,
float (
ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) [ " format " ] [
" duration "
]
) ,
float ( ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) [ " format " ] [ " duration " ] ) ,
)
audio_concat = ffmpeg . concat ( * audio_clips , a = 1 , v = 0 )
ffmpeg . output (
@ -226,19 +213,13 @@ def make_final_video(
if settings . config [ " settings " ] [ " storymode " ] :
audio_clips_durations = [
float (
ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/postaudio- { i } .mp3 " ) [
" format "
] [ " duration " ]
ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/postaudio- { i } .mp3 " ) [ " format " ] [ " duration " ]
)
for i in range ( number_of_clips )
]
audio_clips_durations . insert (
0 ,
float (
ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) [ " format " ] [
" duration "
]
) ,
float ( ffmpeg . probe ( f " assets/temp/ { reddit_id } /mp3/title.mp3 " ) [ " format " ] [ " duration " ] ) ,
)
if settings . config [ " settings " ] [ " storymodemethod " ] == 0 :
image_clips . insert (
@ -248,16 +229,14 @@ def make_final_video(
) ,
)
background_clip = background_clip . overlay (
image_clips [ 1 ] ,
enable = f " between(t, { current_time } , { current_time + audio_clips_durations [ 1 ] } ) " ,
image_clips [ 0 ] ,
enable = f " between(t, { current_time } , { current_time + audio_clips_durations [ 0 ] } ) " ,
x = " (main_w-overlay_w)/2 " ,
y = " (main_h-overlay_h)/2 " ,
)
current_time + = audio_clips_durations [ 1 ]
current_time + = audio_clips_durations [ 0 ]
elif settings . config [ " settings " ] [ " storymodemethod " ] == 1 :
for i in track (
range ( 0 , number_of_clips + 1 ) , " Collecting the image files... "
) :
for i in track ( range ( 0 , number_of_clips + 1 ) , " Collecting the image files... " ) :
image_clips . append (
ffmpeg . input ( f " assets/temp/ { reddit_id } /png/img { i } .png " ) [ " v " ] . filter (
" scale " , screenshot_width , - 1
@ -273,9 +252,9 @@ def make_final_video(
else :
for i in range ( 0 , number_of_clips + 1 ) :
image_clips . append (
ffmpeg . input ( f " assets/temp/ { reddit_id } /png/comment_ { i } .png " ) [
" v"
]. filter ( " scale " , screenshot_width , - 1 )
ffmpeg . input ( f " assets/temp/ { reddit_id } /png/comment_ { i } .png " ) [ " v " ] . filter (
" scale" , screenshot_width , - 1
)
)
image_overlay = image_clips [ i ] . filter ( " colorchannelmixer " , aa = opacity )
background_clip = background_clip . overlay (
@ -294,15 +273,11 @@ def make_final_video(
subreddit = settings . config [ " reddit " ] [ " thread " ] [ " subreddit " ]
if not exists ( f " ./results/ { subreddit } " ) :
print_substep (
" The ' results ' folder could not be found so it was automatically created. "
)
print_substep ( " The ' results ' folder could not be found so it was automatically created. " )
os . makedirs ( f " ./results/ { subreddit } " )
if not exists ( f " ./results/ { subreddit } /OnlyTTS " ) and allowOnlyTTSFolder :
print_substep (
" The ' OnlyTTS ' folder could not be found so it was automatically created. "
)
print_substep ( " The ' OnlyTTS ' folder could not be found so it was automatically created. " )
os . makedirs ( f " ./results/ { subreddit } /OnlyTTS " )
# create a thumbnail for the video
@ -316,11 +291,7 @@ def make_final_video(
os . makedirs ( f " ./results/ { subreddit } /thumbnails " )
# get the first file with the .png extension from assets/backgrounds and use it as a background for the thumbnail
first_image = next (
(
file
for file in os . listdir ( " assets/backgrounds " )
if file . endswith ( " .png " )
) ,
( file for file in os . listdir ( " assets/backgrounds " ) if file . endswith ( " .png " ) ) ,
None ,
)
if first_image is None :
@ -342,9 +313,7 @@ def make_final_video(
title_thumb ,
)
thumbnailSave . save ( f " ./assets/temp/ { reddit_id } /thumbnail.png " )
print_substep (
f " Thumbnail - Building Thumbnail in assets/temp/ { reddit_id } /thumbnail.png "
)
print_substep ( f " Thumbnail - Building Thumbnail in assets/temp/ { reddit_id } /thumbnail.png " )
text = f " Background by { background_config [ ' video ' ] [ 2 ] } "
background_clip = ffmpeg . drawtext (
@ -373,6 +342,7 @@ def make_final_video(
path = (
path [ : 251 ] + " .mp4 "
) # Prevent a error by limiting the path length, do not change this.
try :
ffmpeg . output (
background_clip ,
final_audio ,
@ -390,6 +360,9 @@ def make_final_video(
capture_stdout = False ,
capture_stderr = False ,
)
except ffmpeg . Error as e :
print ( e . stderr . decode ( " utf8 " ) )
exit ( 1 )
old_percentage = pbar . n
pbar . update ( 100 - old_percentage )
if allowOnlyTTSFolder :