Skip to content

Commit

Permalink
Fix 296 filter output name (#297)
Browse files Browse the repository at this point in the history
* align script

* fix #296 add return name
  • Loading branch information
lucemia authored Feb 20, 2024
1 parent 141d5e9 commit 21d656f
Show file tree
Hide file tree
Showing 10 changed files with 704 additions and 730 deletions.
28 changes: 14 additions & 14 deletions scripts/code_gen/templates/_components.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
{% endif %}
{% if f.is_input_dynamic %}
{% if f.is_input_type_mixed %}
*streams: "FilterableStream",
*streams: FilterableStream,
{% elif f.filter_type.value in ["vf", "vaf"] %}
*streams: "VideoStream",
*streams: VideoStream,
{% elif f.filter_type.value in ["af", "avf"] %}
*streams: "AudioStream",
*streams: AudioStream,
{% endif %}
{% elif f.input_stream_typings | length == 1 %}
{% else %}
{% for stream_typing in f.input_stream_typings %}
{% if type == "method" and loop.index0 == 0 %}
{% elif stream_typing.type.value == "video" %}
{{ stream_typing.name | stream_name_safe }}: "VideoStream",
{{ stream_typing.name | stream_name_safe }}: VideoStream,
{% else %}
{{ stream_typing.name | stream_name_safe }}: "AudioStream",
{{ stream_typing.name | stream_name_safe }}: AudioStream,
{% endif %}
{% endfor %}
{% endif %}
Expand Down Expand Up @@ -62,14 +62,14 @@ Default("nan")
{%- if f.is_output_dynamic -%}
-> FilterNode:
{%- elif f.output_stream_typings | length == 1 -%}
-> "{{ return_type }}":
-> {{ return_type }}:
{%- else -%}
-> tuple[
{% for stream_typing in f.output_stream_typings %}
{% if stream_typing.type.value == "video" %}
"VideoStream",
VideoStream,
{% else %}
"AudioStream",
AudioStream,
{% endif %}
{% endfor %}
]:
Expand All @@ -86,13 +86,13 @@ Args:
{% endif %}
Returns:
{%- if f.is_output_dynamic %}
the filter node
filter_node: the filter node
{% else -%}
{% for stream_tpying in f.output_stream_typings %}
{%- if stream_tpying.type.value == "video" %}
the video stream
{% for stream_typing in f.output_stream_typings %}
{%- if stream_typing.type.value == "video" %}
{{ stream_typing.name}}: the video stream
{%- else %}
the audio stream
{{ stream_typing.name}}: the audio stream
{%- endif -%}
{%- endfor %}
{%- endif %}
Expand Down Expand Up @@ -139,7 +139,7 @@ filter_node = FilterNode(
inputs=(
{{ stream_params(f, type) }}
),
kwargs=to_tuple(({
kwargs=_to_tuple(({
{% for option in f.options %}
"{{ option.name}}": {{ option.name | option_name_safe }},
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion scripts/code_gen/templates/filters.py.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Literal

from .dag.nodes import FilterNode, FilterableStream
from .schema import Default, StreamType, to_tuple
from .schema import Default, StreamType, _to_tuple
from .types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from .streams.video import VideoStream
from .streams.audio import AudioStream
Expand Down
12 changes: 1 addition & 11 deletions scripts/code_gen/templates/streams/audio.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import re
from typing import TYPE_CHECKING, Any, Literal

from ..dag.nodes import FilterableStream, FilterNode
from ..schema import Default, StreamType, to_tuple
from ..schema import Default, StreamType, _to_tuple
from ..types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from ..utils.typing import override
from .channel_layout import CHANNEL_LAYOUT
Expand All @@ -16,16 +16,6 @@ if TYPE_CHECKING:


class AudioStream(FilterableStream):
@property
@override
def video(self) -> "VideoStream":
raise NotImplementedError("This stream does not have a video component")

@property
@override
def audio(self) -> "AudioStream":
return AudioStream(node=self.node, selector=StreamType.audio, index=self.index)

{% for f in filters %}
{% if f.filter_type.value in ["af", "avf"] and not f.is_input_dynamic %}
{{ _components.filter_method(f) }}
Expand Down
12 changes: 1 addition & 11 deletions scripts/code_gen/templates/streams/video.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import re
from typing import TYPE_CHECKING, Any, Literal

from ..dag.nodes import FilterableStream, FilterNode
from ..schema import Default, StreamType, to_tuple
from ..schema import Default, StreamType, _to_tuple
from ..types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from ..utils.typing import override

Expand All @@ -16,16 +16,6 @@ if TYPE_CHECKING:


class VideoStream(FilterableStream):
@property
@override
def video(self) -> "VideoStream":
return VideoStream(node=self.node, index=self.index, selector=StreamType.video)

@property
@override
def audio(self) -> "AudioStream":
raise NotImplementedError("Cannot convert video to audio")

{% for f in filters %}
{% if f.filter_type.value in ["vf", "vaf"] and not f.is_input_dynamic %}
{{ _components.filter_method(f) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import re
from typing import TYPE_CHECKING, Any, Literal

from ..dag.nodes import FilterableStream, FilterNode
from ..schema import Default, StreamType, to_tuple
from ..schema import Default, StreamType, _to_tuple
from ..types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from ..utils.typing import override
from .channel_layout import CHANNEL_LAYOUT
Expand Down Expand Up @@ -109,7 +109,7 @@ References:


),
kwargs=to_tuple(({
kwargs=_to_tuple(({

"order": order,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Literal

from .dag.nodes import FilterNode, FilterableStream
from .schema import Default, StreamType, to_tuple
from .schema import Default, StreamType, _to_tuple
from .types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from .streams.video import VideoStream
from .streams.audio import AudioStream
Expand Down Expand Up @@ -93,7 +93,7 @@ References:


),
kwargs=to_tuple(({
kwargs=_to_tuple(({

"order": order,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import re
from typing import TYPE_CHECKING, Any, Literal

from ..dag.nodes import FilterableStream, FilterNode
from ..schema import Default, StreamType, to_tuple
from ..schema import Default, StreamType, _to_tuple
from ..types import Boolean, Duration, Color, Flags, Dictionary, Pix_fmt, Int, Int64, Double, Float, String, Video_rate, Image_size, Rational, Sample_fmt, Binary
from ..utils.typing import override

Expand Down
Loading

0 comments on commit 21d656f

Please sign in to comment.