@@ -69,7 +69,7 @@ def audio_bytes(obj: ArrayLike) -> memoryview:
6969
7070
7171@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 :
7373 """convert bytes to rawvideo NumPy array
7474
7575 :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
7878 :type dtype: str
7979 :param size: frame dimension in pixels and number of color components (height, width, components)
8080 :type size: Tuple[int, int, int]
81+ :param squeeze: True to remove all the singular dimensions
82+ :type squeeze: bool
8183 :return: rawvideo frames
8284 :rtype: ArrayLike
8385 """
8486
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
8689
8790
8891@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 :
9093 """convert bytes to rawaudio NumPy array
9194
9295 :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:
9598 :type dtype: str
9699 :param shape: number of audio channels
97100 :type shape: Tuple[int]
101+ :param squeeze: True to remove all the singular dimensions
102+ :type squeeze: bool
98103 :return: raw audio samples
99104 :rtype: ArrayLike
100105 """
101106
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