Skip to content

Commit

Permalink
fix #349 auto input variable (#368)
Browse files Browse the repository at this point in the history
* fix #349 auto input variable

* add list-all utils in cache

* fix concat filter

* add test case for auto

* fix concat's schema

* update test case

* update test case

* remove not used code
  • Loading branch information
lucemia authored Mar 15, 2024
1 parent 298c2ef commit b3d6dc1
Show file tree
Hide file tree
Showing 88 changed files with 323 additions and 229 deletions.
9 changes: 7 additions & 2 deletions src/ffmpeg/common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class FFMpegIOType:
class FFMpegFilterDef:
name: str

typings_input: str | tuple[Literal["video", "audio"], ...]
typings_output: str | tuple[Literal["video", "audio"], ...]
typings_input: str | tuple[Literal["video", "audio"], ...] = ()
typings_output: str | tuple[Literal["video", "audio"], ...] = ()


@dataclass(frozen=True, kw_only=True)
Expand All @@ -107,8 +107,13 @@ class FFMpegFilter:
formula_typings_input: str | None = None
formula_typings_output: str | None = None

pre: tuple[tuple[str, str], ...] = ()
options: tuple[FFMpegFilterOption, ...] = ()

@property
def pre_dict(self) -> dict[str, str]:
return dict(self.pre)

@property
def to_def(self) -> FFMpegFilterDef:
return FFMpegFilterDef(
Expand Down
7 changes: 6 additions & 1 deletion src/ffmpeg/common/tests/__snapshots__/test_serialize.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@
"__class__": "ffmpeg.streams.video.VideoStream",
"node": {
"__class__": "ffmpeg.dag.nodes.FilterNode",
"kwargs": [],
"kwargs": [
[
"n",
2
]
],
"inputs": [
{
"__class__": "ffmpeg.streams.video.VideoStream",
Expand Down
4 changes: 4 additions & 0 deletions src/ffmpeg/dag/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from typing import Any

from ..common.schema import FFMpegFilterDef, StreamType
from ..schema import Auto
from ..utils.run import _to_tuple
from .nodes import FilterableStream, FilterNode


def filter_node_factory(filter: FFMpegFilterDef, *inputs: FilterableStream, **kwargs: Any) -> FilterNode:
for k, v in kwargs.items():
if isinstance(v, Auto):
kwargs[k] = eval(v, {"StreamType": StreamType, "re": re, **kwargs, "streams": inputs})

if isinstance(filter.typings_input, str):
input_typings = tuple(eval(filter.typings_input, {"StreamType": StreamType, "re": re, **kwargs}))
Expand Down
10 changes: 10 additions & 0 deletions src/ffmpeg/dag/tests/__snapshots__/test_factory.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# serializer version: 1
# name: test_filter_node_factory
FilterNode(kwargs=(('n', 0),), inputs=(), name='foo', input_typings=(), output_typings=())
# ---
# name: test_filter_node_factory.1
FilterNode(kwargs=(('n', 1),), inputs=(VideoStream(node=InputNode(kwargs=(), inputs=(), filename='foo.mp4'), index=None),), name='foo', input_typings=(<StreamType.video: 'video'>,), output_typings=())
# ---
# name: test_filter_node_factory.2
FilterNode(kwargs=(('n', 2),), inputs=(VideoStream(node=InputNode(kwargs=(), inputs=(), filename='foo.mp4'), index=None), VideoStream(node=InputNode(kwargs=(), inputs=(), filename='foo.mp4'), index=None)), name='foo', input_typings=(<StreamType.video: 'video'>, <StreamType.video: 'video'>), output_typings=())
# ---
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"[0:v][1:v]",
"concat",
"concat=",
"n=2",
"[s0]"
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -n -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -n -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -y -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -y -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"ffmpeg -y -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat[s0]' -map '[s0]' output.mp4"
"ffmpeg -y -i tmp1.mp4 -i tmp2.mp4 -filter_complex '[0:v][1:v]concat=n=2[s0]' -map '[s0]' output.mp4"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"-i",
"tmp2.mp4",
"-filter_complex",
"[0:v][1:v]concat[s0]",
"[0:v][1:v]concat=n=2[s0]",
"-map",
"[s0]",
"output.mp4"
Expand Down
Loading

0 comments on commit b3d6dc1

Please sign in to comment.