Skip to content

cv::cudacodec::VideoReader unable to Play rtsp stream  #9739

Closed

Description

@pawan9
System information (version)
  • OpenCV => 3.3.0
  • Operating System / Platform => Ubuntu 16.04, x86_64
  • Compiler => gcc version 5.4.1 20160904
  • Cuda => 8.0
  • Nvidia card => GTX 1080 Ti
Detailed description

i am trying to play a rtsp stream using cudacodec::VideoReader

Rtsp Stream Details ( from vlc )

stream_details
this stream plays fine in vlc and cv::VideoCapture but when i try to play it in cudacodec::VideoReader i get a error saying:

OpenCV Error: Gpu API call (CUDA_ERROR_FILE_NOT_FOUND [Code = 301]) in CuvidVideoSource, file /home/sumit/Downloads/softwares/opencv/modules/cudacodec/src/cuvid_video_source.cpp, line 66
Invalid UE golomb code
Invalid UE golomb code
OpenCV Error: Unsupported format or combination of formats (Unsupported video source) in FFmpegVideoSource, file /home/sumit/Downloads/softwares/opencv/modules/cudacodec/src/ffmpeg_video_source.cpp, line 110 terminate called after throwing an instance of 'cv::Exception'
what(): /home/sumit/Downloads/softwares/opencv/modules/cudacodec/src/ffmpeg_video_source.cpp:110: error: (-210) Unsupported video source in function FFmpegVideoSource

Steps to reproduce
#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:[email protected]/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

Activity

  1. pawan9 commented on Oct 10, 2017

    @pawan9
    Author

    on debugging found out that OpenCV was compiled without HAVE_FFMPEG flag. Had to maually compile ffmpeg and then recompiled OpenCV and now it works fine.

  2. ZinniaSun2000 commented on Oct 17, 2017

    @ZinniaSun2000

    how to compile it? Can you give me more hint?

  3. Adonishl commented on Nov 1, 2017

    @Adonishl

    Recently, i also encounter with this problem. While I have compiled ffmpeg from source code and added "-D WITH_FFMPEG" flag into OpenCV's compiling, the rtsp/rtmp streams still cannot be decoded. Is there any special tricks?

  4. pawan9 commented on Nov 1, 2017

    @pawan9
    Author

    @Adonishl what do you see in the opencv cmake configuration (ffmpeg part). It should look similar to this
    screenshot from 2017-11-01 17-19-22

    If not than you would have to build ffmpeg manually.

  5. Adonishl commented on Nov 3, 2017

    @Adonishl

    @pawan9 in opencv cmake configuration, I got
    screenshot from 2017-11-02 20-00-26
    however, it works fine with the stream came from an ip camera, but still come to the same error message when i use ffserver to stream a video file as a rtsp stream.
    Actually, I can play this rtsp stream in vlc and use ffmpeg to decode this rtsp stream as well. But still not work in OpenCV.
    Well, an example for ffserver to stream a video file is:

    1. modify the configure file for ffserver("/etc/ffserver.conf") to
    HTTPPort 9999
    RTSPPort 9990
    HTTPBindAddress 0.0.0.0
    MaxClients 1000
    MaxBandWidth 100000
    CustomLog -
    <Stream test>
      Format rtp
      File "/home/video/test.mp4"
    </Stream>
    
    1. Use command "ffserver -f /etc/ffserver.conf", you can get a rtsp stream for the video file(/home/video/test.mp4). And the stream address is "rtsp://localhost:9990/test"
      It really stucked me for weeks!!!If you don't mind to try this, please tell me about your result. Thank you!
  6. pawan9 commented on Nov 4, 2017

    @pawan9
    Author

    @Adonishl I had a similar problem where a stream from a ip camera was playing perfectly in vlc but was not being played by cv::cudacodec::VideoReader even after building it with FFMPEG.

    You should check if the codec and pixel format of your stream (as shown in vlc) are they supported in the InputMediaStream_FFMPEG::open method.

    What i found out in my case was that while vlc detected the pixel format of stream as YUV420P, ffmpeg detected it as YUVJ420P so i made the below mentioned change here

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

    and it worked for me.

    You should try debugging InputMediaStream_FFMPEG::open and see what is happening.

  7. Adonishl commented on Nov 5, 2017

    @Adonishl

    @pawan9 Today I have checked the codec_id and pix_fmt of my stream. And it showed up that ffmpeg detected my stream as AV_CODEC_ID_H264&YUV420P. And these are supported in InputMediaStream_FFMPEG::open. So I don't think it is the similar problem as yours. But still I'd like to thank you for your mention about debugging the source code of OpenCV. I will keep going on that. Thanks a lot :)

  8. mibrahimy commented on Nov 8, 2017

    @mibrahimy

    @Adonishl Greetings!
    Did you find anything helpful? I am facing the same issue.

  9. Adonishl commented on Nov 8, 2017

    @Adonishl

    @ibrahimsherdil Actually, I just found that my video file is encoded by h264. So I tried to transcode it into MPEG1/MPEG2. It worked for me. Maybe you you can try it.

  10. mibrahimy commented on Nov 9, 2017

    @mibrahimy

    How do you transcode an rstp stream?

  11. Adonishl commented on Nov 9, 2017

    @Adonishl

    @ibrahimsherdil You can use FFmpeg command line to transcode any video file/stream. And also you can try vlc to convert/stream a video file/stream.

  12. basilzeno commented on Dec 8, 2017

    @basilzeno

    @pawan9 I have same issue, after applying your suggestion, only rtsp with local IP address is working. I tried to change tcp flag in this file also, but i noticed that opencv forces ffmpeg to use tcp.

    Are there any solutions?

    Error:
    OpenCV Error: Unsupported format or combination of formats (Unsupported video source) in FFmpegVideoSource,.....

    • System information (version):
      • OpenCV => 3.3.1
      • Operating System / Platform => Ubuntu 16.04, x86_64
      • Compiler => gcc version 5.4.
      • Cuda => 8.0
      • Nvidia card => GTX 550 Ti
  13. pawan9 commented on Dec 16, 2017

    @pawan9
    Author

    @basilzeno Is the remote stream working in VLC ?
    check the codec of that stream and make sure it is supported by your graphics card.

  14. basilzeno commented on Dec 16, 2017

    @basilzeno

    @pawan9 yes, It is working in VLC !

  15. pawan9 commented on Dec 16, 2017

    @pawan9
    Author

    @basilzeno what is the codec and pixel format of the stream ?

  16. basilzeno commented on Dec 27, 2017

    @basilzeno

    @pawan9
    For local rtsp url:
    Video Codec: H264
    Pixel Format : YUV420

    For public rtsp url:
    Video Codec: H264
    Pixel Format : YUVJ420

    I can open both using vlc:
    vlc rtsp_stream

    I can write them into mp4 file using ffmpeg:
    Local:
    fmpeg -i rtsp://admin:usrname@IP:Port//* -r 30 -vcodec copy -an -t 60 [Path To mp4 File]
    Public:
    fmpeg -rtsp_transport tcp -i rtsp://IP/***** -r 30 -vcodec copy -an -t 60 [Path To mp4 File]
    HERE, I added rtsp_transport flag, without it there will be error: "Invalid data found when processing input"

    Any ideas to solve the problem?

  17. pawan9 commented on Dec 28, 2017

    @pawan9
    Author

    @basilzeno Please refer to my comment above, make the changes as described and rebuild OpenCV.

  18. basilzeno commented on Dec 28, 2017

    @basilzeno

    @pawan9 I made the changes as described, then rebuilt OpenCV again, BUT it's still not working!

  19. Dyex719 commented on Jun 26, 2018

    @Dyex719

    @Adonishl
    Can you please elaborate how I can transcode a live RTSP stream?
    I tried @pawan9 's fix, but I still get the same error.
    Video Codec: H264
    Pixel Format : YUVJ420

  20. Dyex719 commented on Jun 26, 2018

    @Dyex719

    I have the same exact error however the solution as mentioned by @pawan9 unfortunately doesn't work.

    When I run gdb on opencv/modules/cudacodec/src/ffmpeg_video_source.cpp,

    (gdb) n OpenCV Error: Gpu API call (CUDA_ERROR_FILE_NOT_FOUND [Code = 301]) in CuvidVideoSource, file /usr/deepak/ffmpeg-gpu/opencv/modules/cudacodec/src/cuvid_video_source.cpp, line 66 [New Thread 0x7fffe1328700 (LWP 31246)] [New Thread 0x7fffe0b27700 (LWP 31247)] [New Thread 0x7fffdba98700 (LWP 31248)] [Thread 0x7fffdba98700 (LWP 31248) exited] 22 if (!d_reader->nextFrame(d_frame))

    (gdb) n OpenCV Error: Unsupported format or combination of formats (Unsupported video source) in nextFrame, file /usr/deepak/ffmpeg-gpu/opencv/modules/cudacodec/src/video_reader.cpp, line 128 terminate called after throwing an instance of 'cv::Exception' what(): /usr/deepak/ffmpeg-gpu/opencv/modules/cudacodec/src/video_reader.cpp:128: error: (-210) Unsupported video source in function nextFrame

  21. nick1392 commented on Nov 15, 2018

    @nick1392

    Getting the same issue here, any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: gpu/cuda (contrib)priority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions