天天看點

Windows下Qt5,FFMpeg編譯

1. 下載下傳安裝Qt5.4.1windows mingw安裝包

http://download.qt.io/official_releases/qt/5.4/5.4.1/qt-opensource-windows-x86-mingw491_opengl-5.4.1.exe

2. 下載下傳msys,并安裝。

http://downloads.sourceforge.net/mingw/MSYS-1.0.11.exe

3. 啟動MSYS,cp /etc/fstate.sample /etc/fstate

4. 編譯/etc/fstate, 把檔案中mingw的位置指向Qt5.4.1\Tools\mingw491_32 下。

5. 下載下傳FFMPEG并解壓

http://www.ffmpeg.org/releases/ffmpeg-2.2.tar.gz

6. 修改FFmepg中的Configure檔案, 把所有的pr指令注釋掉。

7. 執行.  ./configure --disable-yasm --enable-shared  --enable-static  --prefix=/installdir

大功告成

Windows下在QT中使用FFMPEG時

1.在工程目錄下建立ffmpeg檔案夾。

拷貝ffmpeg的所有頭檔案到$$PWD/ffmpeg/include下。

拷貝ffmpeg編譯好的lib*.dll.a 到$$PWD/ffmpeg/lib下,并重命名為lib*.a

拷貝ffmpeg編譯好的*.dll 到Qt5.4.1\5.4\mingw491_32\bin 目錄下,友善運作時找到可用的動态庫。或者把ffmpe dll所在的位置加入到QtCreator->項目->運作->Build Environment->PATH下。

2.在.pro中加入下面内容

DEFINES += __STDC_LIMIT_MACROS      
DEFINES += __STDC_CONSTANT_MACROS      
DEFINES += __STDC_FORMAT_MACROS      
INCLUDEPATH += $$PWD/ffmpeg/include      
LIBS += -L$$PWD/ffmpeg/lib -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale      

編譯FFMPEG需要使用第三方庫時,比如faac, x264時,

 使用export CPPFLAGS=-I/g/workspace/Mp4v2Test/aacd/faac-1.28/build/include/ 制定第三方庫的頭檔案位置

使用 export LDFLAGS=-L/g/workspace/Mp4v2Test/aacd/faac-1.28/build/lib/ 指定第三方庫的庫檔案位置。

$ ./configure --disable-yasm --enable-shared  --enable-static  --prefix=/g/workspace/ffmpeg-2.2/build/ --enable-libfaac --enable-nonfree

FFMPEG使用native aac encode

/** Save the encoder context for easiert access later. */      
*output_codec_context = stream->codec;      
/**      
* Set the basic encoder parameters.      
* The input file's sample rate is used to avoid a sample rate conversion.      
*/      
(*output_codec_context)->channels       = OUTPUT_CHANNELS;      
(*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);      
(*output_codec_context)->sample_rate    = input_codec_context->sample_rate;      
(*output_codec_context)->sample_fmt     = AV_SAMPLE_FMT_FLTP; //native encode隻支援這一種采樣率,是以轉換時有可能丢失資料      
(*output_codec_context)->bit_rate       = OUTPUT_BIT_RATE;      
/**      
* Some container formats (like MP4) require global headers to be present      
* Mark the encoder so that it behaves accordingly.      
*/      
if ((*output_format_context)->oformat->flags & AVFMT_GLOBALHEADER)      
(*output_codec_context)->flags |= CODEC_FLAG_GLOBAL_HEADER;      
av_dict_set(&opts, "strict", "experimental", 0);      
/** Open the encoder for the audio stream to use it later. */      
error = avcodec_open2(*output_codec_context, output_codec, &opts);      
//    av_dict_free(&opts);      
if (error < 0) {      
fprintf(stderr, "Could not open output codec (error '%s')\n",      
get_error_text(error));      
goto cleanup;      
}      

繼續閱讀