zoukankan      html  css  js  c++  java
  • ffmpeg avformat_open_input返回失败的解决办法

    用ffmpeg做的第一个程序,参考网上的代码,就出现了一些问题,其中avformat_open_input返回失败。

    下面是我在网上收集到的失败信息的相关解决:

    ////////////////////////////////////////////////////////////////////////////////////

    很多朋友在使用新版本的ffmpeg时,都遇到了avformat_open_input返回失败的问题。

    在下也遇到了此问题。在stackoverflow上搜了一下,解决方法如下。

    在调用avformat_open_input之前,先调用如下接口初始化一下即可。

    av_register_all();

    这算是新版本ffmpeg代码流程的一个变化了。

     老版本的ffmpeg,代码流程如下:

    avcodec_register_all();

    av_open_input_file(&pFormatCtx, "/path/to/video/file",  NULL,  0,  NULL);

     而新版本中,代码流程如下:

    av_register_all();

    avformat_open_input(&pFormatCtx, "/path/to/video/file", NULL, NULL);

     最后,我们要使用ffmpeg的过程中,遇到返回值失败时,可以尝试将失败原因打印出来。

    方法如下:

    if( err_code=avformat_open_input(&pFormatCtx, test_file, NULL, NULL) )
    {
        av_strerror(err_code, buf, 1024);
        printf("Couldn't open file %s: %d(%s)", test_file, err_code, buf);
        return -1; 
    }

    最后再列几个变化了的接口:

    老版本:

    avcodec_open

    avcodec_decode_video

    img_convert

     

    新版本:

    avcodec_open2

    avcodec_decode_video2

    sws_scale

    ////////////////////////////////////////////////////////////////////////////////////

    而我真正的解决方法是,打印出来的信息显示,avformat_open_input函数返回-2;然后我查看了下-2信息的错误原因是no file or directory

    所以我再想,难道文件名不对?然后仔细的查看了下,不是的,但为什么按f5调试,还是会失败,后面才知道,原来是因为我需要打开的视频文件存的位置不对,test.mp4文件应该放在和.cpp一起的,而我放在了debug目录下,所以不行,打不开。

  • 相关阅读:
    P5136 sequence(矩阵快速幂)
    P5135 painting(组合数)
    CF888E Maximum Subsequence(meet in the middle)
    P4463 [国家集训队] calc(拉格朗日插值)
    CF364D Ghd(随机化)
    P3270 [JLOI2016]成绩比较(拉格朗日插值)
    bzoj3453: tyvj 1858 XLkxc(拉格朗日插值)
    P4593 [TJOI2018]教科书般的亵渎(拉格朗日插值)
    tomcat8版本实现虚拟主机
    NFS网络文件系统方案
  • 原文地址:https://www.cnblogs.com/lihaiping/p/return-2.html
Copyright © 2011-2022 走看看