繁体   English   中英

使用ffmpeg时编译错误

[英]Compile error when using ffmpeg

在Qt Mac中编译ffmpeg的示例期间,我发现了一个奇怪的问题。

我已经安装了ffmpeg库,并在终端上使用cc和gcc编译器测试了此示例,并且在编译和运行时没有任何问题。

但是,当我在Qt中调用库(ffmpeg是C库)来编译示例的相同代码时,g ++编译器给了我很多错误。

我在main.cpp代码中使用了这种结构:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>

extern "C" {
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
}

#include <QDebug>

编译输出给我:

In file included from ../audvid/main.cpp:7:
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_string(char*, int64_t)':
/opt/local/include/libavutil/timestamp.h:48: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:49: error: expected `)'
before 'PRId64' /opt/local/include/libavutil/timestamp.h:49: warning:
spurious trailing '%' in format
/opt/local/include/libavutil/timestamp.h:49: warning: too many
arguments for format /opt/local/include/libavutil/timestamp.h: At
global scope: /opt/local/include/libavutil/timestamp.h:68: error:
'AVRational' has not been declared
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_time_string(char*, int64_t, int*)':
/opt/local/include/libavutil/timestamp.h:70: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:71: error: 'av_q2d' was not
declared in this scope ../audvid/main.cpp: In function 'int
decode_packet(int*, int)': ../audvid/main.cpp:50: error: cannot
convert 'AVRational*' to 'int*' for argument '3' to 'char*
av_ts_make_time_string(char*, int64_t, int*)' ../audvid/main.cpp:73:
error: cannot convert 'AVRational*' to 'int*' for argument '3' to
'char* av_ts_make_time_string(char*, int64_t, int*)'
../audvid/main.cpp:75: error: 'struct AVFrame' has no member named
'channels' ../audvid/main.cpp:84: error: 'struct AVFrame' has no
member named 'channels' ../audvid/main.cpp:90: error: 'struct AVFrame'
has no member named 'channels' ../audvid/main.cpp: In function 'int
open_codec_context(int*, AVFormatContext*, AVMediaType)':
../audvid/main.cpp:112: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp:123: error:
'av_get_media_type_string' was not declared in this scope
../audvid/main.cpp:129: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp: In function 'int
get_format_from_sample_fmt(const char**, AVSampleFormat)':
../audvid/main.cpp:152: warning: comparison between signed and
unsigned integer expressions ../audvid/main.cpp: In function 'int
main(int, char**)': ../audvid/main.cpp:239: error: invalid conversion
from 'void*' to 'uint8_t**' make: *** [main.o] Error 1 make: Leaving
directory
`/Users/polin/Desktop/audvid/audvid-build-    Qt_4_8_0_qt_everywhere_opensource_src_4_8_0_tp-Release'
10:44:37: The process "/usr/bin/make" exited with code 2. Error while
building/deploying project audvid (target: Qt 4.8.0
(qt-everywhere-opensource-src-4.8.0-tp)) When executing step 'Make'

我不明白我在代码中是否犯了错误或者是否必须更改Qt编译器? (而且我不知道该怎么办)

您需要在#include <libavutil/imgutils.h>之前包括libavutil/avutil.h 另外,您还需要添加#include <libavcodec/avcodec.h>

因为ffmpeg用纯C语言编写。某些C99设计与g ++编译器不兼容。 因此,解决它的一种方法是找到“错误的”源代码在哪里,并用C ++设计风格替换它们。 例如

av_get_bytes_per_sample( static_cast<AVSampleFormat>(format) )
#undef av_err2str
#define av_err2str(errnum) \
av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
#undef av_ts2timestr
#define av_ts2timestr(ts, tb) \
av_ts_make_time_string((char*)__builtin_alloca(AV_TS_MAX_STRING_SIZE), ts, tb)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM