Skip to content

Commit

Permalink
add custom filter test case (#282)
Browse files Browse the repository at this point in the history
* add custom filter test case

* fix
  • Loading branch information
lucemia authored Feb 16, 2024
1 parent b6671c1 commit efa6e71
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
36 changes: 30 additions & 6 deletions src/ffmpeg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def vfilter(
Note:
This function is for custom filter which is not implemented in typed-ffmpeg
"""
return FilterNode(name=name, inputs=streams, input_typings=input_typings, kwargs=tuple(kwargs.items())).video(0)
return FilterNode(
name=name,
inputs=streams,
output_typings=(StreamType.video,),
input_typings=input_typings,
kwargs=tuple(kwargs.items()),
).video(0)


def afilter(
Expand All @@ -93,10 +99,22 @@ def afilter(
Note:
This function is for custom filter which is not implemented in typed-ffmpeg
"""
return FilterNode(name=name, inputs=streams, input_typings=input_typings, kwargs=tuple(kwargs.items())).audio(0)


def filter_multi_output(*streams: FilterableStream, name: str, **kwargs: Any) -> FilterNode:
return FilterNode(
name=name,
inputs=streams,
output_typings=(StreamType.audio,),
input_typings=input_typings,
kwargs=tuple(kwargs.items()),
).audio(0)


def filter_multi_output(
*streams: FilterableStream,
name: str,
input_typings: tuple[StreamType, ...] = (),
output_tyings: tuple[StreamType, ...] = (),
**kwargs: Any
) -> FilterNode:
"""
Apply a custom filter which has multiple outputs to this stream
Expand All @@ -111,4 +129,10 @@ def filter_multi_output(*streams: FilterableStream, name: str, **kwargs: Any) ->
Note:
This function is for custom filter which is not implemented in typed-ffmpeg
"""
return FilterNode(name=name, kwargs=tuple(kwargs.items()), inputs=streams)
return FilterNode(
name=name,
kwargs=tuple(kwargs.items()),
inputs=streams,
input_typings=input_typings,
output_typings=output_tyings,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"ffmpeg",
"-i",
"input.mp4",
"-filter_complex",
"[0][0]gltransition=duration=1:offset=0.5:direction=left[s0]",
"-map",
"[s0]",
"output.mp4"
]
20 changes: 19 additions & 1 deletion src/ffmpeg/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from syrupy.assertion import SnapshotAssertion
from syrupy.extensions.json import JSONSnapshotExtension

from ..base import input, merge_outputs, output
from ffmpeg.schema import StreamType

from ..base import input, merge_outputs, output, vfilter
from ..filters import concat, join
from ..streams.video import VideoStream

Expand Down Expand Up @@ -149,3 +151,19 @@ def test_concat_dumuxer(snapshot: SnapshotAssertion) -> None:
)

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


def test_customize_vfilter(snapshot: SnapshotAssertion) -> None:
in_file = input("input.mp4")

gltransition = vfilter(
in_file,
in_file,
name="gltransition",
duration=1,
offset=0.5,
direction="left",
input_typings=(StreamType.video, StreamType.video),
)

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

0 comments on commit efa6e71

Please sign in to comment.