def _load_input_videos(self):
""" Opens and checks that all input video files are valid, can
be processed, and have the same resolution and framerate. """
self.video_resolution = None
self.video_fps = None
self.frames_total = 0
if not len(self.video_paths) > 0:
return False
for video_path in self.video_paths:
cap = cv2.VideoCapture()
cap.open(video_path)
video_name = os.path.basename(video_path)
if not cap.isOpened():
if not self.suppress_output:
print("[DVR-Scan] Error: Couldn't load video %s." % video_name)
print("[DVR-Scan] Check that the given file is a valid video"
" clip, and ensure all required software dependencies"
" are installed and configured properly.")
cap.release()
return False
curr_resolution = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
curr_framerate = cap.get(cv2.CAP_PROP_FPS)
self.frames_total += cap.get(cv2.CAP_PROP_FRAME_COUNT)
cap.release()
if self.video_resolution is None and self.video_fps is None:
self.video_resolution = curr_resolution
self.video_fps = curr_framerate
if not self.suppress_output:
print("[DVR-Scan] Opened video %s (%d x %d at %2.3f FPS)." % (
video_name, self.video_resolution[0],
self.video_resolution[1], self.video_fps))
# Check that all other videos specified have the same resolution
# (we'll assume the framerate is the same if the resolution matches,
# since the VideoCapture FPS information is not always accurate).
elif curr_resolution != self.video_resolution:
if not self.suppress_output:
print("[DVR-Scan] Error: Can't append clip %s, video resolution"
" does not match the first input file." % video_name)
return False
else:
if not self.suppress_output:
print("[DVR-Scan] Appended video %s." % video_name)
# If we get to this point, all videos have the same parameters.
return True
评论列表
文章目录