下载完webrtc代码之后
1、打开src目录下的.gn文件
2、在default_args里面添加
rtc_use_h264 = true
ffmpeg_branding = "Chrome"
如下:
default_args = {
# Webrtc does not support component builds because we are not using the
# template "component" but we rely directly on "rtc_static_library" and
# "rtc_shared_library". This means that we cannot use the chromium default
# value for this argument.
# This also means that the user can override this value using --args or
# the args.gn file but this setting will be ignored because we don't support
# component builds.
is_component_build = false
rtc_use_h264 = true
ffmpeg_branding = "Chrome"
}
3、重新运行gn
例如:
gn gen out/Default --ide="vs2015"
让WebRTC支持H264编解码
到这里还没结束, 因为网页使用 WebRTC 发送 SDP ,进行协商时,默认的 codec 顺序是:
-
VP8
-
VP9
-
H264
所以需要修改源码,internal_encoder_factory.cc,GetSupportedFormats函数,将H264编码器移到最前面,代码如下:
std::vector<SdpVideoFormat> InternalEncoderFactory::GetSupportedFormats()
const {
std::vector<SdpVideoFormat> supported_codecs;
//chb 20191106
for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs())
supported_codecs.push_back(format);
supported_codecs.push_back(SdpVideoFormat(cricket::kVp8CodecName));
for (const webrtc::SdpVideoFormat& format : webrtc::SupportedVP9Codecs())
supported_codecs.push_back(format);
return supported_codecs;
}