Skip to content

other

DarSelf module-attribute

DarSelf = TypeVar('DarSelf', bound=Dar)

SarSelf module-attribute

SarSelf = TypeVar('SarSelf', bound=Sar)

Dar

Bases: Fraction

A Fraction representing the Display Aspect Ratio.

This represents the dimensions of the physical display used to view the image. For more information, see https://en.wikipedia.org/wiki/Display_aspect_ratio.

from_size classmethod

from_size(
    width: int,
    height: int,
    sar: Sar | bool = True,
    /,
    func: FuncExceptT | None = ...,
) -> DarSelf
from_size(
    clip: VideoNode, sar: Sar | bool = True, /, func: FuncExceptT | None = ...
) -> DarSelf
from_size(
    clip_width: VideoNode | int,
    _height: int | Sar | bool = True,
    _sar: Sar | bool = True,
    /,
    func: FuncExceptT | None = None,
) -> DarSelf
Source code
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@classmethod
def from_size(
    cls: type[DarSelf],
    clip_width: vs.VideoNode | int,
    _height: int | Sar | bool = True,
    _sar: Sar | bool = True,
    /,
    func: FuncExceptT | None = None
) -> DarSelf:
    width: int
    height: int
    sar: Sar | Literal[False]

    if isinstance(clip_width, vs.VideoNode):
        from ..functions import check_variable_resolution

        check_variable_resolution(clip_width, func or cls.from_size)

        width, height, sar = clip_width.width, clip_width.height, _height  # type: ignore

        if sar is True:
            sar = Sar.from_clip(clip_width)  # type: ignore
    else:
        width, height, sar = clip_width, _height, _sar if isinstance(_sar, Sar) else False  # type: ignore

    gcd = max_common_div(width, height)

    if sar is False:
        sar = Sar(1, 1)

    return cls(width // gcd * sar.numerator, height // gcd * sar.denominator)

to_sar

to_sar(active_area: float, height: int) -> Sar

Convert the DAR to a SAR object.

Parameters:

  • active_area

    (float) –

    The active image area. For more information, see Sar.from_ar.

  • height

    (int) –

    The height of the image.

Returns:

  • Sar

    A SAR object created using the DAR.

Source code
134
135
136
137
138
139
140
141
142
143
def to_sar(self, active_area: float, height: int) -> Sar:
    """
    Convert the DAR to a SAR object.

    :param active_area:     The active image area. For more information, see ``Sar.from_ar``.
    :param height:          The height of the image.

    :return:                A SAR object created using the DAR.
    """
    return Sar.from_dar(self, active_area, height)

Direction

Bases: CustomIntEnum

Enum to simplify the direction argument.

DOWN class-attribute instance-attribute

DOWN = 5

HORIZONTAL class-attribute instance-attribute

HORIZONTAL = 0

LEFT class-attribute instance-attribute

LEFT = 2

RIGHT class-attribute instance-attribute

RIGHT = 3

UP class-attribute instance-attribute

UP = 4

VERTICAL class-attribute instance-attribute

VERTICAL = 1

is_axis property

is_axis: bool

Whether the Direction represents an axis (horizontal/vertical).

is_way property

is_way: bool

Whether the Direction is one of the 4 arrow directions.

string property

string: str

A string representation of the Direction.

Region

Bases: CustomStrEnum

StrEnum signifying an analog television region.

FILM class-attribute instance-attribute

FILM = 'FILM'

True 24fps content.

NTSC class-attribute instance-attribute

NTSC = 'NTSC'

The first American standard for analog television broadcast was developed by National Television System Committee (NTSC) in 1941.

For more information see this <https://en.wikipedia.org/wiki/NTSC>_.

NTSC_FILM class-attribute instance-attribute

NTSC_FILM = 'NTSC (FILM)'

NTSC 23.976fps content.

NTSCi class-attribute instance-attribute

NTSCi = 'NTSCi'

Interlaced NTSC.

PAL class-attribute instance-attribute

PAL = 'PAL'

Phase Alternating Line (PAL) colour encoding system.

For more information see this <https://en.wikipedia.org/wiki/PAL>_.

PALi class-attribute instance-attribute

PALi = 'PALi'

Interlaced PAL.

UNKNOWN class-attribute instance-attribute

UNKNOWN = 'unknown'

Unknown region.

framerate property

framerate: Fraction

Obtain the Region's framerate.

from_framerate classmethod

from_framerate(framerate: float | Fraction, strict: bool = False) -> Region

Determine the Region using a given framerate.

Source code
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
@classmethod
def from_framerate(cls, framerate: float | Fraction, strict: bool = False) -> Region:
    """Determine the Region using a given framerate."""

    key = Fraction(framerate)

    if strict:
        return _framerate_region_map[key]

    if key not in _framerate_region_map:
        diffs = [(k, abs(float(key) - float(v))) for k, v in _region_framerate_map.items()]

        diffs.sort(key=lambda x: x[1])

        return diffs[0][0]

    return _framerate_region_map[key]

Resolution

Bases: NamedTuple

Tuple representing a resolution.

height instance-attribute

height: int

width instance-attribute

width: int

from_video classmethod

from_video(clip: VideoNode) -> Resolution

Create a Resolution object using a given clip's dimensions.

Source code
294
295
296
297
298
299
300
301
302
@classmethod
def from_video(cls, clip: vs.VideoNode) -> Resolution:
    """Create a Resolution object using a given clip's dimensions."""

    from ..functions import check_variable_resolution

    assert check_variable_resolution(clip, cls.from_video)

    return Resolution(clip.width, clip.height)

transpose

transpose() -> Resolution

Flip the Resolution matrix over its diagonal.

Source code
304
305
306
307
def transpose(self) -> Resolution:
    """Flip the Resolution matrix over its diagonal."""

    return Resolution(self.height, self.width)

Sar

Bases: Fraction

A Fraction representing the Sample Aspect Ratio.

This represents the aspect ratio of the pixels or samples of an image. It may also be known as the Pixel Aspect Ratio in certain scenarios. For more information, see https://en.wikipedia.org/wiki/Pixel_aspect_ratio.

This is most useful for anamorphic content, and can allow you to ascertain the true aspect ratio. For more information, see: <https://web.archive.org/web/20140218044518/http://lipas.uwasa.fi/~f76998/video/conversion/#conversion_table>_

apply

apply(clip: VideoNode) -> VideoNode

Apply the SAR values as _SARNum and _SARDen frame properties to a clip.

Source code
208
209
210
211
def apply(self, clip: vs.VideoNode) -> vs.VideoNode:
    """Apply the SAR values as _SARNum and _SARDen frame properties to a clip."""

    return clip.std.SetFrameProps(_SARNum=self.numerator, _SARDen=self.denominator)

from_ar classmethod

Calculate the SAR from the given display aspect ratio and active image area. This method is used to obtain metadata to set in the video container for anamorphic video.

For a list of known standards, refer to the following tables: <https://web.archive.org/web/20140218044518/http://lipas.uwasa.fi/~f76998/video/conversion/#conversion_table>_

Parameters:

  • num

    (int) –

    The numerator.

  • den

    (int) –

    The denominator.

  • active_area

    (float) –

    The active image area.

  • height

    (int) –

    The height of the image.

Returns:

  • SarSelf

    A SAR object created using DAR and active image area information.

Source code
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@classmethod
def from_ar(cls: type[SarSelf], num: int, den: int, active_area: float, height: int) -> SarSelf:
    """
    Calculate the SAR from the given display aspect ratio and active image area.
    This method is used to obtain metadata to set in the video container for anamorphic video.

    For a list of known standards, refer to the following tables:
    `<https://web.archive.org/web/20140218044518/http://lipas.uwasa.fi/~f76998/video/conversion/#conversion_table>`_

    :param num:             The numerator.
    :param den:             The denominator.
    :param active_area:     The active image area.
    :param height:          The height of the image.

    :return:                A SAR object created using DAR and active image area information.
    """

    return cls(Dar(num, den).to_sar(active_area, height))

from_clip classmethod

from_clip(clip: HoldsPropValueT) -> SarSelf

Get the SAR from the clip's frame properties.

Parameters:

Returns:

  • SarSelf

    A SAR object of the SAR properties from the given clip.

Source code
162
163
164
165
166
167
168
169
170
171
172
173
174
@classmethod
def from_clip(cls: type[SarSelf], clip: HoldsPropValueT) -> SarSelf:
    """
    Get the SAR from the clip's frame properties.

    :param clip:        Clip or frame that holds the frame properties.

    :return:            A SAR object of the SAR properties from the given clip.
    """

    from ..utils import get_prop

    return cls(get_prop(clip, '_SARNum', int, None, 1), get_prop(clip, '_SARDen', int, None, 1))

from_dar classmethod

from_dar(dar: Dar, active_area: float, height: int) -> SarSelf

Calculate the SAR using a DAR object. See Dar.to_sar for more information.

Source code
195
196
197
198
199
200
201
202
203
204
205
206
@classmethod
def from_dar(cls: type[SarSelf], dar: Dar, active_area: float, height: int) -> SarSelf:
    """Calculate the SAR using a DAR object. See ``Dar.to_sar`` for more information."""

    sar_n, sar_d = dar.numerator * height, dar.denominator * active_area

    if isinstance(active_area, float):
        sar_n, sar_d = int(sar_n * 10000), int(sar_d * 10000)

    gcd = max_common_div(sar_n, sar_d)

    return cls(sar_n // gcd, sar_d // gcd)

SceneChangeMode

Bases: CustomIntEnum

Enum for various scene change modes.

SCXVID class-attribute instance-attribute

SCXVID = 2

Get the scene changes using the vapoursynth-scxvid plugin https://github.com/dubhater/vapoursynth-scxvid.

WWXD class-attribute instance-attribute

WWXD = 1

Get the scene changes using the vapoursynth-wwxd plugin https://github.com/dubhater/vapoursynth-wwxd.

WWXD_SCXVID_INTERSECTION class-attribute instance-attribute

WWXD_SCXVID_INTERSECTION = 0

Only get the scene changes if both wwxd and scxvid mark a frame as being a scene change.

WWXD_SCXVID_UNION class-attribute instance-attribute

WWXD_SCXVID_UNION = 3

Get every scene change detected by both wwxd or scxvid.

is_SCXVID property

is_SCXVID: bool

Check whether a mode that uses scxvid is used.

is_WWXD property

is_WWXD: bool

Check whether a mode that uses wwxd is used.

prop_keys property

prop_keys: Iterable[str]

check_cb

check_cb(akarin: bool | None = None) -> Callable[[VideoFrame], bool]
Source code
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def check_cb(self, akarin: bool | None = None) -> Callable[[vs.VideoFrame], bool]:
    if akarin is None:
        akarin = hasattr(vs.core, 'akarin')

    if akarin:
        return (lambda f: bool(f[0][0, 0]))

    keys = set(self.prop_keys)
    prop_key = next(iter(keys))

    if self is SceneChangeMode.WWXD_SCXVID_UNION:
        return (lambda f: any(f.props[key] == 1 for key in keys))

    if self is SceneChangeMode.WWXD_SCXVID_INTERSECTION:
        return (lambda f: all(f.props[key] == 1 for key in keys))

    return (lambda f: f.props[prop_key] == 1)

ensure_presence

ensure_presence(clip: VideoNode, akarin: bool | None = None) -> VideoNode

Ensures all the frame properties necessary for scene change detection are created.

Source code
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
def ensure_presence(self, clip: vs.VideoNode, akarin: bool | None = None) -> vs.VideoNode:
    """Ensures all the frame properties necessary for scene change detection are created."""

    from ..exceptions import CustomRuntimeError

    stats_clip = []

    if self.is_SCXVID:
        if not hasattr(vs.core, 'scxvid'):
            raise CustomRuntimeError(
                'You are missing scxvid!\n\tDownload it from https://github.com/dubhater/vapoursynth-scxvid',
                self.ensure_presence
            )
        stats_clip.append(clip.scxvid.Scxvid())

    if self.is_WWXD:
        if not hasattr(vs.core, 'wwxd'):
            raise CustomRuntimeError(
                'You are missing wwxd!\n\tDownload it from https://github.com/dubhater/vapoursynth-wwxd',
                self.ensure_presence
            )
        stats_clip.append(clip.wwxd.WWXD())

    return self._prepare_akarin(clip, stats_clip, akarin)

lambda_cb

lambda_cb(
    akarin: bool | None = None,
) -> Callable[[int, VideoFrame], Type | int]
Source code
397
398
399
def lambda_cb(self, akarin: bool | None = None) -> Callable[[int, vs.VideoFrame], Sentinel.Type | int]:
    callback = self.check_cb(akarin)
    return (lambda n, f: Sentinel.check(n, callback(f)))

prepare_clip

prepare_clip(
    clip: VideoNode, height: int | None = 360, akarin: bool | None = None
) -> VideoNode

Prepare a clip for scene change metric calculations.

The clip will always be resampled to YUV420 8bit if it's not already, as that's what the plugins support.

Parameters:

  • clip

    (VideoNode) –

    Clip to process.

  • height

    (int | None, default: 360 ) –

    Output height of the clip. Smaller frame sizes are faster to process, but may miss more scene changes or introduce more false positives. Width is automatically calculated. None means no resizing operation is performed. Default: 360.

  • akarin

    (bool | None, default: None ) –

    Use the akarin plugin for speed optimizations. None means it will check if its available, and if it is, use it. Default: None.

Returns:

  • VideoNode

    A prepared clip for performing scene change metric calculations on.

Source code
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
def prepare_clip(self, clip: vs.VideoNode, height: int | None = 360, akarin: bool | None = None) -> vs.VideoNode:
    """
    Prepare a clip for scene change metric calculations.

    The clip will always be resampled to YUV420 8bit if it's not already,
    as that's what the plugins support.

    :param clip:        Clip to process.
    :param height:      Output height of the clip. Smaller frame sizes are faster to process,
                        but may miss more scene changes or introduce more false positives.
                        Width is automatically calculated. `None` means no resizing operation is performed.
                        Default: 360.
    :param akarin:      Use the akarin plugin for speed optimizations. `None` means it will check if its available,
                        and if it is, use it. Default: None.

    :return:            A prepared clip for performing scene change metric calculations on.
    """
    from ..utils import get_w

    if height is not None:
        clip = clip.resize.Bilinear(get_w(height, clip), height, vs.YUV420P8)
    elif not clip.format or (clip.format and clip.format.id != vs.YUV420P8):
        clip = clip.resize.Bilinear(format=vs.YUV420P8)

    return self.ensure_presence(clip, akarin)