首页 > 系统相关 >windows ffmpeg2.8 动态库和静态库32位编译(hx264,opus)

windows ffmpeg2.8 动态库和静态库32位编译(hx264,opus)

时间:2022-08-17 19:56:11浏览次数:100  
标签:enable lib 编译 windows 32 make ffmpeg2.8 -- disable

环境

所有库都是在 msys 中 进行32位编译

msys环境安装

修改 msys 程序目录的 msys2_shell.cmd

rem set MSYS2_PATH_TYPE=inherit 
改为
set MSYS2_PATH_TYPE=inherit

vs Command Prompt 中 打开 msys 继承 x86(x64) vs 的环境变量,

msys 可以使用 cl 编译器,使用对应x86(x64)下的系统依赖库

vsx86 Native Tools Command Prompt for 2019 中输入

msys2_shell.cmd -mingw32 启动 msys

64位 就打开 x64Command Prompt ,和 -mingw64

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.17
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>msys2_shell.cmd -mingw32

opus-1.3.1

根据github的描述,

To build from a distribution tarball, you only need to do the following:

    % ./configure
    % make

To build from the git repository, the following steps are necessary:

0) Set up a development environment:

1) Clone the repository:

    % git clone https://gitlab.xiph.org/xiph/opus.git
    % cd opus

2) Compiling the source

    % ./autogen.sh
    % ./configure
    % make

直接在官网下载压缩包opus-1.3.1.tar.gz进行编译可以少一步

CC=cl ./configure --prefix=`pwd`/build --disable-rtcd
--enable-shared (--enable-static) --disable-asm --disable-rtcd 
make -j8 && make install

指定 --prefix= 可以在make install 的时候把头文件,库和相关文档放到指定路径里面

--disable-asm 纯c实现,不使用针对汇编代码

--disable--rtcd 关闭运行时CPU能力检测,按字面意思理解是少了一个进程或者线程一直检测cpu

x264

git clone http://git.videolan.org/git/x264.git
./configure --disable-asm --enable-static --disable-cli --enable-debug --prefix=`pwd`/build --host=mingw32

静态库后缀是.a,直接加载即可

动态库可以通过vs工具把动态库的.a转为windows.lib

CC=cl \
./configure --disable-asm --enable-shared --enable-static  --disable-cli --enable-debug --prefix=`pwd`/build

编译出来的静态库动态库windows的lib和dll

make -j8 && make install
  • 64位 x64 Native Tools Command Prompt

ffmpeg SDK编译

  • 官方编译文档1

  • 官方编译文档2

    官方编译文档2 中配置 zlib 的方式会把系统环境变量的 $include,$lib 覆盖掉

    set include=%include%;[your absolute path to the zlib folder]
    set lib=%lib%;[your absolute path to the zlib folder]
    

    可以通过 export 引入

  • 安装 yasm

    pacman -S yasm

  • 引入库

    export PKG_CONFIG_PATH=/t/library/deps/opus-1.3.1/lib/pkgconfig/:/t/library/deps/x264/lib/pkgconfig/:$PKG_CONFIG_PATH
    
    pkg-config --cflags opus(x264) 检查头文件引用路径
    pkg-config --libs opus(x264) 检查库路径
    

    不对的话,修改/库路径/pkgconfig/*.pc

  • 编译

    ./configure --prefix=`pwd`/build --toolchain=msvc \
    --enable-gpl \
    --disable-programs \
    --disable-d3d11va \
    --disable-dxva2 \
    --arch=x86 \
    --target-os=win32 \
    --extra-ldflags="/NODEFAULTLIB:libcmt" \
    --extra-cflags="-MD -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WIN32_WINNT=0x0A00" \
    --extra-ldflags="-APPCONTAINER WindowsApp.lib" \
    --enable-shared \
    --disable-static \
    --enable-libx264 \
    --extra-cflags="-I`pwd`/../deps/x264/include"  \
    --extra-ldflags="-LIBPATH:`pwd`/../deps/x264/lib" \
    --enable-libopus
    

    关于 WINAPI_FAMILY

    更多配置配置项查看 configure 文件

    x264 配置到 PKG_CONFIG_PATH 还是会找不到库,要手动指定路径

    make 失败,输出常量中有换行符,删除 config.h#define CC_IDENT 的中文

    make -j8 && make install
    

编译ffmpeg常见问题

编译失败查看 ffmpeg 目录下的config.log,看最后的报错

编译时要使用 -MD 编译,使用 -MT 会有以下错误

LINK : error LNK2001: 无法解析的外部符号 _mainCRTStartup

找不到cl.exe 或者系统.lib一般都是没有从 Native Tools Command Prompt 中打开,例如

cl not found
找不到 msvcrt.lib
找不到 kernel32.lib

windows 使用 ffmpeg 常见问题

  • c++ 使用 ffmpeg 头文件没用 extern "C" {} 包裹起来,编译失败

  • 无法解析的外部符号

    1>avutil.a(random_seed.o) : error LNK2019: 无法解析的外部符号 __imp__CryptAcquireContextA@20,函数 _av_get_random_seed 中引用了该符号
    1>avutil.a(random_seed.o) : error LNK2019: 无法解析的外部符号 __imp__CryptReleaseContext@8,函数 _av_get_random_seed 中引用了该符号
    1>avutil.a(random_seed.o) : error LNK2019: 无法解析的外部符号 __imp__CryptGenRandom@12,函数 _av_get_random_seed 中引用了该符号
    
    #pragma comment(lib, "Advapi32.lib")
    

标签:enable,lib,编译,windows,32,make,ffmpeg2.8,--,disable
From: https://www.cnblogs.com/blackTree/p/16548757.html

相关文章