| 1 |
from enum import IntEnum |
| 2 |
from pathlib import Path |
| 3 |
from typing import Any, Union |
| 4 |
|
| 5 |
import numpy as np |
| 6 |
|
| 7 |
from av.frame import Frame |
| 8 |
|
| 9 |
from .format import VideoFormat |
| 10 |
from .plane import VideoPlane |
| 11 |
from .reformatter import ColorPrimaries, ColorTrc |
| 12 |
|
| 13 |
_SupportedNDarray = Union[ |
| 14 |
np.ndarray[Any, np.dtype[np.uint8]], |
| 15 |
np.ndarray[Any, np.dtype[np.uint16]], |
| 16 |
np.ndarray[Any, np.dtype[np.float16]], |
| 17 |
np.ndarray[Any, np.dtype[np.float32]], |
| 18 |
] |
| 19 |
|
| 20 |
supported_np_pix_fmts: set[str] |
| 21 |
|
| 22 |
class PictureType(IntEnum): |
| 23 |
NONE = 0 |
| 24 |
I = 1 |
| 25 |
P = 2 |
| 26 |
B = 3 |
| 27 |
S = 4 |
| 28 |
SI = 5 |
| 29 |
SP = 6 |
| 30 |
BI = 7 |
| 31 |
|
| 32 |
class CudaContext: |
| 33 |
@property |
| 34 |
def device_id(self) -> int: ... |
| 35 |
@property |
| 36 |
def primary_ctx(self) -> bool: ... |
| 37 |
def __init__(self, device_id: int = 0, primary_ctx: bool = True) -> None: ... |
| 38 |
|
| 39 |
class VideoFrame(Frame): |
| 40 |
format: VideoFormat |
| 41 |
planes: tuple[VideoPlane, ...] |
| 42 |
pict_type: int |
| 43 |
colorspace: int |
| 44 |
color_range: int |
| 45 |
color_trc: int |
| 46 |
color_primaries: int |
| 47 |
|
| 48 |
@property |
| 49 |
def time(self) -> float: ... |
| 50 |
@property |
| 51 |
def width(self) -> int: ... |
| 52 |
@property |
| 53 |
def height(self) -> int: ... |
| 54 |
@property |
| 55 |
def interlaced_frame(self) -> bool: ... |
| 56 |
@property |
| 57 |
def rotation(self) -> int: ... |
| 58 |
def __init__( |
| 59 |
self, width: int = 0, height: int = 0, format: str = "yuv420p" |
| 60 |
) -> None: ... |
| 61 |
def reformat( |
| 62 |
self, |
| 63 |
width: int | None = None, |
| 64 |
height: int | None = None, |
| 65 |
format: str | None = None, |
| 66 |
src_colorspace: str | int | None = None, |
| 67 |
dst_colorspace: str | int | None = None, |
| 68 |
interpolation: int | str | None = None, |
| 69 |
src_color_range: int | str | None = None, |
| 70 |
dst_color_range: int | str | None = None, |
| 71 |
dst_color_trc: int | ColorTrc | None = None, |
| 72 |
dst_color_primaries: int | ColorPrimaries | None = None, |
| 73 |
threads: int | None = None, |
| 74 |
) -> VideoFrame: ... |
| 75 |
def to_rgb(self, **kwargs: Any) -> VideoFrame: ... |
| 76 |
def save(self, filepath: str | Path) -> None: ... |
| 77 |
def to_image(self, **kwargs): ... |
| 78 |
def to_ndarray( |
| 79 |
self, channel_last: bool = False, **kwargs: Any |
| 80 |
) -> _SupportedNDarray: ... |
| 81 |
@staticmethod |
| 82 |
def from_image(img): ... |
| 83 |
@staticmethod |
| 84 |
def from_numpy_buffer( |
| 85 |
array: _SupportedNDarray, format: str = "rgb24", width: int = 0 |
| 86 |
) -> VideoFrame: ... |
| 87 |
@staticmethod |
| 88 |
def from_ndarray( |
| 89 |
array: _SupportedNDarray, format: str = "rgb24", channel_last: bool = False |
| 90 |
) -> VideoFrame: ... |
| 91 |
@staticmethod |
| 92 |
def from_bytes( |
| 93 |
data: bytes, |
| 94 |
width: int, |
| 95 |
height: int, |
| 96 |
format: str = "rgba", |
| 97 |
flip_horizontal: bool = False, |
| 98 |
flip_vertical: bool = False, |
| 99 |
) -> VideoFrame: ... |
| 100 |
@staticmethod |
| 101 |
def from_dlpack( |
| 102 |
planes: object | tuple[object, ...], |
| 103 |
format: str = "nv12", |
| 104 |
width: int = 0, |
| 105 |
height: int = 0, |
| 106 |
stream: int | None = None, |
| 107 |
device_id: int | None = None, |
| 108 |
primary_ctx: bool = True, |
| 109 |
cuda_context: CudaContext | None = None, |
| 110 |
) -> VideoFrame: ... |