WEBRTC 支持H264编解码



WEBRTC视频编解码支持H264 VP8 VP9 但是默认是VP8 ,根据SDP描述协商

WEBRTC H264编码采用OPENH264 解码采用FFMPEG

一 让WEBRTC支持H264编码

1. 修改配置支持H264编码

 webrtc/build/common.gypi  rtc_use_h264=1(只要有都设为1),这样OPENH264就会生成

 然后需要重新编译 python webrtc/build/gyp_webrtc ninja -C out/Debug

2 修改SDP生成次序

webrtcvideoengine2.cc DefaultVideoCodecList 可以修改SDP中 视频编码的次序把

放在最前面,让SDP支持H264

  if (CodecIsInternallySupported(kH264CodecName)) {
    VideoCodec codec = MakeVideoCodecWithDefaultFeedbackParams(
        kDefaultH264PlType, kH264CodecName);
    // TODO(hta): Move all parameter generation for SDP into the codec
    // implementation, for all codecs and parameters.
    // TODO(hta): Move selection of profile-level-id to H.264 codec
    // implementation.
    // TODO(hta): Set FMTP parameters for all codecs of type H264.
    codec.SetParam(kH264FmtpProfileLevelId,
                   kH264ProfileLevelConstrainedBaseline);
    codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1");
    codec.SetParam(kH264FmtpPacketizationMode, "1");
    codecs.push_back(codec);
    codecs.push_back(
        VideoCodec::CreateRtxCodec(kDefaultRtxH264PlType, kDefaultH264PlType));
  }

二 让WEBRTC支持H264解码
thirdpart 下有ffmpeg源码,不用下载ffmpeg编译
1.修改gyp配置 支持ffmpeg编译<webrtc/build/common.gypi rtc_initialize_ffmpeg=1
2.默认ffmpeg 不会把h264.c等文件编译进ffmpeg 就会导致 H264DecoderImpl::InitDecode 调用 avcodec_find_decoder 失败,
找不到解码器需要修改 ffmpeg_generated.gypi 默认只支持chrome chromeOS中编译H264,找到h264.c
然后 在LINUX X64 中去掉chrome


 ['(OS == "linux" and target_arch == "arm" and arm_neon == 1 and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "arm" and arm_neon == 1 and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "arm" and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "arm" and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "arm64" and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "arm64" and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "ia32" and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "ia32" and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "mipsel" and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "mipsel" and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "x64" and ffmpeg_branding == "Chrome") or(OS == "linux" and target_arch == "x64")or (OS == "mac" and target_arch == "x64" and ffmpeg_branding == "Chrome") or (OS == "win" and target_arch == "ia32" and ffmpeg_branding == "Chrome") or (OS == "win" and target_arch == "x64" and ffmpeg_branding == "Chrome")', {



再找到

          'libavcodec/x86/h264_qpel.c',
          'libavcodec/x86/h264chroma_init.c',
          'libavcodec/x86/h264dsp_init.c',

对应得

['(OS == "linux" and target_arch == "ia32" and ffmpeg_branding == "Chrome") or (OS == "linux" and target_arch == "ia32" and ffmpeg_branding == "ChromeOS") or (OS == "linux" and target_arch == "x64" and ffmpeg_branding == "Chrome") or <span style="color:#ff0000;">(OS == "linux" and target_arch == "x64")</span> or (OS == "mac" and target_arch == "x64" and ffmpeg_branding == "Chrome") or (OS == "win" and target_arch == "ia32" and ffmpeg_branding == "Chrome") or (OS == "win" and target_arch == "x64" and ffmpeg_branding == "Chrome")', {

在LINUX X64 中去掉chrome

3.重新生成ninja python webrtc/build/gyp_webrtc ninja -C out/Debug


可在video_send_stream.cc 函数,中调试 encoded_image._buffer 看码流或写入文件

int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image,
                                 const CodecSpecificInfo* codec_specific_info,
                                 const RTPFragmentationHeader* fragmentation) 
</pre><pre class="cpp" name="code" snippet_file_name="blog_20160630_8_8873287" code_snippet_id="1736351">


  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值