@@ -69,7 +69,7 @@ def audio_bytes(obj: ArrayLike) -> memoryview:
69
69
70
70
71
71
@hookimpl
72
- def bytes_to_video (b : bytes , dtype : str , shape : Tuple [int , int , int ]) -> ArrayLike :
72
+ def bytes_to_video (b : bytes , dtype : str , shape : Tuple [int , int , int ], squeeze : bool ) -> ArrayLike :
73
73
"""convert bytes to rawvideo NumPy array
74
74
75
75
:param b: byte data of arbitrary number of video frames
@@ -78,15 +78,18 @@ def bytes_to_video(b: bytes, dtype: str, shape: Tuple[int, int, int]) -> ArrayLi
78
78
:type dtype: str
79
79
:param size: frame dimension in pixels and number of color components (height, width, components)
80
80
:type size: Tuple[int, int, int]
81
+ :param squeeze: True to remove all the singular dimensions
82
+ :type squeeze: bool
81
83
:return: rawvideo frames
82
84
:rtype: ArrayLike
83
85
"""
84
86
85
- return np .frombuffer (b , dtype ).reshape (- 1 , * shape )
87
+ x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
88
+ return x .squeeze () if squeeze else x
86
89
87
90
88
91
@hookimpl
89
- def bytes_to_audio (b : bytes , dtype : str , shape : Tuple [int ]) -> ArrayLike :
92
+ def bytes_to_audio (b : bytes , dtype : str , shape : Tuple [int ], squeeze : bool ) -> ArrayLike :
90
93
"""convert bytes to rawaudio NumPy array
91
94
92
95
:param b: byte data of arbitrary number of video frames
@@ -95,8 +98,11 @@ def bytes_to_audio(b: bytes, dtype: str, shape: Tuple[int]) -> ArrayLike:
95
98
:type dtype: str
96
99
:param shape: number of audio channels
97
100
:type shape: Tuple[int]
101
+ :param squeeze: True to remove all the singular dimensions
102
+ :type squeeze: bool
98
103
:return: raw audio samples
99
104
:rtype: ArrayLike
100
105
"""
101
106
102
- return np .frombuffer (b , dtype ).reshape (- 1 , * shape )
107
+ x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
108
+ return x .squeeze () if squeeze else x
0 commit comments