这是我第一次使用FFmpeg。我尝试用avformat_open_input
打开的每种类型的媒体文件都返回"处理输入时发现无效数据"。我使用的是32位FFmpeg构建版本:92de2c2。我根据这个答案设置我的VS2015项目:在Visual Studio中使用FFmpeg。这段代码可能出了什么问题?
#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;
}
}
您忘记呼叫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;
}
}