win10+vs2019编译webrtc-m79并支持H264编解码

源码下载

请自行使用科学上网方式获取
或者使用声网的镜像 https://webrtc.org.cn/mirror/

准备工作

  • Depot-tools
  • python2.7
  • 安装VS2019

安装配置depot-tools

下载之后需要将路径添加到系统环境变量中,最好放在最上层

安装配置vs2019

WebRTC的编译需要2017及以上版本,因为会用到C++11、C++14的很多新特性。

安装VS2019时选择自定义安装,必须勾选如下几项:
Desktop development with C++组件中 10.0.17134或以上的Win10 SDK(如果没看到该版本,去左侧可选组件那里勾选),后面还要安装调试工具
Desktop development with C++组件中MFC以及ATL这两项

安装完VS2019后,必须安装SDK调试工具。
打开控制面板->程序与功能,找到刚才安装的最新Windows Software Development Kit,鼠标右键->change。
勾选Debugging Tools For Windows,然后点击change。

生成vs工程文件

cd src
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
gn gen out/x86_debug
 --ide=vs2019 
--args="is_debug=true target_cpu=\"x86\" is_clang=false is_component_ffmpeg=true ffmpeg_branding=\"Chrome\" proprietary_codecs=true  rtc_use_h264=true rtc_include_tests=false gtest_enable_absl_printers=false libyuv_include_tests=false  is_component_build=false rtc_enable_protobuf=true use_custom_libcxx=false use_custom_libcxx_for_host=false"   
--winsdk=10.0.18362.0
参数 参数说明
rtti 默认webrtc不开启rtti,如果在代码中使用typeid将引起链接失败
is_debug 是否是Debug版,默认true,false:表示编译Release版。
is_clang 如果用vs编译的化,is_clang要置为false,否则编译不过去
target_cpu cpu类型,Windows下可以取x86、x64
proprietary_codecs 是否使用版权编码,也就是H264,这里取true
rtc_use_h264 是否使用H264,这里取true,注意Windows平台编码使用OpenH264,解码使用ffmpeg
ffmpeg_branding ffmpeg的分支名,这里采用Chrome的分支。
–ide 是用的什么编译器
–winsdk 指定win sdk的版本
use_custom_libcxx 默认使用自带的libcxx作为默认的c++标准库,链接时将与vc++的libcxx冲突。使用use_custom_libcxx = false去除对内置libcxx引用

ninja编译

ninja -C out/x86_debug

注意

webrtc默认编译器是Clang,所以使用VS进行编译时,需要在VS中增加Clang工具
若不想在VS下使用Clang,可以在webrtc编译命令行中增加is_clang=false use_lld=false。

但是使用is_clang=false use_lld=false命令参数,webrtc不能使用H264功能,因为H264的解码调用的是ffmpeg的264解码器,编译ffmpeg必须使用clang编译器。谷歌也在尝试ffmpeg使用Clang编译,其他程序使用CL编译,但是现在这个问题单还是Open状态,目前还没有解决。

https://bugs.chromium.org/p/webrtc/issues/detail?id=9213

要支持H264 必须开启如下几个参数:

rtc_use_h264=true
use_openh264=true
ffmpeg_branding="Chrome"
proprietary_codecs=true

常见错误及解决

No module named ‘win32api’
pip install pypiwin32
bugs.webrtc.org/9213#c13
将 modules\video_coding\codecs\h264\目录下的
h264_decoder_impl.h
h264_encoder_impl.h
h264_color_space.h
几个文件中的#error "See: bugs.webrtc.org/9213#c13."  注释掉。
error C2059: 语法错误:“字符串”

原因是PCM_VIDC这个标志未定义,通过宏定义无法正确生成,
注释掉\third_party\ffmpeg\libavcodec\pcm.c的最后一行

猜你喜欢

转载自blog.csdn.net/machh/article/details/112790036