Support excluding the overlay from concatenated videos.
This commit is contained in:
parent
b62e9ebbf9
commit
8c1d031def
1 changed files with 32 additions and 26 deletions
|
@ -13,6 +13,7 @@ class Concat(dcc.doom_base.Wad):
|
||||||
parser = super().get_parser(prog_name)
|
parser = super().get_parser(prog_name)
|
||||||
parser.add_argument("start_map")
|
parser.add_argument("start_map")
|
||||||
parser.add_argument("end_map")
|
parser.add_argument("end_map")
|
||||||
|
parser.add_argument("-n", "--nooverlay", action="store_true")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
@ -38,19 +39,20 @@ class Concat(dcc.doom_base.Wad):
|
||||||
sink = ograph.add("buffersink")
|
sink = ograph.add("buffersink")
|
||||||
asink = ograph.add("abuffersink")
|
asink = ograph.add("abuffersink")
|
||||||
|
|
||||||
img = wand.image.Image(height=chunk.streams[0].height,width=chunk.streams[0].width)
|
if not parsed_args.nooverlay:
|
||||||
mapstring = v.name[-6:-4]
|
img = wand.image.Image(height=chunk.streams[0].height,width=chunk.streams[0].width)
|
||||||
text = self._config["map_names"][f"map{mapstring}"]
|
mapstring = v.name[-6:-4]
|
||||||
dcc.text.draw_text(img, f"MAP{mapstring}: {text}", font_size=120)
|
text = self._config["map_names"][f"map{mapstring}"]
|
||||||
img.trim(reset_coords=True)
|
dcc.text.draw_text(img, f"MAP{mapstring}: {text}", font_size=120)
|
||||||
img.border("graya(25%, 25%)", 10, 10)
|
img.trim(reset_coords=True)
|
||||||
img.border(dcc.config.TEXT_STROKE_COLOR, 16, 16)
|
img.border("graya(25%, 25%)", 10, 10)
|
||||||
# for this to work... the image needs to have a width that's a multiple
|
img.border(dcc.config.TEXT_STROKE_COLOR, 16, 16)
|
||||||
# of 8. dude whyyyyyyy
|
# for this to work... the image needs to have a width that's a multiple
|
||||||
padfactor=8
|
# of 8. dude whyyyyyyy
|
||||||
img.border("transparent", padfactor, 0)
|
padfactor=8
|
||||||
img.crop(width=img.width-img.width%padfactor, height=img.height)
|
img.border("transparent", padfactor, 0)
|
||||||
text_frame = av.video.frame.VideoFrame(img.width, img.height, format="rgba")
|
img.crop(width=img.width-img.width%padfactor, height=img.height)
|
||||||
|
text_frame = av.video.frame.VideoFrame(img.width, img.height, format="rgba")
|
||||||
|
|
||||||
if len(output.streams.get()) == 0:
|
if len(output.streams.get()) == 0:
|
||||||
# TODO: less hardcoding.
|
# TODO: less hardcoding.
|
||||||
|
@ -72,17 +74,20 @@ class Concat(dcc.doom_base.Wad):
|
||||||
output.streams[1].bit_rate=chunk.streams[1].bit_rate
|
output.streams[1].bit_rate=chunk.streams[1].bit_rate
|
||||||
src = ograph.add_buffer(template=chunk.streams[0], time_base=chunk.streams[0].time_base)
|
src = ograph.add_buffer(template=chunk.streams[0], time_base=chunk.streams[0].time_base)
|
||||||
asrc = ograph.add_abuffer(template=chunk.streams[1], time_base=chunk.streams[1].time_base)
|
asrc = ograph.add_abuffer(template=chunk.streams[1], time_base=chunk.streams[1].time_base)
|
||||||
overlay = ograph.add_buffer(width=img.width, height=img.height, format="rgba", time_base=chunk.streams[0].time_base)
|
|
||||||
overlay_fo = ograph.add("fade", args="out:240:60")
|
|
||||||
overlay.link_to(overlay_fo, 0, 0)
|
|
||||||
composite = ograph.add("overlay", args="x=4:y=4")
|
|
||||||
src.link_to(composite, 0, 0)
|
|
||||||
overlay_fo.link_to(composite, 0, 1)
|
|
||||||
ifade = ograph.add("fade", args="in:0:60")
|
ifade = ograph.add("fade", args="in:0:60")
|
||||||
iafade = ograph.add("afade", args="in:{}:48000".format(offset*48000/1000000))
|
iafade = ograph.add("afade", args="in:{}:48000".format(offset*48000/1000000))
|
||||||
ofade = ograph.add("fade", args="out:{}:60".format((chunk.duration*60/1000000)-60))
|
ofade = ograph.add("fade", args="out:{}:60".format((chunk.duration*60/1000000)-60))
|
||||||
oafade = ograph.add("afade", args="out:{}:48000".format(((offset+chunk.duration)*48000/1000000)-48000))
|
oafade = ograph.add("afade", args="out:{}:48000".format(((offset+chunk.duration)*48000/1000000)-48000))
|
||||||
composite.link_to(ifade, 0, 0)
|
if not parsed_args.nooverlay:
|
||||||
|
overlay = ograph.add_buffer(width=img.width, height=img.height, format="rgba", time_base=chunk.streams[0].time_base)
|
||||||
|
overlay_fo = ograph.add("fade", args="out:240:60")
|
||||||
|
overlay.link_to(overlay_fo, 0, 0)
|
||||||
|
composite = ograph.add("overlay", args="x=4:y=4")
|
||||||
|
src.link_to(composite, 0, 0)
|
||||||
|
overlay_fo.link_to(composite, 0, 1)
|
||||||
|
composite.link_to(ifade, 0, 0)
|
||||||
|
else:
|
||||||
|
src.link_to(ifade, 0, 0)
|
||||||
asrc.link_to(iafade, 0, 0)
|
asrc.link_to(iafade, 0, 0)
|
||||||
ifade.link_to(ofade, 0, 0)
|
ifade.link_to(ofade, 0, 0)
|
||||||
iafade.link_to(oafade, 0, 0)
|
iafade.link_to(oafade, 0, 0)
|
||||||
|
@ -97,12 +102,13 @@ class Concat(dcc.doom_base.Wad):
|
||||||
packet.pts += (offset * packet.time_base.denominator) / (packet.time_base.numerator * 1000000)
|
packet.pts += (offset * packet.time_base.denominator) / (packet.time_base.numerator * 1000000)
|
||||||
if packet.stream_index == 0: # TODO: robustness
|
if packet.stream_index == 0: # TODO: robustness
|
||||||
for ifr in packet.decode():
|
for ifr in packet.decode():
|
||||||
text_frame = av.video.frame.VideoFrame(img.width, img.height, format="rgba")
|
if not parsed_args.nooverlay:
|
||||||
text_frame.planes[0].update(img.make_blob(format="rgba"))
|
text_frame = av.video.frame.VideoFrame(img.width, img.height, format="rgba")
|
||||||
text_frame.pts = ifr.pts
|
text_frame.planes[0].update(img.make_blob(format="rgba"))
|
||||||
text_frame.dts = ifr.dts
|
text_frame.pts = ifr.pts
|
||||||
text_frame.time_base = ifr.time_base
|
text_frame.dts = ifr.dts
|
||||||
overlay.push(text_frame)
|
text_frame.time_base = ifr.time_base
|
||||||
|
overlay.push(text_frame)
|
||||||
src.push(ifr)
|
src.push(ifr)
|
||||||
ofr = sink.pull()
|
ofr = sink.pull()
|
||||||
for p in output.streams[packet.stream_index].encode(ofr):
|
for p in output.streams[packet.stream_index].encode(ofr):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue