Skip to content

Instantly share code, notes, and snippets.

@adibMosharrof
Created February 5, 2021 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adibMosharrof/562107d28657808c6cd138cec93c2acf to your computer and use it in GitHub Desktop.
Save adibMosharrof/562107d28657808c6cd138cec93c2acf to your computer and use it in GitHub Desktop.
PySceneDetect extra frames error
from scenedetect.frame_timecode import FrameTimecode
from scenedetect import VideoManager, SceneManager, StatsManager
from scenedetect.detectors import ContentDetector
import cv2
threshold = 50
#please specify the video path
video_path = './tmp/test1.mp4'
#you can find the video at the url below
# video_path = 'https://vimeo.com/508743795'
video = cv2.VideoCapture(video_path)
video_manager = VideoManager([video_path])
stats_manager = StatsManager()
scene_manager = SceneManager(stats_manager)
scene_manager.add_detector(
ContentDetector(threshold=threshold))
base_timecode = video_manager.get_base_timecode()
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)
scenes = scene_manager.get_scene_list(base_timecode)
num_frames = video.get(cv2.CAP_PROP_FRAME_COUNT)
print(f'total frames in video {num_frames}')
print(f'last scene {scenes[-1]}')
video.set(1,scenes[-1][1].get_frames())
_,frame = video.read()
print(len(frame))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment