WEBRTC 支持H264编解码

来源:互联网 发布:linux互斥锁 实例 编辑:程序博客网 时间:2024/06/11 23:55

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上查看代码片派生到我的代码片
  1.   
[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 <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 看码流或写入文件

[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上查看代码片派生到我的代码片
  1. </pre><pre class="cpp" name="code" snippet_file_name="blog_20160630_8_8873287" code_snippet_id="1736351">  


0 0