Skip to content

Commit 02b84fe

Browse files
committed
Camp changes
1 parent a8610fa commit 02b84fe

5 files changed

Lines changed: 10684 additions & 5538 deletions

File tree

formvideo.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
FRAMERATE = 50
1717
LOUD_LEVEL = -23
1818

19+
# Paths relative to app root
1920
TEMP_DIR = Path("temp/")
2021
OUT_DIR = Path("static/video/output")
2122
LOG_DIR = Path("logs/")
23+
RESOURCE_DIR = Path("resources/")
24+
25+
FONT_PATH = Path("resources/Raleway.ttf")
2226

2327
def timecode_split(timecode, framerate = FRAMERATE):
24-
2528
splits = timecode.split(":")
2629
hours = int(splits[0])
2730
minutes = int(splits[1])
@@ -35,6 +38,7 @@ def timecode_split(timecode, framerate = FRAMERATE):
3538

3639
return (hours, minutes, seconds, frames)
3740

41+
3842
def timecode_to_seconds(timecode, framerate = FRAMERATE):
3943
hours,minutes,seconds,frames = timecode_split(timecode, framerate)
4044

@@ -48,6 +52,12 @@ def timecode_to_timestamp(timecode, framerate = FRAMERATE):
4852

4953
def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = OUT_DIR, temp_dir = TEMP_DIR):
5054

55+
video = Path(video)
56+
57+
working_dir = video.parent
58+
59+
logger.info(working_dir)
60+
5161
# Timing information
5262
end_dur = 10 # How long to hold the endslate for
5363
end_fade_in = 2
@@ -67,10 +77,10 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
6777
col_bkg = "#00000000" #"#21301850"
6878

6979
# Resource files
70-
bkgd_file = "resources/BG_V3.mp4"
71-
transp_file = "resources/transparent.png"
72-
logo_file = "resources/logo.svg"
73-
spons_file = "resources/sponsor_slide_rounded.png"
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"
7484

7585
# Generated files paths
7686
copr_file = "copyright.png"
@@ -85,7 +95,7 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
8595

8696
# Calculate some other reused variables
8797
fade_offset = end_s - start_s - (end_fade_in/2.)
88-
afade_offset = fade_offset - (afade_out/2.) # When to fade out the main talk audio
98+
afade_offset = fade_offset - (afade_out) # When to fade out the main talk audio
8999
eb_end = fade_offset + end_dur #
90100
end_tdur = end_dur + end_fade # Total duration of the endslate, including fade time
91101
title_end = spn_dur + title_dur
@@ -113,30 +123,30 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
113123
start_title_args = [
114124
IMAGEMAGICK_BIN,
115125
"-size", "1800x300", "-background", "#00000000",
116-
"-fill", col_talk, "-gravity", "center", "caption:{}".format(talk["title"]),
126+
"-fill", col_talk, "-gravity", "center", "-font", str(FONT_PATH), "caption:{}".format(talk["title"]),
117127
"(", "+clone", "-shadow", "500x2+0+0", ")", "+swap", "-background", col_bkg, "-layers", "merge", "+repage",
118128
stalk_file
119129
]
120130

121131
start_pres_arg = [
122132
IMAGEMAGICK_BIN,
123133
"-size", "1800x256", "-background", "#00000000",
124-
"-fill", col_pres, "-gravity", "center", "caption:{}".format(talk["presenter"]),
134+
"-fill", col_pres, "-gravity", "center", "-font", str(FONT_PATH), "caption:{}".format(talk["presenter"]),
125135
"(", "+clone", "-shadow", "500x2+0+0", ")", "+swap", "-background", col_bkg, "-layers", "merge", "+repage",
126136
spres_file
127137
]
128138

129139
copyright_args = [
130140
IMAGEMAGICK_BIN,
131141
"-size", "1000x256", "-background", "#00000000",
132-
"-fill", "#2eadd9", "-gravity", "east", "caption:{}".format(lic_text),
142+
"-fill", "#2eadd9", "-gravity", "east", "-font", str(FONT_PATH), "caption:{}".format(lic_text),
133143
"(", "+clone", "-shadow", "500x2+0+0", ")", "+swap", "-background", col_bkg, "-layers", "merge", "+repage",
134144
copr_file
135145
]
136146

137147
ffmpeg_loudness_args = [
138148
FFMPEG_BIN,
139-
"-ss", start_ts, "-to", end_ts, "-i", video,
149+
"-ss", start_ts, "-to", end_ts, "-i", video.name,
140150
"-filter_complex", "[0:a]afade=in:d={in_:.2f},afade=out:st={out_st:.2f}:d={out:.2f},loudnorm=print_format=json".format(in_ = afade_in, out = afade_out, out_st = afade_offset),
141151
"-f", "null", "-"
142152
]
@@ -152,7 +162,7 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
152162
# First FFmpeg pass for getting loudness stats
153163
logger.info("Detecting loudness information")
154164
logger.debug(ffmpeg_loudness_args)
155-
analysis = subprocess.check_output(ffmpeg_loudness_args, stderr=subprocess.STDOUT).decode("utf-8").split("\n")
165+
analysis = subprocess.check_output(ffmpeg_loudness_args, stderr=subprocess.STDOUT, cwd=working_dir).decode("utf-8").split("\n")
156166

157167
json_detect = False
158168
json_string = ""
@@ -179,7 +189,7 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
179189
# Run the final build FFmpeg
180190
ffmpeg_args = [
181191
FFMPEG_BIN,
182-
"-ss", start_ts, "-to", end_ts, "-i", video, #0
192+
"-ss", start_ts, "-to", end_ts, "-i", video.name, #0
183193
"-stream_loop", "-1", "-r", str(framerate), "-i", bkgd_file, #1
184194
"-loop", "1", "-framerate", str(framerate), "-i", transp_file, #2
185195
"-loop", "1", "-framerate", str(framerate), "-i", spres_file, #3
@@ -218,7 +228,7 @@ def form_video(video, talk, start_tc, end_tc, framerate = FRAMERATE, out_dir = O
218228
]
219229
logger.info("Running main build")
220230
logger.debug(ffmpeg_args)
221-
subprocess.run(ffmpeg_args, stderr=error_log)
231+
subprocess.run(ffmpeg_args, stderr=error_log, cwd=working_dir)
222232

223233
return str(output_path)
224234

@@ -231,6 +241,7 @@ def ingest_video(input_path, output_dir, framerate = FRAMERATE):
231241
ffmpeg_args = [
232242
FFMPEG_BIN,
233243
"-i", input_path,
244+
"-vf", "bwdif",
234245
"-c:v", "h264", "-crf", "12", "-g", str(math.floor(framerate/2)), "-flags", "+cgop", "-s", "1920x1080",
235246
#"-c:v", "h264_nvenc", "-b:v", "12M",
236247
"-c:a", "aac", "-ar", "48000", "-b:a", "128k",
@@ -265,4 +276,4 @@ def ingest_video(input_path, output_dir, framerate = FRAMERATE):
265276
"presenter": "Kim M"
266277
}
267278

268-
form_video("static/video/stage_a/bbb_50.mp4", talk_data, "00:05:05:00", "00:05:20:00")
279+
form_video("static/video/stagea/bbb_sunflower_2160p_60fps_normal.mp4", talk_data, "00:05:05:00", "00:05:20:00", out_dir=Path("/mnt/vid_working/output"))

resources/BG_V3_LC_Shaded.mp4

751 KB
Binary file not shown.

resources/Raleway.ttf

1.81 MB
Binary file not shown.

0 commit comments

Comments
 (0)