Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 94546f0

Browse files
committed
fixed typing for python <v3.9
1 parent f529a6f commit 94546f0

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ package_dir=
3131
=src
3232
install_requires =
3333
ffmpegio-core
34-
numpy
34+
numpy >= 1.20
3535
python_requires = >=3.7,
3636
packages=ffmpegio_plugin_numpy
3737

src/ffmpegio_plugin_numpy/__init__.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import numpy as np
44
from pluggy import HookimplMarker
5+
from typing import Tuple
6+
7+
from numpy.typing import ArrayLike
58

69
hookimpl = HookimplMarker("ffmpegio")
710

@@ -16,84 +19,84 @@
1619

1720

1821
@hookimpl
19-
def video_info(obj: object) -> tuple[tuple[int, int, int], str]:
22+
def video_info(obj: ArrayLike) -> Tuple[Tuple[int, int, int], str]:
2023
"""get video frame info
2124
22-
:param obj: object containing video frame data with arbitrary number of frames
23-
:type obj: object
24-
:return: shape (height,width,components) and data type in numpy dtype str expression
25-
:rtype: tuple[tuple[int, int, int], str]
25+
:param obj: video frame data with arbitrary number of frames
26+
:type obj: ArrayLike
27+
:return: shape (height,width,components) and data type str
28+
:rtype: Tuple[Tuple[int, int, int], str]
2629
"""
2730
return obj.shape[-3:], obj.dtype.str
2831

2932

3033
@hookimpl
31-
def audio_info(obj: object) -> tuple[int, str]:
34+
def audio_info(obj: ArrayLike) -> Tuple[int, str]:
3235
"""get audio sample info
3336
34-
:param obj: object containing audio data (with interleaving channels) with arbitrary number of samples
35-
:type obj: object
36-
:return: number of channels and sample data type in numpy dtype str expression
37-
:rtype: tuple[tuple[int], str]
37+
:param obj: column-wise audio data with arbitrary number of samples
38+
:type obj: ArrayLike
39+
:return: number of channels and sample data type in data type str
40+
:rtype: Tuple[Tuple[int], str]
3841
"""
3942
return obj.shape[-1:], obj.dtype.str
4043

4144

4245
@hookimpl
43-
def video_bytes(obj: object) -> memoryview:
44-
"""return bytes-like object of packed video pixels, associated with `video_info()`
46+
def video_bytes(obj: ArrayLike) -> memoryview:
47+
"""return bytes-like object of rawvideo NumPy array
4548
46-
:param obj: object containing video frame data with arbitrary number of frames
47-
:type obj: object
48-
:return: packed bytes of video frames
49-
:rtype: bytes-like object
49+
:param obj: video frame data with arbitrary number of frames
50+
:type obj: ArrayLike
51+
:return: memoryview of video frames
52+
:rtype: memoryview
5053
"""
5154

5255
return memoryview(obj)
5356

5457

5558
@hookimpl
56-
def audio_bytes(obj: object) -> memoryview:
57-
"""return bytes-like object of packed audio samples
59+
def audio_bytes(obj: ArrayLike) -> memoryview:
60+
"""return bytes-like object of rawaudio NumPy array
5861
59-
:param obj: object containing audio data (with interleaving channels) with arbitrary number of samples
60-
:type obj: object
61-
:return: packed bytes of audio samples
62-
:rtype: bytes-like object
62+
:param obj: column-wise audio data with arbitrary number of samples
63+
:type obj: ArrayLike
64+
:return: memoryview of audio samples
65+
:rtype: memoryview
6366
"""
6467

6568
return memoryview(obj)
6669

6770

6871
@hookimpl
69-
def bytes_to_video(b: bytes, dtype: str, shape: tuple[int, int, int]) -> object:
70-
"""convert bytes to rawvideo object
72+
def bytes_to_video(b: bytes, dtype: str, shape: Tuple[int, int, int]) -> ArrayLike:
73+
"""convert bytes to rawvideo NumPy array
7174
7275
:param b: byte data of arbitrary number of video frames
7376
:type b: bytes
74-
:param dtype: data type numpy dtype string (e.g., '|u1', '<f4')
77+
:param dtype: data type string (e.g., '|u1', '<f4')
7578
:type dtype: str
7679
:param size: frame dimension in pixels and number of color components (height, width, components)
77-
:type size: tuple[int, int, int]
78-
:return: python object holding the rawvideo frames
79-
:rtype: object
80+
:type size: Tuple[int, int, int]
81+
:return: rawvideo frames
82+
:rtype: ArrayLike
8083
"""
8184

8285
return np.frombuffer(b, dtype).reshape(-1, *shape)
8386

8487

8588
@hookimpl
86-
def bytes_to_audio(b: bytes, dtype: str, shape: tuple[int]) -> object:
87-
"""convert bytes to rawaudio object
89+
def bytes_to_audio(b: bytes, dtype: str, shape: Tuple[int]) -> ArrayLike:
90+
"""convert bytes to rawaudio NumPy array
8891
8992
:param b: byte data of arbitrary number of video frames
9093
:type b: bytes
91-
:param dtype: numpy dtype string of the bytes (e.g., '<s2', '<f4')
94+
:param dtype: data type string (e.g., '<s2', '<f4')
9295
:type dtype: str
93-
:param shape: number of interleaved audio channels (1-element tuple)
94-
:type shape: tuple[int]
95-
:return: python object to hold the raw audio samples
96-
:rtype: object
96+
:param shape: number of audio channels
97+
:type shape: Tuple[int]
98+
:return: raw audio samples
99+
:rtype: ArrayLike
97100
"""
98101

99102
return np.frombuffer(b, dtype).reshape(-1, *shape)

0 commit comments

Comments
 (0)