操作系统 :CentOS 7.6_x64、Windows 10_x64
FreeSWITCH版本 :1.10.9
Python版本:3.9.2
一、启用h264相关模块
这里以 mod_openh264 为例进行演示。
1、安装open_h264库
获取 open_h264 源码:
git clone https://github.com/cisco/openh264.git
若下载过慢,可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 20231006 获取。
安装编译工具:
yum install nasm
编译及安装:
make ENABLE64BIT=Yes
make install
2、安装mod_openh264模块
codecs/mod_openh264目录已存在,启用该模块即可。
文件: freeswitch-1.10.9.-release/modules.conf
1)注释掉 codecs/mod_h26x 选项;
2)添加 codecs/mod_openh264 选项;
echo "codecs/mod_openh264" >> modules.conf

3)编译及安装
./rebootstrap.sh
CFLAGS="-O3 -fPIC" ./configure
make -j
make install
查看模块是否安装成功:
ls /usr/local/freeswitch/mod/mod_openh264.* -lh

3、启用mod_openh264模块
文件:conf/autoload_configs/modules.conf.xml
不启用 mod_h26x 、mod_av 模块,启用 mod_openh264 模块;

show codecs 可以看到已启用h264编码。

二、开启视频呼叫
1、配置编码
1 ) 添加编解码支持
文件: conf/vars.xml
修改内容:
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=OPUS,G722,PCMU,PCMA,H264,VP8,G729"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=OPUS,G722,PCMU,PCMA,H264,VP8,G729"/>
2 ) 配置profile
文件:
sip_profiles/internal.xml
sip_profiles/external.xml
修改或添加内容:
<param name="inbound-proxy-media" value="false"/>
<param name="inbound-late-negotiation" value="false"/>
<param name="disable-transcoding" value="false"/>
此外,proxy-media 不能开启,否则会转码失败。
2、测试视频呼叫
普通呼叫:
originate user/1000 &echo
会议室呼叫:
originate user/1000 &conference(test@default)
选择视频应答即可:

演示视频可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 2023100601 获取。
3、转码测试
这里以sipp作为h264视频终端,软电话作为vp8视频终端进行转码测试。
1)sipp配置
这里先播放音频再播放视频。
<!-- Play a pre-recorded PCAP file (RTP stream) -->
<nop>
<action>
<exec play_pcap_audio="g711a.pcap"/>
</action>
</nop>
<pause milliseconds="10000"/>
<nop>
<action>
<exec play_pcap_video="h264.pcap"/>
</action>
</nop>
INVITE请求如下:

完整配置可从文章末尾提供的渠道获取(audioVideoTest1.tar.gz)。
2)软电话配置
配置软电话只支持vp8视频编码。

3)编写拨号方案:
文件: dialplan/public.xml
添加内容:
<extension name="test1112">
<condition field="destination_number" expression="^(7654321)$">
<action application="bridge" data="user/1000"/>
</condition>
</extension>
4)转码测试
重启freeswitch,然后用sipp进行呼叫测试。

演示视频可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 2023100602 获取。
三、从pcap中提取h264视频文件
1、使用wireshark提取h264视频
wireshark版本: 3.6.12
需要安装lua插件。
1)获取lua插件:
github地址: https://github.com/volvet/h264extractor
将 rtp_h264_extractor.lua 复制到wireshark安装目录。
若下载过慢,可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 20231006 获取。
2)添加lua插件
文件:init.lua

在文件末尾添加如下内容:
dofile(DATA_DIR.."rtp_h264_extractor.lua")
3)启动wireshark进行视频提取
工具 -> Extract h264 stream from RTP

提取窗口会显示视频文件路径:

播放视频:
ffplay C:\Users\Mike\Documents\video_20231006-102002.264

2、使用python脚本提取h264视频
需要注意,这里除了解析rtp头,还需要解析h264头。
python解析rtp可参考这篇文章:
https://www.cnblogs.com/MikeZhang/p/pythonUseLibpcap20221029.html
解析h264头请查阅相关rfc文档:
https://www.rfc-editor.org/rfc/rfc3984

示例代码如下:

完整代码可从文末提供的渠道获取。
wireshark和python提取h264的运行效果视频可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 2023100603 获取。
四、资源下载
本文涉及资源及示例代码可从如下渠道获取:
关注微信公众号(聊聊博文,文末可扫码)后回复 20231006 获取。
