def run(self): try: stats = scenedetect.stats_manager.StatsManager() scenemgr = scenedetect.SceneManager(stats) scenemgr.add_detector(scenedetect.ContentDetector()) scenemgr.detect_scenes(frame_source=self) if self.scenes.stats is None: self.scenes.stats = numpy.nan * \ numpy.zeros((self.scenes.source.framecount - 1, 4)) H, W = self.scenes.stats.shape if H < self.scenes.prev.framecount - 1 or W < 4: newstats = numpy.nan * \ numpy.zeros((self.scenes.source.framecount - 1, 4)) newstats[:H, :W] = self.scenes.stats self.scenes.stats = newstats if isinstance(self.scenes.prev, BaseFilter): start = self.scenes.prev.cumulativeIndexReverseMap[self._start + 1] else: start = self._start if (self._end >= self.scenes.prev.framecount or not isinstance(self.scenes.prev, BaseFilter)): end = self.scenes.source.framecount else: end = self.scenes.prev.cumulativeIndexReverseMap[self._end] for m in range(start, end): if isinstance(self.scenes.prev, BaseFilter): n = self.scenes.prev.cumulativeIndexMap[m] else: n = m if n > 0: self.scenes.stats[m - 1] = stats.get_metrics( n - self._start, ["content_val", "delta_hue", "delta_sat", "delta_lum"]) else: self.scenes.stats[m - 1] = numpy.nan finally: if callable(self.notify_complete): self.notify_complete()
def analyze_video(video_file, threshold=30, min_scene_len=10, downscale_factor=1): # First, load into a video manager video_mgr = sd.VideoManager([video_file]) stats_mgr = sd.stats_manager.StatsManager() scene_mgr = sd.SceneManager(stats_mgr) # Add a content detector scene_mgr.add_detector( sd.ContentDetector(threshold=threshold, min_scene_len=min_scene_len)) # Start the video manager video_mgr.set_downscale_factor(downscale_factor) video_mgr.start() # Detect the scenes scene_mgr.detect_scenes(frame_source=video_mgr, show_progress=True) # Retrieve scene list scene_mgr_list = scene_mgr.get_scene_list(base_timecode) # Initialize scene list for analysis scene_list = [] # Build our list from the frame_timecode objects for scene in scene_mgr_list: start_frame, end_frame = scene start_frame = start_frame.frame_num scene_list.append(start_frame) # Extract some info video_fps = end_frame.framerate frames_read = end_frame.frame_num # Release the video manager video_mgr.release() return (video_fps, frames_read, scene_list)
import gc import scenedetect as sd from moviepy.editor import * if __name__ == '__main__': # Specify video location here video_file = '/media/unraid/Datasets/QuantitativeEditing/To Analyze/Bad Lip Reading_2018_Sample of My Pasta.mkv' outfile_dir = '/media/unraid/Datasets/QuantitativeEditing/Parameter Screen/' outfile_prefix = 'Bad Lip Reading_2018_Sample of My Pasta_' # First, load into a video manager video_mgr = sd.VideoManager([video_file]) stats_mgr = sd.stats_manager.StatsManager() scene_mgr = sd.SceneManager(stats_mgr) # Specify range to vary for threshold value for threshold in range(22, 41): # Try a couple different minimum scene lengths for each threshold for min_scene_len in [5, 10, 15]: # Add a content detector scene_mgr.add_detector( sd.ContentDetector(threshold=threshold, min_scene_len=min_scene_len)) # Get the starting timecode base_timecode = video_mgr.get_base_timecode()
print("Analyzig file {} with params:".format(fn)) print(" * Threshold = {}".format(thr)) print(" * Min length = {}".format(minlen)) print(" * Max length = {}".format(maxlen)) with open(fn) as json_file: VL = json.load(json_file) vfile = VL["Filename"] print("Processing {}".format(vfile)) video_manager = sc.VideoManager([vfile]) stats_manager = sc.stats_manager.StatsManager() scene_manager = sc.SceneManager(stats_manager) scene_manager.add_detector(sc.ContentDetector(threshold=thr)) 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) if categ_name not in VL["Categories"]: VL["Categories"].append(categ_name) scenez = []
print(name) yt.register_on_progress_callback(progress_fn) fps = stream.fps name = yt.title.replace(" ", "_") stream.download(output_path="./data", filename=name + " 30") # In[44]: scene_list = [] path = "data/47_Taco_Vs_1_Taco 30.mp4" video_mgr = scenedetect.VideoManager([path]) #put your filename in this line stats_mgr = scenedetect.stats_manager.StatsManager() scene_mgr = scenedetect.SceneManager(stats_mgr) # Now add the content detector scene_mgr.add_detector( scenedetect.ContentDetector(threshold=60, min_scene_len=5 * 30)) # Start the video manager downscale_factor = 1 video_mgr.set_downscale_factor(downscale_factor) video_mgr.start() # Detect the scenes scene_mgr.detect_scenes(frame_source=video_mgr, show_progress=True) # In[46]: