windows下采用PNacl编译ffmpeg4.1

接上篇,linux下采用PNacl编译ffmpeg4.1,本篇介绍在windows下面的实现过程。

一、原材料准备

1、Windows7 X64

2、nacl_sdk windows版(如何获取nacl_sdk不在此讨论)

3、Python2.7(编译插件的时候需要)

4、ffmpeg4.1

二、安装nacl_sdk

这里重要说明一下设置环境变量:

NACL_SDK_ROOT=D:\nacl_sdk\pepper_49
CHROME_PATH=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

三、准备linux模拟器

1、下载安装msys2
2、安装模拟环境下的工具
 pacman -S make
3、设置编译环境
 编辑C:\msys64\msys2_shell.cmd将
 rem set MSYS2_PATH_TYPE=inherit
 修改为
 set MSYS2_PATH_TYPE=inherit
4、双击msys2_shell.cmd启动模拟环境

四、编译ffmpeg

./configure \
    --target-os=linux \

    --arch=pnacl \

    --cross-prefix=pnacl- \
    --cc=pnacl-clang \
    --ld=pnacl-clang++ \
    --enable-static
  make
  make install

编译完成后即可模拟环境的路径下面有已经安装的头文件和静态库文件

测试路径在D:\msys64\usr\local

五、在编译过程中可能遇到的问题

1、libavformat/codec2.c:22:10: fatal error: 'memory.h' file not found
  在ffbuild/config.mak文件里面找到CFLAGS,增中头文件依赖-I"D:\nacl_sdk\pepper_49\include\pnacl"

修改后的样子为:

CFLAGS=   -std=c11 -fomit-frame-pointer -pthread -g -Wdeclaration-after-statement -Wall -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -Wno-unused-const-variable -O3 -fno-math-errno -fno-signed-zeros -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -I"D:\nacl_sdk\pepper_49\include\pnacl"
 2、fftools/cmdutils.c:1072:19: error: variable has incomplete type 'struct rlimit'
  找到opt_timelimit函数在
  #if HAVE_SETRLIMIT后面增加 && !defined(__pnacl__)
  修改后的样子是:
  #if HAVE_SETRLIMIT && !defined(__pnacl__)
 3、fftools/ffmpeg.c:4800:5: error: implicit declaration of function 'getrusage' is invalid in C99
  找到get_benchmark_time_stamps函数在#if HAVE_GETRUSAGE后面增加&& !defined(__pnacl__)
  修改后的样子:
  #if HAVE_GETRUSAGE && !defined(__pnacl__)

4、terminate called after throwing an instance of 'std::bad_alloc'

原因是windows的nacl_sdk的工具是32位的,其他的环境的是64位的,详见:https://bugs.chromium.org/p/chromium/issues/detail?id=584516对此问题的说明:

We've noted this doesn't happen in the GN build for platforms other than Windows.  Crucially, the PNaCl toolchain is built for 64-bit hosts on all other platforms, but for 32-bit Windows.

32位的程序无法使用大内存解决办法:

把下述两个文件通过VS工具修改可以使用大内存

D:\VS2012\VC\bin\amd64>editbin.exe /LARGEADDRESSAWARE "D:\nacl_sdk\pepper_49\toolchain\win_pnacl\bin\le32-nacl-ld.gold.exe"
D:\VS2012\VC\bin\amd64>editbin.exe /LARGEADDRESSAWARE "D:\nacl_sdk\pepper_49\toolchain\win_pnacl\bin\opt.exe"

六、需要说明的问题

1、通过PNacl编译产生的“可执行程序”ffmpeg是不能运行的,它既不是正常的windows的可执行程序,也不是正常的linux的可执行程序

2、在windows下产生的静态库和在linux下面产生的静态库是不能混用的,如果采用VS进行插件开发只能用windows下编译产生的静态库,在linux下编译插件只能采用linux下编译产生的静态库,但编译产生的pexe是可能跨平台使用,chrome安装到哪里,哪里就可以运行pexe

3、本文描述的编译结果是生成静态库,而不是在windows下面编译生成的,请注意。

七、致谢

1、编译环境设置启发

https://www.cnblogs.com/liumeng-blog/p/7511975.html

猜你喜欢

转载自www.cnblogs.com/hnzkliuwei/p/10534948.html