在Msys2 for Visual Studio中使用x264编译ffmpeg的静态库,但从未找到libx264

在Msys2 for Visual Studio中使用x264编译ffmpeg的静态库,但从未找到libx264,ffmpeg,configure,msys2,libx264,Ffmpeg,Configure,Msys2,Libx264,之前使用MSYS2和Visual Studio 2015 x64工具链将ffmpeg 4.2.2下载并编译为静态库。我想从VLC/VideoLan添加x264编解码器,并将其编译到静态库中。但是,运行Configure for ffmpeg会产生一个错误,提示“libx264未找到” 我在“/c/ThirdParty/opt/ffmpeg-4.2.2”处构建了ffmpeg,没有使用VideoLAN的x264,在“/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_-bui

之前使用MSYS2和Visual Studio 2015 x64工具链将ffmpeg 4.2.2下载并编译为静态库。我想从VLC/VideoLan添加x264编解码器,并将其编译到静态库中。但是,运行Configure for ffmpeg会产生一个错误,提示“libx264未找到”

我在“/c/ThirdParty/opt/ffmpeg-4.2.2”处构建了ffmpeg,没有使用VideoLAN的x264,在“/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_-build”上安装了“make-install”

我使用以下步骤从源代码x264进行编译,并使用相同的VS2015工具链将其添加到ffmpeg构建中:

  • 启动“VS2015 x64 Natice Tools命令提示符”
  • 在VS2015命令提示符下,运行“c:\msys64\msys2_shell.cmd-mingw64-use full path”
  • 从MSYS2外壳内部运行“cd/c/ThirdParty/opt”
  • git克隆
  • cd x264
  • CC=cl./configure--enable static--prefix=/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build--disable cli
  • 制造
  • 安装
  • cd../ffmpeg-4.2.2
  • PKG_CONFIG_PATH=/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib\ ./configure--prefix=./ffmpeg\u build--toolchain=msvc--arch=x86\u 64\ --目标os=win64——额外的cflags=-MT——额外的cxxflags=-MT\ --额外ldflags=-L/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib\ --enable-x86asm—enable asm—enable static—disable shared\ --禁用调试--启用gpl--启用avresample--启用libx264

  • 这些步骤工作正常,编译x264很好,但ffmpeg的配置输出为“错误:未找到libx264”

    我还尝试了使用这两行来代替上面的步骤6和10:

    • CC=cl./configure--enable static--prefix=/usr/local--disable cli
    • PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH./configure--prefix=/ffmpeg_build--toolchain=msvc--arch=x86_64--target os=win64--extra-cflags=-MT--extra-libx264.lib--extra-cxflags=-MT--enable-x86asm--enable-static--disable shared disable--disable-debug--enable gpl--enable avresample--启用-libx264
    这个版本将通过Configure,在那里我可以运行“make”,但是make在链接ffmpeg_g.exe时失败,出现了一系列未解析的X264函数,总共14个未解析函数。错误显示在底部,但首先:

    当我查看/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib时,我看到:

    $ ls -l ./ffmpeg_build/lib
    total 50988
    -rw-r--r-- 1 blake blake 27184250 May 11 16:29 libavcodec.a
    -rw-r--r-- 1 blake blake   231304 May 11 16:29 libavdevice.a
    -rw-r--r-- 1 blake blake  8574628 May 11 16:29 libavfilter.a
    -rw-r--r-- 1 blake blake  8081930 May 11 16:29 libavformat.a
    -rw-r--r-- 1 blake blake  1300118 May 11 16:29 libavutil.a
    -rw-r--r-- 1 blake blake    61844 May 11 16:29 libpostproc.a
    -rw-r--r-- 1 blake blake   348732 May 11 16:29 libswresample.a
    -rw-r--r-- 1 blake blake  1316008 May 11 16:29 libswscale.a
    -rw-r--r-- 1 blake blake  5086976 May 28 18:08 libx264.lib
    drwxr-xr-x 1 blake blake        0 May 28 18:08 pkgconfig
    
    同样,对于/c/ThirdParty/opt/ffmpeg-4.2.2/ffmpeg_build/lib/pkgconfig:

    $ ls -l ./ffmpeg_build/lib/pkgconfig/
    total 9
    -rw-r--r-- 1 blake blake 353 May 11 16:29 libavcodec.pc
    -rw-r--r-- 1 blake blake 554 May 11 16:29 libavdevice.pc
    -rw-r--r-- 1 blake blake 449 May 11 16:29 libavfilter.pc
    -rw-r--r-- 1 blake blake 393 May 11 16:29 libavformat.pc
    -rw-r--r-- 1 blake blake 306 May 11 16:29 libavutil.pc
    -rw-r--r-- 1 blake blake 317 May 11 16:29 libpostproc.pc
    -rw-r--r-- 1 blake blake 322 May 11 16:29 libswresample.pc
    -rw-r--r-- 1 blake blake 315 May 11 16:29 libswscale.pc
    -rw-r--r-- 1 blake blake 300 May 28 18:08 x264.pc
    
    在/usr/local/lib中,我看到libx264.lib和pkgconfig目录

    我最近的尝试产生的错误如下所示:

    LD      ffmpeg_g.exe
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_default referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_parse referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_default_preset referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_apply_fastfirstpass referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_param_apply_profile referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_picture_init referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_open_160 referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_reconfig referenced in function reconfig_encoder
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_headers referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_encode referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_close referenced in function X264_close
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_delayed_frames referenced in function X264_frame
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_encoder_maximum_delayed_frames referenced in function X264_init
    libavcodec.a(libx264.o) : error LNK2019: unresolved external symbol __imp_x264_levels referenced in function X264_init
    ffmpeg_g.exe : fatal error LNK1120: 14 unresolved externals
    make: *** [Makefile:111: ffmpeg_g.exe] Error 96
    

    ffmpeg的Configure的--extra-ldflags或--extra-libs选项可能有问题,但在尝试了变体和谷歌搜索之后,我来问你。你知道ffmpeg配置行有什么问题吗?上文第10步

    在libavcodec\libx264.c中注释或删除以下行:

    #if defined(_MSC_VER)
    #define X264_API_IMPORTS 1
    #endif
    
    这可能有助于解决
    未解析的外部符号
    错误。
    对于原始项目10的错误,您为指向lib dir而不是pkgconfig dir的PKG_CONFIG_PATH设置了错误的值。

    在libavcodec\libx264.c中注释或删除这行:

    #if defined(_MSC_VER)
    #define X264_API_IMPORTS 1
    #endif
    
    这可能有助于解决
    未解析的外部符号
    错误。 对于原始项目10的错误,您为指向lib dir而不是pkgconfig dir的PKG_CONFIG_PATH设置了错误的值