99
1010logger = logging .getLogger (__name__ )
1111
12- logger .setLevel (logging .DEBUG )
13-
1412FFMPEG_BIN = "ffmpeg"
1513IMAGEMAGICK_BIN = "convert"
1614FRAMERATE = 50
1715LOUD_LEVEL = - 23
1816
1917# Paths relative to app root
20- TEMP_DIR = Path ("temp/" )
21- OUT_DIR = Path ("static/video/output" )
22- LOG_DIR = Path ("logs/" )
23- RESOURCE_DIR = Path ("resources/" )
18+ TEMP_DIR = Path ("temp/" ). resolve ()
19+ OUT_DIR = Path ("static/video/output" ). resolve ()
20+ LOG_DIR = Path ("logs/" ). resolve ()
21+ RESOURCE_DIR = Path ("resources/" ). resolve ()
2422
25- FONT_PATH = Path ("resources/Raleway.ttf" )
23+ FONT_PATH = Path .joinpath (RESOURCE_DIR , Path ("Raleway.ttf" ))
24+ BKGD_FILE = Path .joinpath (RESOURCE_DIR , Path ("BG_V3_LC_Shaded.mp4" ))
25+ TRANSP_FILE = Path .joinpath (RESOURCE_DIR , Path ("transparent.png" ))
26+ LOGO_FILE = Path .joinpath (RESOURCE_DIR , Path ("logo.svg" ))
27+ SPONS_FILE = Path .joinpath (RESOURCE_DIR , Path ("sponsor_slide_rounded.png" ))
2628
2729def timecode_split (timecode , framerate = FRAMERATE ):
2830 splits = timecode .split (":" )
@@ -52,12 +54,13 @@ def timecode_to_timestamp(timecode, framerate = FRAMERATE):
5254
5355def form_video (video , talk , start_tc , end_tc , framerate = FRAMERATE , out_dir = OUT_DIR , temp_dir = TEMP_DIR ):
5456
57+ temp_dir = Path (temp_dir ).resolve ()
58+ out_dir = Path (out_dir ).resolve ()
59+
5560 video = Path (video )
5661
5762 working_dir = video .parent
5863
59- logger .info (working_dir )
60-
6164 # Timing information
6265 end_dur = 10 # How long to hold the endslate for
6366 end_fade_in = 2
@@ -76,13 +79,7 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
7679 col_pres = "#2eadd9"
7780 col_bkg = "#00000000" #"#21301850"
7881
79- # Resource files
80- bkgd_file = "/data/hackyplayer/resources/BG_V3_LC_Shaded.mp4"
81- transp_file = "/data/hackyplayer/resources/transparent.png"
82- logo_file = "/data/hackyplayer/resources/logo.svg"
83- spons_file = "/data/hackyplayer/resources/sponsor_slide_rounded.png"
84-
85- # Generated files paths
82+ # Generated file names
8683 copr_file = "copyright.png"
8784 spres_file = "start_pres.png"
8885 stalk_file = "start_title.png"
@@ -154,13 +151,13 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
154151 with open (log_path , "a" ) as error_log :
155152
156153 # Build all the text assets
157- logger .info ("Building text assets" )
158- subprocess .run (start_title_args )
159- subprocess .run (start_pres_arg )
160- subprocess .run (copyright_args )
154+ logger .info ("Building text assets. " )
155+ subprocess .check_output (start_title_args )
156+ subprocess .check_output (start_pres_arg )
157+ subprocess .check_output (copyright_args )
161158
162159 # First FFmpeg pass for getting loudness stats
163- logger .info ("Detecting loudness information" )
160+ logger .info ("Detecting loudness information. " )
164161 logger .debug (ffmpeg_loudness_args )
165162 analysis = subprocess .check_output (ffmpeg_loudness_args , stderr = subprocess .STDOUT , cwd = working_dir ).decode ("utf-8" ).split ("\n " )
166163
@@ -190,12 +187,12 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
190187 ffmpeg_args = [
191188 FFMPEG_BIN ,
192189 "-ss" , start_ts , "-to" , end_ts , "-i" , video .name , #0
193- "-stream_loop" , "-1" , "-r" , str (framerate ), "-i" , bkgd_file , #1
194- "-loop" , "1" , "-framerate" , str (framerate ), "-i" , transp_file , #2
190+ "-stream_loop" , "-1" , "-r" , str (framerate ), "-i" , BKGD_FILE , #1
191+ "-loop" , "1" , "-framerate" , str (framerate ), "-i" , TRANSP_FILE , #2
195192 "-loop" , "1" , "-framerate" , str (framerate ), "-i" , spres_file , #3
196193 "-loop" , "1" , "-framerate" , str (framerate ), "-i" , stalk_file , #4
197- "-loop" , "1" , "-framerate" , str (framerate ), "-i" , logo_file , #5
198- "-loop" , "1" , "-framerate" , str (framerate ), "-i" , spons_file , #6
194+ "-loop" , "1" , "-framerate" , str (framerate ), "-i" , LOGO_FILE , #5
195+ "-loop" , "1" , "-framerate" , str (framerate ), "-i" , SPONS_FILE , #6
199196 "-loop" , "1" , "-framerate" , str (framerate ), "-i" , copr_file , #7
200197 "-filter_complex" , ("[0:a]afade=in:d={in_:.2f},afade=out:st={out_st:.2f}:d={out:.2f},adelay={title_end:.2f}:all=1," .format (in_ = afade_in , out = afade_out , out_st = afade_offset , spn_dur = spn_dur , title_end = title_end * 1000 ) +
201198 "loudnorm=I={target:.2f}:TP=-1.5:measured_I={mI}:measured_tp={mTP}:measured_LRA={mLRA}:measured_thresh={mTH}:offset={off}:linear=true:print_format=json[a1];" .format (
@@ -226,9 +223,10 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
226223 "-c:a" , "aac" , "-ar" , "48000" , "-b:a" , "128k" ,
227224 "-r" , str (framerate ), "-pix_fmt" , "yuv420p" , "-movflags" , "+faststart" , output_path , "-y"
228225 ]
229- logger .info ("Running main build" )
226+ logger .info ("Running main build. " )
230227 logger .debug (ffmpeg_args )
231- subprocess .run (ffmpeg_args , stderr = error_log , cwd = working_dir )
228+ subprocess .check_output (ffmpeg_args , stderr = error_log , cwd = working_dir )
229+ logger .info ("Completed main build." )
232230
233231 return str (output_path )
234232
0 commit comments