Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scene_list(test_video_file):
""" Test SceneManager get_scene_list method with VideoManager/ContentDetector. """
vm = VideoManager([test_video_file])
sm = SceneManager()
sm.add_detector(ContentDetector())
try:
base_timecode = vm.get_base_timecode()
video_fps = vm.get_framerate()
start_time = FrameTimecode('00:00:05', video_fps)
end_time = FrameTimecode('00:00:15', video_fps)
assert end_time.get_frames() > start_time.get_frames()
vm.set_duration(start_time=start_time, end_time=end_time)
vm.set_downscale_factor()
vm.start()
num_frames = sm.detect_scenes(frame_source=vm)
def test_wrong_framerate_type(test_video_file):
""" Test VideoManager constructor (__init__ method) with an invalid framerate
argument types to trigger a TypeError exception. """
with pytest.raises(TypeError): VideoManager([test_video_file], framerate=int(0))
with pytest.raises(TypeError): VideoManager([test_video_file], framerate=int(10))
with pytest.raises(TypeError): VideoManager([test_video_file], framerate='10')
VideoManager([test_video_file], framerate=float(10)).release()
def test_detector_metrics(test_video_file):
""" Test passing StatsManager to a SceneManager and using it for storing the frame metrics
from a ContentDetector.
"""
video_manager = VideoManager([test_video_file])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)
#base_timecode = video_manager.get_base_timecode()
assert not stats_manager._registered_metrics
scene_manager.add_detector(ContentDetector())
# add_detector should trigger register_metrics in the StatsManager.
assert stats_manager._registered_metrics
try:
video_fps = video_manager.get_framerate()
start_time = FrameTimecode('00:00:00', video_fps)
duration = FrameTimecode('00:00:20', video_fps)
video_manager.set_duration(start_time=start_time, end_time=duration)
video_manager.set_downscale_factor()
def test_save_load_from_video(test_video_file):
""" Test generating and saving some frame metrics from TEST_VIDEO_FILE to a file on disk, and
loading the file back to ensure the loaded frame metrics agree with those that were saved.
"""
video_manager = VideoManager([test_video_file])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)
base_timecode = video_manager.get_base_timecode()
scene_manager.add_detector(ContentDetector())
try:
video_fps = video_manager.get_framerate()
start_time = FrameTimecode('00:00:00', video_fps)
duration = FrameTimecode('00:00:20', video_fps)
video_manager.set_duration(start_time=start_time, end_time=duration)
video_manager.set_downscale_factor()
video_manager.start()
scene_manager.detect_scenes(frame_source=video_manager)
def find_scenes(video_path):
start_time = time.time()
print("Analyzing video "+video_path)
# type: (str) -> List[Tuple[FrameTimecode, FrameTimecode]]
video_manager = VideoManager([video_path])
stats_manager = StatsManager()
# Pass StatsManager to SceneManager to accelerate computing time
scene_manager = SceneManager(stats_manager)
# Add ContentDetector algorithm (each detector's constructor
# takes detector options, e.g. threshold).
scene_manager.add_detector(ContentDetector())
base_timecode = video_manager.get_base_timecode()
# We save our stats file to {VIDEO_PATH}.stats.csv.
stats_file_path = '%s.stats.csv' % (video_path)
scene_list = []
folder = os.path.splitext(video_path)[0]
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:]))
def scene_detect(opt):
video_manager = VideoManager([os.path.join(opt.avi_dir,opt.reference,'video.avi')])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)
# Add ContentDetector algorithm (constructor takes detector options like threshold).
scene_manager.add_detector(ContentDetector())
base_timecode = video_manager.get_base_timecode()
video_manager.set_downscale_factor()
video_manager.start()
scene_manager.detect_scenes(frame_source=video_manager)
scene_list = scene_manager.get_scene_list(base_timecode)
savepath = os.path.join(opt.work_dir,'scene.pckl')
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:]))
def scene_detect(opt):
video_manager = VideoManager([os.path.join(opt.avi_dir,opt.reference,'video.avi')])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)
# Add ContentDetector algorithm (constructor takes detector options like threshold).
scene_manager.add_detector(ContentDetector())
base_timecode = video_manager.get_base_timecode()
video_manager.set_downscale_factor()
video_manager.start()
scene_manager.detect_scenes(frame_source=video_manager)
scene_list = scene_manager.get_scene_list(base_timecode)
savepath = os.path.join(opt.work_dir,opt.reference,'scene.pckl')