mirror of
https://github.com/hacksider/Deep-Live-Cam.git
synced 2026-07-31 06:17:33 +02:00
fix: clamp video frame seek index (#1790)
Prevent get_video_frame() from seeking to invalid frame positions. The default frame_number=0 now resolves to the first frame instead of -1, and oversized frame requests clamp to the final valid frame instead of seeking past the end. Empty or invalid videos now return None safely after releasing the capture. Affected files: capturer.py Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
This commit is contained in:
+7
-2
@@ -14,8 +14,13 @@ def get_video_frame(video_path: str, frame_number: int = 0) -> Any:
|
||||
if modules.globals.color_correction:
|
||||
capture.set(cv2.CAP_PROP_CONVERT_RGB, 1)
|
||||
|
||||
frame_total = capture.get(cv2.CAP_PROP_FRAME_COUNT)
|
||||
capture.set(cv2.CAP_PROP_POS_FRAMES, min(frame_total, frame_number - 1))
|
||||
frame_total = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||
if frame_total <= 0:
|
||||
capture.release()
|
||||
return None
|
||||
|
||||
target_index = 0 if frame_number <= 1 else min(frame_total - 1, frame_number - 1)
|
||||
capture.set(cv2.CAP_PROP_POS_FRAMES, target_index)
|
||||
has_frame, frame = capture.read()
|
||||
|
||||
if has_frame and modules.globals.color_correction:
|
||||
|
||||
Reference in New Issue
Block a user