WEBRTC 支持H264编解码

古城微笑少年丶 2022-07-14 11:17 744阅读 0赞

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

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

  1. if (CodecIsInternallySupported(kH264CodecName)) {
  2. VideoCodec codec = MakeVideoCodecWithDefaultFeedbackParams(
  3. kDefaultH264PlType, kH264CodecName);
  4. // TODO(hta): Move all parameter generation for SDP into the codec
  5. // implementation, for all codecs and parameters.
  6. // TODO(hta): Move selection of profile-level-id to H.264 codec
  7. // implementation.
  8. // TODO(hta): Set FMTP parameters for all codecs of type H264.
  9. codec.SetParam(kH264FmtpProfileLevelId,
  10. kH264ProfileLevelConstrainedBaseline);
  11. codec.SetParam(kH264FmtpLevelAsymmetryAllowed, “1”);
  12. codec.SetParam(kH264FmtpPacketizationMode, “1”);
  13. codecs.push_back(codec);
  14. codecs.push_back(
  15. VideoCodec::CreateRtxCodec(kDefaultRtxH264PlType, kDefaultH264PlType));
  16. }

二 让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

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

  1. [‘(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”)’, {

再找到

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

  1. ‘libavcodec/x86/h264_qpel.c’,
  2. ‘libavcodec/x86/h264chroma_init.c’,
  3. ‘libavcodec/x86/h264dsp_init.c’,

对应得

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

  1. [‘(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 (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”)’, {

在LINUX X64 中去掉chrome

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

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

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

  1. int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image,
  2. const CodecSpecificInfo* codec_specific_info,
  3. const RTPFragmentationHeader* fragmentation)

[cpp] view plain copy

在CODE上查看代码片 派生到我的代码片

Center

发表评论

表情:
评论列表 (有 0 条评论,744人围观)

还没有评论,来说两句吧...

相关阅读

    相关 H264 解码协议详解

    1.、什么是 H264? H264 是 MPEG-4 标准所定义的最新编码格式,同时也是技术含量最高、代表最新技术水平的视频编码格式之一,标准写法应该是H.264 H26