Repository navigation
Description
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 )

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
pawan9 commentedon Oct 10, 2017
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.
ZinniaSun2000 commentedon Oct 17, 2017
how to compile it? Can you give me more hint?
Adonishl commentedon Nov 1, 2017
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?
pawan9 commentedon Nov 1, 2017
@Adonishl what do you see in the opencv cmake configuration (ffmpeg part). It should look similar to this

If not than you would have to build ffmpeg manually.
Adonishl commentedon Nov 3, 2017
@pawan9 in opencv cmake configuration, I got

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:
It really stucked me for weeks!!!If you don't mind to try this, please tell me about your result. Thank you!
pawan9 commentedon Nov 4, 2017
@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::VideoReadereven 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::openmethod.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
and it worked for me.
You should try debugging
InputMediaStream_FFMPEG::openand see what is happening.Adonishl commentedon Nov 5, 2017
@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 :)
mibrahimy commentedon Nov 8, 2017
@Adonishl Greetings!
Did you find anything helpful? I am facing the same issue.
Adonishl commentedon Nov 8, 2017
@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.
mibrahimy commentedon Nov 9, 2017
How do you transcode an rstp stream?
Adonishl commentedon Nov 9, 2017
@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.
basilzeno commentedon Dec 8, 2017
@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,.....
pawan9 commentedon Dec 16, 2017
@basilzeno Is the remote stream working in VLC ?
check the codec of that stream and make sure it is supported by your graphics card.
basilzeno commentedon Dec 16, 2017
@pawan9 yes, It is working in VLC !
pawan9 commentedon Dec 16, 2017
@basilzeno what is the codec and pixel format of the stream ?
basilzeno commentedon Dec 27, 2017
@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?
pawan9 commentedon Dec 28, 2017
@basilzeno Please refer to my comment above, make the changes as described and rebuild OpenCV.
basilzeno commentedon Dec 28, 2017
@pawan9 I made the changes as described, then rebuilt OpenCV again, BUT it's still not working!
Dyex719 commentedon Jun 26, 2018
@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
Dyex719 commentedon Jun 26, 2018
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 nextFramenick1392 commentedon Nov 15, 2018
Getting the same issue here, any update?