注:本文假设webrtc源码已经下载完毕
1.编译
进入到webrtc/src目录下,重新编译webrtc源代码,让代码支持h264编解码
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_VERSION=2019
set GYP_MSVS_OVERRIDE_PATH="/C/Program Files (x86)/Microsoft Visual Studio/2019/Community"
set GYP_GENERATORS=msvs-ninja,ninja
set WINDOWSSDKDIR="/C/Program Files (x86)/Windows Kits/10"
gn gen out/h264debug --args="is_debug=true target_cpu=\"x64\" use_openh264=true proprietary_codecs=true ffmpeg_branding=\"Chrome\"" --ide=vs2019
等待构建完成,即可demo即可支持open h264编解码。
2.媒体协商优先使用h264编码
打开webrtc/src/media/engine/internal_encoder_factory.cc,找到InternalEncoderFactory::SupportedFormats()函数
std::vector<SdpVideoFormat> InternalEncoderFactory::SupportedFormats() {
std::vector<SdpVideoFormat> supported_codecs;
supported_codecs.push_back(SdpVideoFormat(cricket::kVp8CodecName));
for (const webrtc::SdpVideoFormat& format : webrtc::SupportedVP9Codecs())
supported_codecs.push_back(format);
for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs())
supported_codecs.push_back(format);
if (kIsLibaomAv1EncoderSupported)
supported_codecs.push_back(SdpVideoFormat(cricket::kAv1CodecName));
return supported_codecs;
}
改成:
std::vector<SdpVideoFormat> InternalEncoderFactory::SupportedFormats() {
std::vector<SdpVideoFormat> supported_codecs;
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);
if (kIsLibaomAv1EncoderSupported)
supported_codecs.push_back(SdpVideoFormat(cricket::kAv1CodecName));
return supported_codecs;
}
然后在编译运行,即可在协商时优先使用h264编解码器编解码。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。