VideoCapture open vedio file fail

来源:互联网 发布:钥匙扣淘宝 编辑:程序博客网 时间:2024/06/07 09:13
在Linux(readhat)系统下,以下程序程序编译可以完成,但是运行时则不能打开视频文件,运行时没有提示出现任何错误。

首先确认的是文件的路径没问题,使用绝对路径也测试了还是不行的。

在网上查了没有查到类似的,希望各位帮忙看下,谢谢。

int main(int argc, char** argv)
{
    string input_name = argc == 2 ? argv[1]:"./filename.mp4";
    Mat frame;
    VideoCapture cap;

    cap.open(input_name);
    if(!cap.isOpened())      //执行到这返回false
    {
        cerr << "cannot open video or the specified"<<input_name<<"does not exist in this directory!"<<endl;
        return 1;
    }

    cap.read(frame);
    if(frame.empty())
    {
        cerr <<"the video may be broken!"<<endl;
        return 1;
    }

    cap.release();
    cout << "the video is read successfully!" << endl;
    return 0;

}


经过几天查找终于找到原因了,是没有找到ffmpeg解码器:
在编译openCV时,
设置环境变量PKG_CONFIG_PATH,在~/.bashre中添加如下一行,即可
    export PKG_CONFIG_PATH=/usr/local/ffmpeg/lib/pkgconfig : $PKG_CONFIG_PATH
source ~/.bashre

0 0
原创粉丝点击