2013-01-17 138 views
0

在編譯Qt Mac中的ffmpeg示例時,我發現了一個奇怪的問題。在使用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編譯器? (並且我不知道該怎麼辦)

+0

我刪除了對Qt的引用,因爲它與任何東西都沒什麼關係。您可能正在使用Qt Creator,這是一款面向Qt的IDE。 – rubenvb

回答

1

您需要在#include <libavutil/imgutils.h>之前包含libavutil/avutil.h。您還需要添加#include <libavcodec/avcodec.h>

+1

我試圖以這種方式更改庫,但我總是有錯誤.. – polin

+0

「AVRational」錯誤的原因尚未聲明......和錯誤:'av_q2d'未在此範圍內聲明是你沒有包含'libavutil/avutil.h'。修正後編寫一個新的編譯器輸出 – pogorskiy

0

因爲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)