FFmpeg编译以及遇到的问题_Windows平台

目录

0.1.环境:

0.2.准备:

1.下载并安装MinGw&msys

1.1.配置vcvars

1.2.link.exe重命名

2.下载并配置yasm

3.pkg-config&libglib

4.FFmpeg

5.toolchain=msvc

6.C99-to-C89

6.1.修改FFmpeg的configure文件cc_default

6.2.配置C99-to-C89 Converter & Wrapper

6.3.配置C99的头文件

7.编译

x.配置与编译可能会遇到的问题:

x.1.没有配置yasm.exe

x.2.没有配置pkg-config.exe

x.3.没有配置libglib-2.0-0.dll

x.4.没有配置toolchain=msvc

x.5.没有配置C99-to-C89

x.6.没有配置C99的头文件

x.7.引用lib冲突

x.8.处理器架构位数不一致


0.1.环境:

OS:Win7-64bit
VS:VS2010/VS2013+

0.2.准备:

1.MinGw&msys
2.yasm
3.pkg-config&libglib
4.FFmpeg
5.toolchain=msvc
6.C99-to-C89(VS2010/VS2012需要配置,VS2013+不需要)

1.下载并安装MinGw&msys

mingw-get-setup.exe,MinGw和msys会一起安装的,msys会安装在MinGW目录下。

1.1.配置vcvars

MinGW\msys\1.0\msys.bat中第二行插入:

call "E:\Win7Ultimate64OS\VS2010\VC\bin\vcvars32.bat"
这是针对32位处理器,等价于arch=x86

call "E:\Win7Ultimate64OS\VS2010\VC\bin\amd64\vcvars64.bat"
这是针对64位处理器,等价于arch=x86_64

1.2.link.exe重命名

为了避免MinGW link与MSVC link冲突:
MinGW\msys\1.0\bin\link.exe
link.exe 重命名为:link_rename.exe

2.下载并配置yasm

yasm-1.2.0-win32.exe(或者yasm-1.3.0-win64.exe)

重命名为yasm.exe并且配置路径(以下任选一个):
E:\Win7Ultimate64OS\MinGW\bin\
E:\Win7Ultimate64OS\MinGW\msys\1.0\bin\
C:\Windows\
C:\Windows\SysWOW64\
C:\Windows\System32\ 配置在这个目录不行
但是建议选择前2个目录。同时因为当前操作系统是64bit,所以这里选择System32无效。

3.pkg-config&libglib

pkg-config.exe
libglib-2.0-0.dll

配置路径:
MinGW\bin\

4.FFmpeg

下载FFmpeg源码

5.toolchain=msvc

编译参数”工具链“toolchain使用msvc。

可以在FFmpeg的configure文件中找到toolchain和msvc。

6.C99-to-C89

VS2010/VS2012需要配置,VS2013+不需要。

因为FFmpeg用到C99语法标准,但是VS2010和VS2012对C99的支持很少,所以编译过程中需要将C99语法转为C89语法。VS2013已经开始支持更多的C99标准,所以无需进行这一步。

6.1.修改FFmpeg的configure文件cc_default

修改configure中toolchain分支msvc的编译器为c99wrap cl:

if [ -z "$cl_major_ver" ] || [ $cl_major_ver -ge 18 ]; then
cc_default="cl" 改为 cc_default="c99wrap cl"
这里主要的原因是cl_major_ver的长度为0,所以 if [ -z "$cl_major_ver" ]成立。

6.2.配置C99-to-C89 Converter & Wrapper

c99conv.exe

c99wrap.exe

MinGW\bin\ 或者 MinGW\msys\1.0\bin\

6.3.配置C99的头文件

inttypes.h

stdint.h

Microsoft Visual Studio 10.0\VC\include\

7.编译

双击msys.bat进入类Linux系统,进入FFmpeg目录;

编译脚本:build-ffmpeg-win32.sh

#! /bin/bash
./configure \
--disable-shared \
--disable-swresample \
--disable-avresample \
--enable-swscale \
--disable-avformat \
--disable-avfilter \
--disable-pthreads \
--disable-ffprobe \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-network \
--disable-doc \
--disable-debug \
--disable-symver \
--disable-postproc \
--disable-stripping \
--disable-iconv \
--enable-small \
--enable-version3 \
--enable-gpl \
--enable-decoder=h264 \
--enable-parser=h264 \
--enable-decoder=hevc \
--enable-static \
--enable-memalign-hack \
--cpu=i686 \
--toolchain=msvc \
--extra-cflags=-fno-common \
--prefix=$PWD/../build_output/x86/

./build-ffmpeg-win32.sh,执行编译脚本,需要一段时间

make,编译,需要一段时间

make install

 

x.配置与编译可能会遇到的问题:

x.1.没有配置yasm.exe

执行编译脚本,报错如下:

yasm/nasm not found or too old. Use --disable-yasm for a crippled build.

x.2.没有配置pkg-config.exe

执行编译脚本,告警如下:

WARNING: pkg-config not found, library detection may fail.

x.3.没有配置libglib-2.0-0.dll

执行编译脚本,弹窗系统错误:

pkg-config.exe - 系统错误

无法启动此程序,因为计算机中丢失 libglib-2.0-0.dll。尝试重新安装该程序以解决此问题。

x.4.没有配置toolchain=msvc

引用静态库,报错如下:

1>libavutil.a(display.o) : error LNK2019: 无法解析的外部符号 _hypot,该符号在函数 _av_display_rotation_get 中被引用

1>libavutil.a(error.o) : error LNK2019: 无法解析的外部符号 _strerror_r,该符号在函数 _av_strerror 中被引用

1>E:\VisualCpp2010Project\Win32ConsoleProject\VideoCodec\Debug\VideoCodec.exe : fatal error LNK1120: 2 个无法解析的外部命令

x.5.没有配置C99-to-C89

编译,报错如下:

c99wrap cl is unable to create an executable file.

If c99wrap cl is a cross-compiler, use the --enable-cross-compile option.

Only do this if you know what cross compiling means.

C compiler test failed.

x.6.没有配置C99的头文件

编译,报错如下:

CC libavcodec/012v.o

make: *** [libavcodec/012v.o] Error 1

x.7.引用lib冲突

引用lib时,libcmt.lib与msvcrtd.lib冲突:

LINK : warning LNK4098: 默认库“msvcrtd.lib”与其他库的使用冲突;请使用 /NODEFAULTLIB:library

msvcrtd.lib(cinitexe.obj) : warning LNK4098: 默认库“libcmt.lib”与其他库的使用冲突;请使用 /NODEFAULTLIB:library

libcmt.lib(crt0.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用

解法如下:

第一种:VS->Project->属性->配置属性->链接器->输入->忽略特定默认库->libcmt.lib

第二种:FFmpeg的编译脚本中加入--extra-ldflags="/NODEFAULTLIB:libcmt"

x.8.处理器架构位数不一致

应用程序和引用库编译时选定的处理器架构不一致,导致API无法解析:

error LNK2019: 无法解析的外部符号 _av_init_packet

error LNK2019: 无法解析的外部符号 _avcodec_open2

error LNK2019: 无法解析的外部符号 _av_frame_alloc

error LNK2019: 无法解析的外部符号 _avcodec_alloc_context3

error LNK2019: 无法解析的外部符号 _avcodec_find_decoder

error LNK2019: 无法解析的外部符号 _avcodec_register_all

error LNK2019: 无法解析的外部符号 _av_frame_free

error LNK2019: 无法解析的外部符号 _av_free

error LNK2019: 无法解析的外部符号 _avcodec_close

error LNK2019: 无法解析的外部符号 _avcodec_decode_video2

fatal error LNK1120: 10 个无法解析的外部命令

所以:32位程序引用32位库,64位程序引用64位库

编译脚本中默认--arch=x86,是编译32位库,可以缺省

编译脚本中指定--arch=x86_64,是编译64位库,不可缺省

至此,就可以使用FFmpeg愉快地开发音视频应用了。

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值