Can't open HTTP stream: Error opening file (../cap_ffmpeg_impl.hpp:529)

♀尐吖头ヾ 提交于 2019-12-11 02:48:26

问题


Here is my link format to HTTP stream(user, password and address was changed to dummy):

http://username:password@192.168.0.104:8093/axis-cgi/mjpg/video.cgi

This stream works perfectly in VLC. However, I can't open it using OpenCV library.

Here is my code:

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

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cap;
    const string videoStreamAddress = "http://username:password@192.168.0.104:8093/axis-cgi/mjpg/video.cgi";
    cap.open(videoStreamAddress);
    if (!cap.isOpened())
    {
        cout << endl << "Videostream not found !" << endl;
        system("pause");
        return 0;
    }

    Mat frame;

    while(1)
    {
        cap >> frame;
        if (frame.empty())
            break;

        imshow("IPcamera", frame);

        int c = waitKey(1);
        if (c == 27)
        {
            break;
        }
    }

    waitKey(0);
    return 0;
}

This gives me an error:

warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:529)

which points to:

bool CvCapture_FFMPEG::open( const char* _filename )
{
    unsigned i;
    bool valid = false;

    close();

#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
    int err = avformat_open_input(&ic, _filename, NULL, NULL);
#else
    int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
#endif

    if (err < 0)
    {
        CV_WARN("Error opening file");
        goto exit_func;
    }
...

What could be a problem?


回答1:


Did you try opening a video file in your machine using Videocapture? (Just add the path to the video file to the place where you've put the URL) I assume that it fails in the same way. So this is a problem with ffmpeg. You'll need to build OpenCV yourself with ffmpeg support. (Do some search on gstreamer as well. I'm not much familiar with that).

Also you can try using another software like ManyCam in the middle. It enables you to read the stream easily in the same way you are reading from a webcam.



来源:https://stackoverflow.com/questions/19834202/cant-open-http-stream-error-opening-file-cap-ffmpeg-impl-hpp529

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!