@@ -56,7 +56,9 @@ def audio_bytes(obj: object) -> memoryview:
5656
5757
5858@hookimpl
59- def bytes_to_video (b : bytes , dtype : str , shape : Tuple [int , int , int ]) -> object :
59+ def bytes_to_video (
60+ b : bytes , dtype : str , shape : Tuple [int , int , int ], squeeze : bool
61+ ) -> object :
6062 """convert bytes to rawvideo object
6163
6264 :param b: byte data of arbitrary number of video frames
@@ -65,19 +67,23 @@ def bytes_to_video(b: bytes, dtype: str, shape: Tuple[int, int, int]) -> object:
6567 :type dtype: str
6668 :param size: frame dimension in pixels and number of color components (height, width, components)
6769 :type size: Tuple[int, int, int]
70+ :param squeeze: True to remove all the singular dimensions
71+ :type squeeze: bool
6872 :return: dict holding the rawvideo frame data
6973 :rtype: dict['buffer':bytes, 'dtype':str, 'shape': Tuple[int,int,int]]
7074 """
7175
76+ sh = (len (b ) // get_samplesize (shape , dtype ), * shape )
77+
7278 return {
7379 "buffer" : b ,
7480 "dtype" : dtype ,
75- "shape" : ( len ( b ) // get_samplesize ( shape , dtype ), * shape ) ,
81+ "shape" : tuple ((( i for i in sh if i != 1 ))) if squeeze else sh ,
7682 }
7783
7884
7985@hookimpl
80- def bytes_to_audio (b : bytes , dtype : str , shape : Tuple [int ]) -> object :
86+ def bytes_to_audio (b : bytes , dtype : str , shape : Tuple [int ], squeeze : bool ) -> object :
8187 """convert bytes to rawaudio object
8288
8389 :param b: byte data of arbitrary number of video frames
@@ -86,12 +92,16 @@ def bytes_to_audio(b: bytes, dtype: str, shape: Tuple[int]) -> object:
8692 :type dtype: str
8793 :param shape: number of interleaved audio channels (1-element tuple)
8894 :type shape: Tuple[int]
95+ :param squeeze: True to remove all the singular dimensions
96+ :type squeeze: bool
8997 :return: dict to hold the raw audio samples
9098 :rtype: dict['buffer':bytes, 'dtype':str, 'shape': Tuple[int]]
9199 """
92100
101+ sh = (len (b ) // get_samplesize (shape , dtype ), * shape )
102+
93103 return {
94104 "buffer" : b ,
95105 "dtype" : dtype ,
96- "shape" : ( len ( b ) // get_samplesize ( shape , dtype ), * shape ) ,
106+ "shape" : tuple ((( i for i in sh if i != 1 ))) if squeeze else sh ,
97107 }
0 commit comments