opencv / opencv/opencv-python

[CUDA] opencv cannot decode rtsp video stream

Open
#1,037 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

Expected behaviour

opencv-cuda decode rstp video stream success

Actual behaviour

opencv-cuda can decode mp4 video file, but cannot decode rtsp video stream, with the fault is 【Segmentation fault (core dumped)】

Steps to reproduce

I create docker container and compile opencv-cuda:

docker run -it --network host --gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,video  nvidia/cuda:12.0.0-cudnn8-devel-ubuntu20.04 bash
## compile ffmpeg
## compile opencv-python
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.8.0
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 4.8.0

compile result is :
image

NVIDIA CUDA is YES and contain NVCUVID

main code
1 - decode mp4 video file
import cv2

s = "test2.mp4"
cap = cv2.cudacodec.createVideoReader(s)
frame_id = 0
while 1:
    _, img_gpu = cap.nextFrame()
    if frame_id == 100:
        img_cpu = img_gpu.download()
        print(img_cpu.shape)
        break

    frame_id += 1

the result is
image

2 - decode rtsp video stream
import cv2

s = "rtsp://128.8.84.224:8554/rtsp/test"
cap = cv2.cudacodec.VideoReader(s)
frame_id = 0
while 1:
    _, img_gpu = cap.nextFrame()
    if frame_id == 100:
        img_cpu = img_gpu.download()
        print(img_cpu.shape)
        break

    frame_id += 1

the result is
image
error is in 【_, img_gpu = cap.nextFrame()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Docker CUDA 12.0.0 Ubuntu 20.04 setup and the OpenCV 4.8.0 build described in the issue. Compare the Python paths using createVideoReader for MP4 and VideoReader for RTSP, focusing on the cap.nextFrame() call; the issue is done when the RTSP stream decodes without a segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.