Skip to content

cv2.cudacodec.createVideoReader(x2_rma.mp4) #3920

Open
@apurvathakkar-nextgen

Description

@apurvathakkar-nextgen

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions