PySceneDetect icon indicating copy to clipboard operation
PySceneDetect copied to clipboard

Bug Report for PySceneDetect GitHub Issues

Open luckliu123 opened this issue 6 months ago • 0 comments

Okay, this is the most critical step now. Based on all our rigorous testing, here's a well-structured bug report in English that you can submit to the PySceneDetect GitHub Issues page.

Please replace any placeholder information (like your specific OS details if different, or a link to a sample video if you can provide one) as needed.

Bug Report for PySceneDetect GitHub Issues

Title: VideoStreamCv2 and VideoStreamAv objects missing release() method in PySceneDetect 0.6.6 on Python 3.11.9 and Python 3.9.13

Issue Description:

When using PySceneDetect version 0.6.6 (currently the latest on PyPI as of May 2025) in a clean virtual environment on Windows with Python 3.11.9 or Python 3.9.13, the video object returned by scenedetect.open_video() consistently lacks the release() method. This issue occurs immediately after the object is created and is observed for both the default OpenCV backend (VideoStreamCv2) and the PyAV backend (VideoStreamAv).

This a critical issue as it prevents proper resource deallocation, leading to potential resource leaks and instability, especially when processing multiple files or long videos.

Environment Details (Tested in Clean Virtual Environments):

Operating System: Windows (Please specify your exact Windows version, e.g., Windows 10 Pro Version 22H2, Windows 11, etc.) PySceneDetect Version: 0.6.6 (installed via pip install --no-cache-dir "scenedetect[opencv/pyav]==0.6.6") Python Versions Tested: Python 3.11.9 (64-bit) Python 3.9.13 (64-bit) OpenCV Version (when testing OpenCV backend): opencv-python==4.11.0.86 (pulled in by scenedetect[opencv]==0.6.6 on Python 3.11.9 and Python 3.9.13) Also tested with opencv-python==4.8.0.74 (manually installed first) on Python 3.11.9 with PySceneDetect 0.6.6, same release() issue. NumPy Version (when testing OpenCV backend with OpenCV 4.8.0.74 on Python 3.11.9): numpy==1.26.4 (to resolve opencv-python==4.8.0.74 incompatibility with NumPy 2.x) PyAV (av) Version (when testing PyAV backend): av==14.3.0 (pulled in by scenedetect[pyav]==0.6.6) Steps to Reproduce (in a clean virtual environment):

Test Case 1: OpenCV Backend (e.g., Python 3.9.13)

Create a new virtual environment using Python 3.9.13: Bash

Assuming py -3.9 points to Python 3.9.13

py -3.9 -m venv pysd_py39_cv_test .\pysd_py39_cv_test\Scripts\activate Upgrade pip and install PySceneDetect with OpenCV: Bash

python -m pip install --upgrade pip pip install --no-cache-dir "scenedetect[opencv]==0.6.6" (This typically installs opencv-python==4.11.0.86 and a compatible NumPy, e.g., numpy==2.0.2 as observed in my logs). Run the following minimal Python script (test_pysd_opencv.py): Python

test_pysd_opencv.py

import sys import traceback print(f"--- Minimal PySceneDetect OpenCV Backend Test ---") print(f"Python Executable: {sys.executable}") print(f"Python Version: {sys.version}")

SCENEDETECT_VERSION_TEST = "Not imported" CV2_VERSION_TEST = "Not imported" try: import scenedetect SCENEDETECT_VERSION_TEST = scenedetect.version print(f"PySceneDetect Version: {SCENEDETECT_VERSION_TEST}") except Exception as e: print(f"CRITICAL: Failed to import PySceneDetect: {e}") sys.exit(1) try: import cv2 CV2_VERSION_TEST = cv2.version print(f"OpenCV (cv2) Version: {CV2_VERSION_TEST}") except Exception as e: print(f"WARNING: Failed to import cv2 (OpenCV): {e}")

video_path = "C:/path/to/your/sample_video.mp4" # IMPORTANT: Replace with a valid video path print(f"\nAttempting to open video with OpenCV backend: '{video_path}'") video = None try: video = scenedetect.open_video(video_path) # Default backend is OpenCV if video is None: print(" Result: scenedetect.open_video() returned None.") else: print(f" Video object obtained. Type: {type(video)}") has_release_attr = hasattr(video, 'release') print(f" Checking 'release' attribute: hasattr(video, 'release') = {has_release_attr}") if not has_release_attr: print(" [!!!CRITICAL FINDING!!!]: 'release' attribute is MISSING from the VideoStreamCv2 object.") # Attempt to see if internal capture object exists and has release if hasattr(video, 'capture') and video.capture is not None and
hasattr(video.capture, 'release') and callable(video.capture.release): print(" Internal 'video.capture' object FOUND and has a callable 'release' method.") else: print(" Internal 'video.capture' object or its 'release' method NOT found/callable.") elif callable(getattr(video, 'release', None)): print(" 'release' attribute exists and is callable. Attempting to call...") video.release() print(" video.release() called successfully.") else: print(" 'release' attribute exists but is NOT callable.") except Exception as e: print(f"\nAn error occurred during open_video or checks: {e}") print(traceback.format_exc()) finally: print("\n--- Test Finished ---") Observed Output (example from my Python 3.9.13 + PSD 0.6.6 + OpenCV 4.11.0 test): --- Minimal PySceneDetect OpenCV Backend Test --- Python Executable: C:\Users\Administrator\Desktop\python_testing_envs\pysd_py3913_env\Scripts\python.exe Python Version: 3.9.13 (...) [MSC v.1929 64 bit (AMD64)] PySceneDetect Version: 0.6.6 OpenCV (cv2) Version: 4.11.0

Attempting to open video with OpenCV backend: 'C:/Users/Administrator/Desktop/导入/127.mp4' Backend pyav not available. Trying another backend: opencv Video object obtained. Type: <class 'scenedetect.backends.opencv.VideoStreamCv2'> Checking 'release' attribute: hasattr(video, 'release') = False [!!!CRITICAL FINDING!!!]: 'release' attribute is MISSING from the VideoStreamCv2 object. Internal 'video.capture' object FOUND and has a callable 'release' method.

--- Test Finished --- (Note: The "Backend pyav not available" message appears if PyAV isn't also installed, PySceneDetect then tries OpenCV. The key is that the VideoStreamCv2 object from the OpenCV backend is missing release.) Test Case 2: PyAV Backend (e.g., Python 3.11.9)

Create a new virtual environment using Python 3.11.9: Bash

Assuming py -3.11 points to Python 3.11.9

py -3.11 -m venv pysd_py311_pyav_test .\pysd_py311_pyav_test\Scripts\activate Upgrade pip. Then, to ensure import scenedetect doesn't fail due to a missing OpenCV (as observed if OpenCV is completely absent), install a minimal OpenCV first, then PySceneDetect with PyAV: Bash

python -m pip install --upgrade pip pip install --no-cache-dir "opencv-python==4.8.0.74" # Or any version that allows scenedetect to import pip install --no-cache-dir "scenedetect[pyav]==0.6.6" (This typically installs av==14.3.0 as per my logs). Run the following minimal Python script (test_pysd_pyav.py): Python

test_pysd_pyav.py

import sys import traceback print(f"--- Minimal PySceneDetect PyAV Backend Test ---") print(f"Python Executable: {sys.executable}") print(f"Python Version: {sys.version}")

SCENEDETECT_VERSION_TEST = "Not imported" CV2_VERSION_TEST = "Not imported" # Will be imported by scenedetect if present AV_VERSION_TEST = "Not imported" try: import scenedetect SCENEDETECT_VERSION_TEST = scenedetect.version print(f"PySceneDetect Version: {SCENEDETECT_VERSION_TEST}") except Exception as e: print(f"CRITICAL: Failed to import PySceneDetect: {e}") sys.exit(1) try: import cv2 CV2_VERSION_TEST = cv2.version print(f"OpenCV (cv2) Version (if present for base import): {CV2_VERSION_TEST}") except ImportError: print(f"Note: cv2 (OpenCV) not found for import by this test script directly.") except Exception: pass # Ignore other cv2 import errors here try: import av AV_VERSION_TEST = av.version print(f"PyAV (av) Version: {AV_VERSION_TEST}") except Exception as e: print(f"WARNING: Failed to import PyAV (av): {e}")

video_path = "C:/path/to/your/sample_video.mp4" # IMPORTANT: Replace with a valid video path print(f"\nAttempting to open video with PyAV backend: '{video_path}'") video = None try: video = scenedetect.open_video(video_path, backend='pyav') # Explicitly use PyAV if video is None: print(" Result: scenedetect.open_video(..., backend='pyav') returned None.") else: print(f" Video object obtained. Type: {type(video)}") # Expected: VideoStreamAv has_release_attr = hasattr(video, 'release') print(f" Checking 'release' attribute: hasattr(video, 'release') = {has_release_attr}") if not has_release_attr: print(" [!!!CRITICAL FINDING!!!]: 'release' attribute is MISSING from the VideoStreamAv object.") elif callable(getattr(video, 'release', None)): print(" 'release' attribute exists and is callable. Attempting to call...") video.release() print(" video.release() called successfully.") else: print(" 'release' attribute exists but is NOT callable.") except Exception as e: print(f"\nAn error occurred during open_video (backend='pyav') or checks: {e}") print(traceback.format_exc()) finally: print("\n--- Test Finished ---") Observed Output (example from my Python 3.11.9 + PSD 0.6.6 + AV 14.3.0 + OpenCV 4.8.0 test): --- Minimal PySceneDetect PyAV Backend Test --- Python Executable: C:\Users\Administrator\Desktop\python_environments\pysd_venv\Scripts\python.exe Python Version: 3.11.9 (...) [MSC v.1938 64 bit (AMD64)] PySceneDetect Version: 0.6.6 OpenCV (cv2) Version (if present for base import): 4.8.0 PyAV (av) Version: 14.3.0

Attempting to open video with PyAV backend: 'C:/Users/Administrator/Desktop/导入/127.mp4' Video object obtained. Type: <class 'scenedetect.backends.pyav.VideoStreamAv'> Checking 'release' attribute: hasattr(video, 'release') = False [!!!CRITICAL FINDING!!!]: 'release' attribute is MISSING from the VideoStreamAv object.

--- Test Finished --- Expected Behavior:

The video object returned by scenedetect.open_video() (whether VideoStreamCv2 or VideoStreamAv) should always have a callable release() method for proper resource management.

Actual Behavior:

In both Python 3.11.9 and Python 3.9.13 environments, with PySceneDetect 0.6.6, the video objects returned by open_video() are missing the release() attribute immediately after creation, for both OpenCV and PyAV backends. The VideoStreamCv2 object does seem to contain an internal capture object (the raw cv2.VideoCapture) which itself has a release() method, suggesting the wrapper is failing to expose or correctly inherit/set its own release method.

Impact:

This defect can lead to significant resource leaks (memory, file handles) and program instability, especially in batch processing scenarios.

This detailed report should give the PySceneDetect developers enough information to investigate the issue. Good luck!

luckliu123 avatar May 11 '25 16:05 luckliu123