注:本文假設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編解碼器編解碼。