Blacken the code base.

This commit is contained in:
yrriban 2025-12-24 18:35:43 -05:00
parent d585c1529d
commit 07d079f204
19 changed files with 138 additions and 168 deletions

View file

@ -34,12 +34,10 @@ class Concat(dcc.doom_base.Wad):
+ f"to{parsed_args.end_map}"
)
output = av.open(
self.fabricate.joinpath(parsed_args.wad).joinpath(
f"{fn_base}.mp4"), "w"
self.fabricate.joinpath(parsed_args.wad).joinpath(f"{fn_base}.mp4"), "w"
)
summary_file = open(
self.fabricate.joinpath(parsed_args.wad).joinpath(
f"{fn_base}.txt"), "w"
self.fabricate.joinpath(parsed_args.wad).joinpath(f"{fn_base}.txt"), "w"
)
self._offset = 0
@ -66,11 +64,13 @@ class Concat(dcc.doom_base.Wad):
start_time = self._offset / 1000000
text = self._add_chunk(
videodir.joinpath(f"{parsed_args.wad}_map{idx}.mp4"),
output, not parsed_args.nooverlay
output,
not parsed_args.nooverlay,
)
list.append(
summary, f"{text} {math.floor(start_time / 60):02}:"
+ f"{math.floor(start_time % 60):02}"
summary,
f"{text} {math.floor(start_time / 60):02}:"
+ f"{math.floor(start_time % 60):02}",
)
if state == State.DONE:
break
@ -82,8 +82,7 @@ class Concat(dcc.doom_base.Wad):
def _add_chunk(self, v, output, overlay):
chunk = av.open(v)
if not (len(chunk.streams.video) == 1
and len(chunk.streams.audio) == 1):
if not (len(chunk.streams.video) == 1 and len(chunk.streams.audio) == 1):
raise Exception(
f"irregular chunk {v}: streams {chunk.streams} "
+ f"(expected 1 video & 1 audio)"
@ -96,16 +95,11 @@ class Concat(dcc.doom_base.Wad):
text = ""
if overlay:
img = wand.image.Image(
height=chunk.streams[0].height,
width=chunk.streams[0].width
height=chunk.streams[0].height, width=chunk.streams[0].width
)
mapstring = v.name[-6:-4]
text = self._config["map_names"][f"map{mapstring}"]
self.draw_text(
img,
f"MAP{mapstring}: {text}",
font_size=120
)
self.draw_text(img, f"MAP{mapstring}: {text}", font_size=120)
img.trim(reset_coords=True)
img.border("graya(25%, 25%)", 10, 10)
img.border(self.thumbnail_text_stroke, 16, 16)
@ -113,17 +107,14 @@ class Concat(dcc.doom_base.Wad):
# multiple of 8. dude whyyyyyyy
padfactor = 8
img.border("transparent", padfactor, 0)
img.crop(
width=img.width - img.width % padfactor,
height=img.height
)
img.crop(width=img.width - img.width % padfactor, height=img.height)
if len(output.streams.get()) == 0:
# We can't use the input stream as a template here; it doesn't
# have everything needed to do encoding and will fail
# mysteriously later.
vs = chunk.streams.video[0]
vr = int(vs.time_base.denominator/vs.time_base.numerator)
vr = int(vs.time_base.denominator / vs.time_base.numerator)
ovs = output.add_stream("h264", rate=vr)
ovs.extradata = copy.deepcopy(vs.extradata)
ovs.height = vs.height
@ -145,12 +136,10 @@ class Concat(dcc.doom_base.Wad):
oas.bit_rate = astr.bit_rate
src = ograph.add_buffer(
template=chunk.streams.video[0],
time_base=chunk.streams.video[0].time_base
template=chunk.streams.video[0], time_base=chunk.streams.video[0].time_base
)
asrc = ograph.add_abuffer(
template=chunk.streams.audio[0],
time_base=chunk.streams.audio[0].time_base
template=chunk.streams.audio[0], time_base=chunk.streams.audio[0].time_base
)
# TODO: video fades are absolute relative to the input video; audio
# fades need to have their timestamps offset by the position in the
@ -163,19 +152,18 @@ class Concat(dcc.doom_base.Wad):
iafade_start = self._offset * sample_rate / 1000000
iafade = ograph.add("afade", args=f"in:{iafade_start}:{sample_rate}")
oafade_start = (
(self._offset + chunk.duration) * sample_rate / 1000000
- sample_rate
)
self._offset + chunk.duration
) * sample_rate / 1000000 - sample_rate
oafade = ograph.add("afade", args=f"out:{oafade_start}:{sample_rate}")
if overlay:
overlay = ograph.add_buffer(
width=img.width, height=img.height,
format="rgba", time_base=chunk.streams.video[0].time_base
)
overlay_fo = ograph.add(
"fade", args=f"out:{4 * frame_rate}:{frame_rate}"
width=img.width,
height=img.height,
format="rgba",
time_base=chunk.streams.video[0].time_base,
)
overlay_fo = ograph.add("fade", args=f"out:{4 * frame_rate}:{frame_rate}")
overlay.link_to(overlay_fo, 0, 0)
composite = ograph.add("overlay", args="x=4:y=4")
src.link_to(composite, 0, 0)
@ -194,9 +182,8 @@ class Concat(dcc.doom_base.Wad):
for packet in chunk.demux():
if packet.dts is None:
continue
pof = (
(self._offset * packet.time_base.denominator)
/ (packet.time_base.numerator * 1000000)
pof = (self._offset * packet.time_base.denominator) / (
packet.time_base.numerator * 1000000
)
packet.dts += pof
packet.pts += pof
@ -221,9 +208,7 @@ class Concat(dcc.doom_base.Wad):
def _make_text_frame(self, img, ifr):
# We need to give each frame its own memory it can own.
text_frame = av.video.frame.VideoFrame(
img.width, img.height, format="rgba"
)
text_frame = av.video.frame.VideoFrame(img.width, img.height, format="rgba")
text_frame.planes[0].update(img.make_blob(format="rgba"))
text_frame.pts = ifr.pts
text_frame.dts = ifr.dts