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_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)
with open(TEST_STATS_FILES[0], 'w') as stats_file:
stats_manager.save_to_csv(stats_file, base_timecode)
stats_manager_new = StatsManager()
def test_content_detect(test_video_file):
""" Test SceneManager with VideoManager and ContentDetector. """
vm = VideoManager([test_video_file])
sm = SceneManager()
sm.add_detector(ContentDetector())
try:
video_fps = vm.get_framerate()
start_time = FrameTimecode('00:00:00', video_fps)
end_time = FrameTimecode('00:00:05', video_fps)
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)
assert num_frames == end_time.get_frames() + 1
finally:
vm.release()
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)
assert num_frames == (1 + end_time.get_frames() - start_time.get_frames())
def test_content_detect_opencv_videocap(test_video_file):
""" Test SceneManager with cv2.VideoCapture and ContentDetector. """
cap = cv2.VideoCapture(test_video_file)
sm = SceneManager()
sm.add_detector(ContentDetector())
try:
video_fps = cap.get(cv2.CAP_PROP_FPS)
duration = FrameTimecode('00:00:05', video_fps)
num_frames = sm.detect_scenes(frame_source=cap, end_time=duration)
assert num_frames == duration.get_frames()
finally:
cap.release()
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')
if scene_list == []:
scene_list = [(video_manager.get_base_timecode(),video_manager.get_current_timecode())]
with open(savepath, 'wb') as fil:
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')
if scene_list == []:
scene_list = [(video_manager.get_base_timecode(),video_manager.get_current_timecode())]
with open(savepath, 'wb') as fil: