modify video reader in pipeline

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11378034
This commit is contained in:
liaojie.laj
2023-01-10 23:01:57 +08:00
committed by wenmeng.zwm
parent ed859e5274
commit a2b8d95188

View File

@@ -525,23 +525,12 @@ class VideoFrameInterpolationPipeline(Pipeline):
logger.info('load video frame-interpolation done')
def preprocess(self, input: Input, out_fps: float = 0) -> Dict[str, Any]:
# read images
file_extension = os.path.splitext(input)[1]
if file_extension in VIDEO_EXTENSIONS: # input is a video file
video_reader = VideoReader(input)
inputs = []
for frame in video_reader:
inputs.append(frame)
fps = video_reader.fps
elif file_extension == '': # input is a directory
inputs = []
input_paths = sorted(glob.glob(f'{input}/*'))
for input_path in input_paths:
img = LoadImage(input_path, mode='rgb')
inputs.append(img)
fps = 25 # default fps
else:
raise ValueError('"input" can only be a video or a directory.')
# input is a video file
video_reader = VideoReader(input)
inputs = []
for frame in video_reader:
inputs.append(frame)
fps = video_reader.fps
for i, img in enumerate(inputs):
img = torch.from_numpy(img.copy()).permute(2, 0, 1).float()