@@ -145,28 +145,20 @@ def decode_and_resize(self, video_file, pts_list, height, width, device):
145145 ]
146146 return frames
147147
148+
148149class OpenCVDecoder (AbstractDecoder ):
149- def __init__ (self ):
150- import cv2 .videoio_registry as vr
150+ def __init__ (self , backend ):
151+ import cv2
152+
153+ self ._available_backends = {"FFMPEG" : cv2 .CAP_FFMPEG }
154+ self ._backend = self ._available_backends .get (backend )
151155
152156 self ._print_each_iteration_time = False
153- api_pref = None
154- # Check backend abi/api for compatibility
155- for backend in vr .getStreamBufferedBackends ():
156- if not vr .hasBackend (backend ):
157- continue
158- if not vr .isBackendBuiltIn (backend ):
159- _ , abi , api = vr .getStreamBufferedBackendPluginVersion (backend )
160- if (abi < 1 or (abi == 1 and api < 2 )):
161- continue
162- api_pref = backend
163- break
164- self ._backend = api_pref
165157
166158 def decode_frames (self , video_file , pts_list ):
167159 import cv2
168160
169- cap = cv2 .VideoCapture (video_file , self ._backend , [] )
161+ cap = cv2 .VideoCapture (video_file , self ._backend )
170162 if not cap .isOpened ():
171163 raise ValueError ("Could not open video stream" )
172164
@@ -194,7 +186,7 @@ def decode_frames(self, video_file, pts_list):
194186 def decode_first_n_frames (self , video_file , n ):
195187 import cv2
196188
197- cap = cv2 .VideoCapture (video_file , self ._backend , [] )
189+ cap = cv2 .VideoCapture (video_file , self ._backend )
198190 if not cap .isOpened ():
199191 raise ValueError ("Could not open video stream" )
200192
@@ -212,7 +204,11 @@ def decode_first_n_frames(self, video_file, n):
212204
213205 def decode_and_resize (self , video_file , pts_list , height , width , device ):
214206 import cv2
215- frames = [cv2 .resize (frame , (width , height )) for frame in self .decode_frames (video_file , pts_list )]
207+
208+ frames = [
209+ cv2 .resize (frame , (width , height ))
210+ for frame in self .decode_frames (video_file , pts_list )
211+ ]
216212 return frames
217213
218214
0 commit comments