opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

cv2.cudacodec.createVideoReader(x2_rma.mp4)

Open apurvathakkar-nextgen opened this issue 8 months ago • 2 comments

Traceback (most recent call last): File "/home/ubuntu/apurva.thakkar/video_analysis/debug.py", line 39, in process_video_with_gpu(video_path) File "/home/ubuntu/apurva.thakkar/video_analysis/debug.py", line 13, in process_video_with_gpu cap = cv2.cudacodec.createVideoReader(video_path) cv2.error: OpenCV(4.12.0-dev) /home/ubuntu/opencv/modules/core/include/opencv2/core/private.cuda.hpp:112: error: (-213:The function/feature is not implemented) The called functionality is disabled for current build or platform in function 'throw_no_cuda'

This is my code import cv2 import time import subprocess

Function to check GPU usage

def check_gpu_usage(): # Run nvidia-smi and capture output result = subprocess.run(['nvidia-smi'], stdout=subprocess.PIPE) print(result.stdout.decode())

def process_video_with_gpu(video_path): # Use the GPU decoder cap = cv2.cudacodec.createVideoReader(video_path) fps = cap.get(cv2.CAP_PROP_FPS)

frame_count = 0
total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

while True:
    ret, frame = cap.read()
    if not ret:
        break
    
    # Process the frame (for now, just print frame count)
    frame_count += 1
    print(f"Processing frame {frame_count}/{total_frames}")
    
    # Check GPU usage after processing each frame
    if frame_count % 10 == 0:  # Check every 10 frames
        check_gpu_usage()
    
    time.sleep(0.1)  

cap.release()

Run the test

if name == "main": video_path = 'x2_rma.mp4'
process_video_with_gpu(video_path)

apurvathakkar-nextgen avatar Apr 08 '25 01:04 apurvathakkar-nextgen