def _init_video_manager(self, input_list, framerate, downscale): self.base_timecode = None logging.debug('Initializing VideoManager.') video_manager_initialized = False try: self.video_manager = VideoManager( video_files=input_list, framerate=framerate, logger=logging) video_manager_initialized = True self.base_timecode = self.video_manager.get_base_timecode() self.video_manager.set_downscale_factor(downscale) except VideoOpenFailure as ex: error_strs = [ 'could not open video%s.' % get_plural(ex.file_list), 'Failed to open the following video file%s:' % get_plural(ex.file_list)] error_strs += [' %s' % file_name[0] for file_name in ex.file_list] dll_okay, dll_name = check_opencv_ffmpeg_dll() if not dll_okay: error_strs += [ 'Error: OpenCV dependency %s not found.' % dll_name, 'Ensure that you installed the Python OpenCV module, and that the', '%s file can be found to enable video support.' % dll_name] logging.debug('\n'.join(error_strs[1:])) if not dll_okay: click.echo(click.style( '\nOpenCV dependency missing, video input/decoding not available.\n', fg='red')) raise click.BadParameter('\n'.join(error_strs), param_hint='input video') except VideoFramerateUnavailable as ex: error_strs = ['could not get framerate from video(s)', 'Failed to obtain framerate for video file %s.' % ex.file_name] error_strs.append('Specify framerate manually with the -f / --framerate option.') logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='input video') except VideoParameterMismatch as ex: error_strs = ['video parameters do not match.', 'List of mismatched parameters:'] for param in ex.file_list: if param[0] == cv2.CAP_PROP_FPS: param_name = 'FPS' if param[0] == cv2.CAP_PROP_FRAME_WIDTH: param_name = 'Frame width' if param[0] == cv2.CAP_PROP_FRAME_HEIGHT: param_name = 'Frame height' error_strs.append(' %s mismatch in video %s (got %.2f, expected %.2f)' % ( param_name, param[3], param[1], param[2])) error_strs.append( 'Multiple videos may only be specified if they have the same framerate and' ' resolution. -f / --framerate may be specified to override the framerate.') logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='input videos') except InvalidDownscaleFactor as ex: error_strs = ['Downscale value is not > 0.', str(ex)] logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='downscale factor') return video_manager_initialized
def _init_video_manager(self, input_list, framerate, downscale): self.base_timecode = None logging.debug('Initializing VideoManager.') video_manager_initialized = False try: self.video_manager = VideoManager( video_files=input_list, framerate=framerate, logger=logging) video_manager_initialized = True self.base_timecode = self.video_manager.get_base_timecode() self.video_manager.set_downscale_factor(downscale) except VideoOpenFailure as ex: error_strs = [ 'could not open video%s.' % get_plural(ex.file_list), 'Failed to open the following video file%s:' % get_plural(ex.file_list)] error_strs += [' %s' % file_name[0] for file_name in ex.file_list] dll_okay, dll_name = check_opencv_ffmpeg_dll() if not dll_okay: error_strs += [ 'Error: OpenCV dependency %s not found.' % dll_name, 'Ensure that you installed the Python OpenCV module, and that the', '%s file can be found to enable video support.' % dll_name] logging.debug('\n'.join(error_strs[1:])) if not dll_okay: click.echo(click.style( '\nOpenCV dependency missing, video input/decoding not available.\n', fg='red')) raise click.BadParameter('\n'.join(error_strs), param_hint='input video') except VideoFramerateUnavailable as ex: error_strs = ['could not get framerate from video(s)', 'Failed to obtain framerate for video file %s.' % ex.file_name] error_strs.append('Specify framerate manually with the -f / --framerate option.') logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='input video') except VideoParameterMismatch as ex: error_strs = ['video parameters do not match.', 'List of mismatched parameters:'] for param in ex.file_list: if param[0] == cv2.CAP_PROP_FPS: param_name = 'FPS' if param[0] == cv2.CAP_PROP_FRAME_WIDTH: param_name = 'Frame width' if param[0] == cv2.CAP_PROP_FRAME_HEIGHT: param_name = 'Frame height' error_strs.append(' %s mismatch in video %s (got %.2f, expected %.2f)' % ( param_name, param[3], param[1], param[2])) error_strs.append( 'Multiple videos may only be specified if they have the same framerate and' ' resolution. -f / --framerate may be specified to override the framerate.') logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='input videos') except InvalidDownscaleFactor as ex: error_strs = ['Downscale value is not > 0.', str(ex)] logging.debug('\n'.join(error_strs)) raise click.BadParameter('\n'.join(error_strs), param_hint='downscale factor') return video_manager_initialized