@@ -31,7 +31,10 @@ def video_info(obj: ArrayLike) -> Tuple[Tuple[int, int, int], str]:
31
31
:return: shape (height,width,components) and data type str
32
32
:rtype: Tuple[Tuple[int, int, int], str]
33
33
"""
34
- return obj .shape [- 3 :] if obj .ndim != 2 else [* obj .shape , 1 ], obj .dtype .str
34
+ try :
35
+ return obj .shape [- 3 :] if obj .ndim != 2 else [* obj .shape , 1 ], obj .dtype .str
36
+ except :
37
+ return None
35
38
36
39
37
40
@hookimpl
@@ -43,7 +46,10 @@ def audio_info(obj: ArrayLike) -> Tuple[int, str]:
43
46
:return: number of channels and sample data type in data type str
44
47
:rtype: Tuple[Tuple[int], str]
45
48
"""
46
- return obj .shape [- 1 :] if obj .ndim > 1 else [1 ], obj .dtype .str
49
+ try :
50
+ return obj .shape [- 1 :] if obj .ndim > 1 else [1 ], obj .dtype .str
51
+ except :
52
+ return None
47
53
48
54
49
55
@hookimpl
@@ -56,7 +62,10 @@ def video_bytes(obj: ArrayLike) -> memoryview:
56
62
:rtype: memoryview
57
63
"""
58
64
59
- return memoryview (np .ascontiguousarray (obj ))
65
+ try :
66
+ return memoryview (np .ascontiguousarray (obj ))
67
+ except :
68
+ return None
60
69
61
70
62
71
@hookimpl
@@ -69,7 +78,10 @@ def audio_bytes(obj: ArrayLike) -> memoryview:
69
78
:rtype: memoryview
70
79
"""
71
80
72
- return memoryview (np .ascontiguousarray (obj ))
81
+ try :
82
+ return memoryview (np .ascontiguousarray (obj ))
83
+ except :
84
+ return None
73
85
74
86
75
87
@hookimpl
@@ -90,9 +102,11 @@ def bytes_to_video(
90
102
:rtype: ArrayLike
91
103
"""
92
104
93
- x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
94
- return x .squeeze () if squeeze else x
95
-
105
+ try :
106
+ x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
107
+ return x .squeeze () if squeeze else x
108
+ except :
109
+ return None
96
110
97
111
@hookimpl
98
112
def bytes_to_audio (b : bytes , dtype : str , shape : Tuple [int ], squeeze : bool ) -> ArrayLike :
@@ -110,5 +124,9 @@ def bytes_to_audio(b: bytes, dtype: str, shape: Tuple[int], squeeze: bool) -> Ar
110
124
:rtype: ArrayLike
111
125
"""
112
126
113
- x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
114
- return x .squeeze () if squeeze else x
127
+ try :
128
+ x = np .frombuffer (b , dtype ).reshape (- 1 , * shape )
129
+ return x .squeeze () if squeeze else x
130
+ except :
131
+ return None
132
+
0 commit comments