Skip to content

Commit

Permalink
Fix #258 map label (#259)
Browse files Browse the repository at this point in the history
* add test case

* fix #258 map label for input node
  • Loading branch information
lucemia authored Feb 6, 2024
1 parent 5f4876d commit 5050b53
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/ffmpeg/dag/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def __post_init__(self) -> None:

@override
def get_args(self, context: _DAGContext = empty_dag_context) -> list[str]:
incoming_labels = "".join(k.label(context) for k in self.inputs)
incoming_labels = "".join(f"[{k.label(context)}]" for k in self.inputs)
outputs = context.get_outgoing_streams(self)

outgoing_labels = ""
for output in sorted(outputs, key=lambda stream: stream.index or 0):
# NOTE: all outgoing streams must be filterable
assert isinstance(output, FilterableStream)
outgoing_labels += output.label(context)
outgoing_labels += f"[{output.label(context)}]"

commands = []
for key, value in self.kwargs:
Expand Down Expand Up @@ -233,14 +233,14 @@ def label(self, context: _DAGContext) -> str:
):
# NOTE: if the node has only one output, we don't need to specify the index
if self.selector:
return f"[{context.get_node_label(self.node)}:{selector}]"
return f"{context.get_node_label(self.node)}:{selector}"
else:
return f"[{context.get_node_label(self.node)}]"
return f"{context.get_node_label(self.node)}"
else:
if self.selector:
return f"[{context.get_node_label(self.node)}#{self.index}:{selector}]"
return f"{context.get_node_label(self.node)}#{self.index}:{selector}"
else:
return f"[{context.get_node_label(self.node)}#{self.index}]"
return f"{context.get_node_label(self.node)}#{self.index}"

def view(self) -> str:
from ..utils.view import view
Expand Down Expand Up @@ -371,7 +371,10 @@ def get_args(self, context: _DAGContext = empty_dag_context) -> list[str]:
# !handle mapping
commands = []
for input in self.inputs:
commands += ["-map", input.label(context)]
if isinstance(input.node, InputNode):
commands += ["-map", input.label(context)]
else:
commands += ["-map", f"[{input.label(context)}]"]

for key, value in self.kwargs:
if isinstance(value, bool) and value is True:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"-i",
"/path/to/jpegs/*.jpg",
"-map",
"[0]",
"0",
"movie.mp4"
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"-i",
"input2.mp4",
"-map",
"[0]",
"0",
"output1.mp4",
"-map",
"[1]",
"1",
"output2.mp4"
]
14 changes: 14 additions & 0 deletions src/ffmpeg/tests/__snapshots__/test_base/test_concat_dumuxer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"ffmpeg",
"-f",
"concat",
"-safe",
"0",
"-protocol_whitelist",
"file,http,https,tcp,tls",
"-i",
"input1.mp4",
"-map",
"0",
"output.mp4"
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"-map",
"[s4]",
"-map",
"[2:v]",
"2:v",
"-shortest",
"-vcodec",
"copy",
Expand Down
11 changes: 11 additions & 0 deletions src/ffmpeg/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,14 @@ def test_compile_merge_outputs_with_filter_complex(snapshot: SnapshotAssertion)
output2 = output(splitted.video(1), filename="output2.mp4")

assert snapshot(extension_class=JSONSnapshotExtension) == (merge_outputs(output1, output2).compile())


def test_concat_dumuxer(snapshot: SnapshotAssertion) -> None:
stream = input(
"input1.mp4",
f="concat",
safe="0",
protocol_whitelist="file,http,https,tcp,tls",
)

assert snapshot(extension_class=JSONSnapshotExtension) == (stream.output(filename="output.mp4").compile())

0 comments on commit 5050b53

Please sign in to comment.