예제 #1
0
파일: utils.py 프로젝트: scraplab/psypose
def get_shots(video_path, downscale_factor=None, threshold=30):
    """
    

    Parameters
    ----------
    video_path : scenedetect VideoManager object.
    downscale_factor : Factor by which to downscale video to improve speed.
    threshold : Cut detection threshold.

    Returns
    -------
    cut_tuples : A list of tuples where each tuple contains the in- and out-frame of each shot.

    """
    #print('Detecting cuts...')
    video = VideoManager([video_path])
    video.set_downscale_factor(downscale_factor)
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=threshold))
    video.start()
    scene_manager.detect_scenes(frame_source=video)
    shot_list = scene_manager.get_scene_list()
    cut_tuples = []
    for shot in shot_list:
        cut_tuples.append((shot[0].get_frames(), shot[1].get_frames()))
    video.release()
    return cut_tuples
예제 #2
0
def find_scene(video, results):
    video_manager = VideoManager([video])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=THRESHOLD))
    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)
            # Each scene is a tuple of (start, end) FrameTimecodes.
    for i, scene in enumerate(scene_list):
        #scene[0].get_timecode(), scene[0].get_frames(),
        #scene[1].get_timecode(), scene[1].get_frames(),))
        results.append((scene[0].get_timecode()))
    video_manager.release()
def capture_video(video_path, capture_path, default_path):
    print("\n[전환장면 캡처 시작] 영상 내 전환 시점을 기준으로 이미지 추출을 시작합니다")

    video_manager = VideoManager([video_path])
    stats_manager = StatsManager()
    scene_manager = SceneManager(stats_manager)

    # 가장 예민하게 잡아내도록 1~100 중 1로 설정
    scene_manager.add_detector(ContentDetector(threshold=1))

    video_manager.set_downscale_factor()

    video_manager.start()
    scene_manager.detect_scenes(frame_source=video_manager)

    scene_list = scene_manager.get_scene_list()
    print(">>>", f'{len(scene_list)} scenes detected!')  # 전환 인식이 된 장면의 수

    save_images(scene_list,
                video_manager,
                num_images=1,
                image_name_template='$SCENE_NUMBER',
                output_dir=capture_path)

    write_scene_list_html(default_path + 'SceneDetectResult.html', scene_list)

    captured_timeline_list = []  # 전환된 시점을 저장할 리스트 함수
    for scene in scene_list:
        start, end = scene

        # 전환 시점 저장
        captured_timeline_list.append(start.get_seconds())

    print("[전환장면 캡처 종료] 영상 내 전환 시점을 기준으로 이미지 추출을 종료합니다\n")
    return captured_timeline_list
예제 #4
0
def find_scenes(video_path, threshold=30.0):
    # Create our video & scene managers, then add the detector.
    video_manager = VideoManager([video_path])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=threshold))

    # Improve processing speed by downscaling before processing.
    video_manager.set_downscale_factor()

    # Start the video manager and perform the scene detection.
    video_manager.start()
    time = scene_manager.detect_scenes(frame_source=video_manager)

    # Each returned scene is a tuple of the (start, end) timecode.

    times = scene_manager.get_scene_list(time)

    video_splitter.split_video_ffmpeg(
        video_path,
        times,
        '$VIDEO_NAME - Scene $SCENE_NUMBER',
        video_path,
        arg_override='-c:v libx264 -preset fast -crf 21 -c:a aac',
        hide_progress=False,
        suppress_output=False)
예제 #5
0
 def calculate_scene_list(video: Message, threshold: int = 30) -> List[Tuple[FrameTimecode, FrameTimecode]]:
     video_manager = VideoManager([video.message_data.file_path])
     stats_manager = StatsManager()
     scene_manager = SceneManager(stats_manager)
     scene_manager.add_detector(ContentDetector(threshold=threshold))
     try:
         video_manager.start()
         base_timecode = video_manager.get_base_timecode()
         scene_manager.detect_scenes(frame_source=video_manager)
         scene_list = scene_manager.get_scene_list(base_timecode)
         return scene_list
     finally:
         video_manager.release()
예제 #6
0
def keyframe_detection_with_scenedetect(parameters):
	video = VideoManager([parameters.input_file])
	scene = SceneManager()
	scene.add_detector(ContentDetector(threshold = 30.0))

	video.set_downscale_factor()
	video.start()
	scene.detect_scenes(frame_source = video)

	return scene.get_scene_list()
예제 #7
0
def find_scenes(video_path, threshold=30.0):
    # Create our video & scene managers, then add the detector.
    video_manager = VideoManager([video_path])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=threshold))
    # Base timestamp at frame 0 (required to obtain the scene list).
    base_timecode = video_manager.get_base_timecode()
    # Improve processing speed by downscaling before processing.
    video_manager.set_downscale_factor()
    # Start the video manager and perform the scene detection.
    video_manager.start()
    scene_manager.detect_scenes(frame_source=video_manager)
    # Each returned scene is a tuple of the (start, end) timecode.
    return scene_manager.get_scene_list(base_timecode)
예제 #8
0
def find_scenes(videoURL):
    threshold = 30.0
    video_path = settings.MEDIA_ROOT
    video_path = video_path.replace('\\', '/')

    video_manager = VideoManager([video_path + videoURL])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=threshold))

    base_timecode = video_manager.get_base_timecode()
    #base_timecode = video_manager.get(cv2.CAP_PROP_POS_MSEC)
    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)

    return scene_manager.get_scene_list(base_timecode)
예제 #9
0
def find_scenes(video_path, framerate):

    # Create our video & scene managers, then add the detector.
    video_manager = VideoManager([str(video_path)])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(THRESHOLD, MINIMUM))

    # Improve processing speed by downscaling before processing.
    video_manager.set_downscale_factor(DOWNSCALE)

    # Start the video manager and perform the scene detection.
    video_manager.start()
    scene_manager.detect_scenes(frame_source=video_manager)

    # Each returned scene is a tuple of the (start, end) timecode.
    return scene_manager.get_scene_list(framerate)
예제 #10
0
    def _find_scenes(self, video_path, threshold=30.0):
        """https://pyscenedetect.readthedocs.io/en/latest/

        Args:
            video_path ([type]): [description]
            threshold (float, optional): [description]. Defaults to 30.0.

        Returns:
            [type]: [description]
        """
        video_manager = VideoManager([video_path])
        scene_manager = SceneManager()
        scene_manager.add_detector(ContentDetector(threshold=threshold))
        base_timecode = video_manager.get_base_timecode()
        video_manager.set_downscale_factor()
        video_manager.start()
        scene_manager.detect_scenes(frame_source=video_manager)
        time_frames = scene_manager.get_scene_list(base_timecode)
        return [(frame[0].get_frames(), frame[1].get_frames())
                for frame in time_frames]
예제 #11
0
def find_scenes(
    video_path: str, threshold: float = 30.0
) -> List[Tuple[FrameTimecode, FrameTimecode]]:
    # Create our video & scene managers, then add the detector.
    video_manager = VideoManager([video_path])
    scene_manager = SceneManager()
    scene_manager.add_detector(ContentDetector(threshold=threshold))

    # Improve processing speed by downscaling before processing.
    video_manager.set_downscale_factor()

    # Start the video manager and perform the scene detection.
    video_manager.start()
    scene_manager.detect_scenes(frame_source=video_manager, show_progress=False)

    # Each returned scene is a tuple of the (start, end) timecode.
    return scene_manager.get_scene_list()
예제 #12
0
def find_scenes(video_path, threshold=30.0):
    try:
        # Create our video & scene managers, then add the detector.
        video_manager = VideoManager([video_path])
        scene_manager = SceneManager()
        scene_manager.add_detector(ContentDetector(threshold=threshold))

        # Improve processing speed by downscaling before processing.
        video_manager.set_downscale_factor()

        # Start the video manager and perform the scene detection.
        video_manager.start()
        scene_manager.detect_scenes(frame_source=video_manager)

        # Each returned scene is a tuple of the (start, end) timecode.
        return scene_manager.get_scene_list()
    except Exception as e:
        logging.error(e)
예제 #13
0
    for game in tqdm(random.sample(l, len(l))):
        # for game in getListGames("v1", task="camera-changes"):
        for half in [1, 2]:
            filename = f"{SOCCERNET_PATH}/{game}/{half}.mkv"
            outname = f"{SOCCERNET_PATH}/{game}/{half}_camerachanges"
            # video_path.append(filename)
            # ThresholdDetector
            # ThresholdDetector
            if algo_name == "ContentDetector":
                list_param = [10, 20, 30, 40, 50, 60]

            for threshold in random.sample(list_param, len(list_param)):
                algo = f"{algo_name}{threshold}"
                if os.path.exists(f"{outname}_{algo}.json"):
                    continue
                video_manager = VideoManager([filename])
                scene_manager = SceneManager()
                # for threshold in [10,20,30,40,50,60]:

                if algo_name == "ContentDetector":
                    scene_manager.add_detector(
                        ContentDetector(threshold=threshold))

                # list_param = [64, 128, 256, 32, 16, 8, 4]

                # Base timestamp at frame 0 (required to obtain the scene list).
                base_timecode = video_manager.get_base_timecode()

                # Improve processing speed by downscaling before processing.
                video_manager.set_downscale_factor()
예제 #14
0
from scenedetect import VideoManager, SceneManager, StatsManager
from scenedetect.detectors import ContentDetector
from scenedetect.scene_manager import save_images, write_scene_list_html

# video_path = '/Users/madchick/Desktop/Dropbox/동영상/싸이클01.mp4'
video_path = '/Users/madchick/Projects/test02.mp4'
stats_path = 'result.csv'

video_manager = VideoManager([video_path])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)

scene_manager.add_detector(ContentDetector(threshold=50))

video_manager.set_downscale_factor()

video_manager.start()
scene_manager.detect_scenes(frame_source=video_manager)

# result
with open(stats_path, 'w') as f:
    stats_manager.save_to_csv(f, video_manager.get_base_timecode())

scene_list = scene_manager.get_scene_list()
print(f'{len(scene_list)} scenes detected!')

save_images(scene_list,
            video_manager,
            num_images=1,
            image_name_template='$SCENE_NUMBER',
            output_dir='scenes')
예제 #15
0
def test_api(test_video_file):
    # (str) -> None
    """ Test overall PySceneDetect API functionality.

    Can be considered a high level integration/black-box test.

    """

    print("Running PySceneDetect API test...")

    print("PySceneDetect version being used: %s" %
          str(scenedetect.__version__))

    # Create a video_manager point to video file testvideo.mp4. Note that multiple
    # videos can be appended by simply specifying more file paths in the list
    # passed to the VideoManager constructor. Note that appending multiple videos
    # requires that they all have the same frame size, and optionally, framerate.
    video_manager = VideoManager([test_video_file])
    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()

    try:
        # If stats file exists, load it.
        if os.path.exists(STATS_FILE_PATH):
            # Read stats from CSV file opened in read mode:
            with open(STATS_FILE_PATH, 'r') as stats_file:
                stats_manager.load_from_csv(stats_file)

        start_time = base_timecode + 20  # 00:00:00.667
        end_time = base_timecode + 20.0  # 00:00:20.000
        # Set video_manager duration to read frames from 00:00:00 to 00:00:20.
        video_manager.set_duration(start_time=start_time, end_time=end_time)

        # Set downscale factor to improve processing speed.
        video_manager.set_downscale_factor()

        # Start video_manager.
        video_manager.start()

        # Perform scene detection on video_manager.
        scene_manager.detect_scenes(frame_source=video_manager)

        # Obtain list of detected scenes.
        scene_list = scene_manager.get_scene_list()
        # Like FrameTimecodes, each scene in the scene_list can be sorted if the
        # list of scenes becomes unsorted.

        print('List of scenes obtained:')
        for i, scene in enumerate(scene_list):
            print('    Scene %2d: Start %s / Frame %d, End %s / Frame %d' % (
                i + 1,
                scene[0].get_timecode(),
                scene[0].get_frames(),
                scene[1].get_timecode(),
                scene[1].get_frames(),
            ))

        # We only write to the stats file if a save is required:
        if stats_manager.is_save_required():
            with open(STATS_FILE_PATH, 'w') as stats_file:
                stats_manager.save_to_csv(stats_file, base_timecode)

    finally:
        video_manager.release()