【问题标题】:FFmpeg avformat_open_input not working: Invalid data found when processing inputFFmpeg avformat_open_input 不起作用:处理输入时发现无效数据
【发布时间】:2017-02-08 06:28:13
【问题描述】:

这是我第一次使用 FFmpeg。我尝试使用avformat_open_input 打开的每种媒体文件都会返回“处理输入时发现无效数据”。我正在使用 32 位 FFmpeg 构建版本:92de2c2。我根据这个答案设置了我的 VS2015 项目:Use FFmpeg in Visual Studio。这段代码可能出了什么问题?

#include "stdafx.h"
#include <stdio.h>

extern "C"
{
    #include "libavcodec/avcodec.h"
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
}

int main(int argc, char *argv[])
{
    AVFormatContext *pFormatCtx = NULL;
    avcodec_register_all();

    const char* filename = "d:\\a.mp4";
    int ret = avformat_open_input(&pFormatCtx, filename, NULL, NULL);
    if (ret != 0) {
        char buff[256];
        av_strerror(ret, buff, 256);
        printf(buff);
        return -1;
    }
}

【问题讨论】:

  • 您是否尝试过其他视频文件?有时这个错误意味着输入文件的格式无效。
  • 是的,我尝试了几种不同的视频文件和格式,包括 mp4、mkv、avi、mp3。我知道这些文件可以工作,因为当我通过 ffmpeg.exe 处理它们时,它们的处理没有问题

标签: visual-c++ visual-studio-2015 ffmpeg


【解决方案1】:

你忘了打电话给av_register_all,ffmpeg 没有注册 demuxer/muxer。

#include "stdafx.h"
#include <stdio.h>

extern "C"
{
    #include "libavcodec/avcodec.h"
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
}

int main(int argc, char *argv[])
{
    AVFormatContext *pFormatCtx = NULL;
    av_register_all();
    avcodec_register_all();

    const char* filename = "d:\\a.mp4";
    int ret = avformat_open_input(&pFormatCtx, filename, NULL, NULL);
    if (ret != 0) {
        char buff[256];
        av_strerror(ret, buff, 256);
        printf(buff);
        return -1;
    }
}

【讨论】:

  • 我这样做了。仍然得到同样的错误。我正在从 ftp 获取文件。对于 smb 它的工作正常
猜你喜欢
  • 2019-08-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2016-06-22
  • 2014-05-03
  • 2019-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多