我一直在尝试在Linux上自动运行几个小时,或者用于Windows。我想用ffmpeg链接一个程序(PhenoCam,但这个问题只是下面列出的短样本ffmpeg程序。)
目前我在Linux上,使用mingw编译并使用Zeranoe ffmpeg builds。目录设置如下所示:
dumpVideoInfo.c
+ bin
avformat-54.dll
avutil-51.dll
+ lib
avcodec.lib
avcodec.dll.a
avutil.lib
avutil.dll.a
尝试动态链接.dll文件会导致无法识别文件格式错误。
$ i586-mingw32msvc-gcc -v -Wall -Iinclude dumpVideoInfo.c -o dumpVideoInfo.exe -L./bin64 -lavformat-54 -lavutil-51
./bin64/avformat-54.dll: file not recognized: File format not recognized
尝试将其与.lib / .dll.a链接,导致未定义的引用错误:
$ i586-mingw32msvc-gcc -v -Wall -Iinclude dumpVideoInfo.c -o dumpVideoInfo.exe -L./lib64 -lavformat -lavutil
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0x30): undefined reference to `_av_register_all'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0x6e): undefined reference to `_avformat_open_input'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xbf): undefined reference to `_avformat_find_stream_info'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xef): undefined reference to `_av_dump_format'
/tmp/ccSKJQAc.o:dumpVideoInfo.c:(.text+0xfe): undefined reference to `_av_free'
正如上面的bin64 / lib64目录所示,我使用的是64位库。更改为32位库后,上面的错误消失了。
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
int main(int argc, char *argv[])
{
char *filename;
if (argc > 1) {
filename = argv[1];
} else {
printf("No video file given.");
return 2;
}
av_register_all();
AVFormatContext *pFormatContext = NULL;
printf("Reading info for file %s.\n", filename);
fflush(stdout);
int ret;
if ((ret = avformat_open_input(&pFormatContext, filename, NULL, NULL)) != 0) {
printf("Could not open file %s.\n", filename);
return 2;
}
if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
printf("No stream information found.\n");
return 2;
}
av_dump_format(pFormatContext, 0, filename, 0);
av_free(pFormatContext);
return 0;
}
感谢您的回答。