我是靠谱客的博主 标致水池,这篇文章主要介绍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.1Toolsmingw491_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.15.4mingw491_32bin 目录下,方便运行时找到可用的动态库。或者把ffmpe dll所在的位置加入到QtCreator->项目->运行->Build Environment->PATH下。

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

复制代码
1
DEFINES += __STDC_LIMIT_MACROS
复制代码
1
DEFINES += __STDC_CONSTANT_MACROS
复制代码
1
DEFINES += __STDC_FORMAT_MACROS
复制代码
1
INCLUDEPATH += $$PWD/ffmpeg/include
复制代码
1
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

复制代码
1
2
/** Save the encoder context for easiert access later. */
复制代码
1
2
*output_codec_context = stream->codec;
复制代码
1
复制代码
1
2
/**
复制代码
1
2
* Set the basic encoder parameters.
复制代码
1
2
* The input file's sample rate is used to avoid a sample rate conversion.
复制代码
1
2
*/
复制代码
1
2
3
(*output_codec_context)->channels = OUTPUT_CHANNELS;
复制代码
1
2
(*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);
复制代码
1
2
3
(*output_codec_context)->sample_rate = input_codec_context->sample_rate;
复制代码
1
2
3
(*output_codec_context)->sample_fmt = AV_SAMPLE_FMT_FLTP; //native encode只支持这一种采样率,所以转换时有可能丢失数据
复制代码
1
2
3
(*output_codec_context)->bit_rate = OUTPUT_BIT_RATE;
复制代码
1
复制代码
1
2
/**
复制代码
1
2
* Some container formats (like MP4) require global headers to be present
复制代码
1
2
* Mark the encoder so that it behaves accordingly.
复制代码
1
2
*/
复制代码
1
2
if ((*output_format_context)->oformat->flags & AVFMT_GLOBALHEADER)
复制代码
1
2
(*output_codec_context)->flags |= CODEC_FLAG_GLOBAL_HEADER;
复制代码
1
复制代码
1
复制代码
1
2
av_dict_set(&opts, "strict", "experimental", 0);
复制代码
1
2
/** Open the encoder for the audio stream to use it later. */
复制代码
1
2
error = avcodec_open2(*output_codec_context, output_codec, &opts);
复制代码
1
2
// av_dict_free(&opts);
复制代码
1
2
if (error < 0) {
复制代码
1
2
fprintf(stderr, "Could not open output codec (error '%s')n",
复制代码
1
2
get_error_text(error));
复制代码
1
2
goto cleanup;
复制代码
1
2
}
复制代码
1

最后

以上就是标致水池最近收集整理的关于Windows下Qt5,FFMpeg编译的全部内容,更多相关Windows下Qt5内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部