cv :: cudacodec :: VideoReader无法播放rtsp流

时间:2017-10-07 05:35:04

标签: c++ opencv ffmpeg

系统信息

  • OpenCV => 3.3.0
  • 操作系统/平台=> Ubuntu 16.04,x86_64
  • 编译器=> gcc版本5.4.1 20160904
  • Cuda => 8.0
  • Nvidia card => GTX 1080 Ti
  • ffmpeg详情
    • libavutil 55. 74.100 / 55. 74.100
    • libavcodec 57.103.100 / 57.103.100
    • libavformat 57. 77.100 / 57. 77.100
    • libavdevice 57. 7.101 / 57. 7.101
    • libavfilter 6.100.100 / 6.100.100
    • libswscale 4. 7.103 / 4. 7.103
    • libswresample 2. 8.100 / 2. 8.100

详细说明

我正在尝试使用cudacodec::VideoReader

播放rtsp流 Rtsp Stream详细信息(来自vlc)

stream_details

此流在vlc和cv::VideoCapture中播放正常,但当我尝试在cudacodec::VideoReader播放时,我收到错误说:

OpenCV Error: Gpu API call (CUDA_ERROR_FILE_NOT_FOUND [Code = 301]) in CuvidVideoSource, file /home/deep/Development/libraries/opencv/opencv/modules/cudacodec/src/cuvid_video_source.cpp, line 66

OpenCV Error: Assertion failed (init_MediaStream_FFMPEG()) in FFmpegVideoSource, file /home/deep/Development/libraries/opencv/opencv/modules/cudacodec/src/ffmpeg_video_source.cpp, line 101

重现的步骤

#include <iostream>
#include "opencv2/opencv_modules.hpp"

#if defined(HAVE_OPENCV_CUDACODEC)

#include <opencv2/core.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/highgui.hpp>

int main(int argc, const char* argv[])
{
    const std::string fname = "rtsp://admin:admin@192.168.1.13/media/video2";

    cv::namedWindow("GPU", cv::WINDOW_NORMAL);

    cv::cuda::GpuMat d_frame;
    cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);

    for (;;)
    {

        if (!d_reader->nextFrame(d_frame))
            break;

        cv::Mat frame;
        d_frame.download(frame);
        cv::imshow("GPU", frame);

        if (cv::waitKey(3) > 0)
            break;
    }
    return 0;
}

#else
int main()
{
    std::cout << "OpenCV was built without CUDA Video decoding support\n" << std::endl;
    return 0;
}
#endif

我尝试使用GDB进行调试,发现在ffmpeg_video_source.cpp bool init_MediaStream_FFMPEG()中直接返回,而不检查if条件。

GDB输出

cv::cudacodec::detail::FFmpegVideoSource::FFmpegVideoSource 
(this=0x402a20 <_start>, fname=...) at /home/deep/Development/libraries/opencv/opencv/modules/cudacodec/src/ffmpeg_video_source.cpp:98
98      cv::cudacodec::detail::FFmpegVideoSource::FFmpegVideoSource(const String& fname) :
(gdb) n
99          stream_(0)
(gdb) n
101         CV_Assert( init_MediaStream_FFMPEG() );
(gdb) s
(anonymous namespace)::init_MediaStream_FFMPEG () at /home/deep/Development/libraries/opencv/opencv/modules/cudacodec/src/ffmpeg_video_source.cpp:94
94              return initialized;
(gdb) display initialized
4: initialized = false
(gdb) s
95          }

更新

我已经解决了这个问题。 solution link

1 个答案:

答案 0 :(得分:1)

在提供的解决方案here中,问题与ffmpeg检测到的像素格式有关。

要检查rtsp像素格式,您可以使用ffprobe。 然后在cap_ffmpeg_impl.hpp内,你应该添加与像素格式相关的案例,如

case AV_PIX_FMT_YUV420P:
case AV_PIX_FMT_YUVJ420P:
    *chroma_format = ::VideoChromaFormat_YUV420;
     break;

然后重建opencv。