应用场景:SIP终端拨入后,FS将该SIP终端的视频流转发为RTSP 流,提供NVR进行录制;
问题1、如何在Freeswitch配置录制?
<action application=“record” data="xxx.wav"> ->同步阻塞方式 <action application="export" data="nolocal:execute_on_answer=record_session xxx.wav"/> nolocal表示非本端执行
网上的资料很多,最开始的疑问是:
1 使用record录制和record_session录制有什么区别?
record是同步的,record_session是异步的;
最直观的感受是,record的action执行完了之后,如果拨号计划后面还有其他的action,则不会被执行;
record_session则是起了一个线程去执行record,不会影响拨号计划后面的其他action的执行;
2 record,record_session配置录对端的时候,为什么配置完了总是失败?
失败是因为下面的方法判断失败:
一是必须配置为非代理(CF_PROXY_MODE)、非透传模式;
二是如果是a-leg录制,必须先answer,否则channel状态不是ready,如果录制b-leg,则可以使用execute_on_answer;
SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t check_ready, switch_bool_t check_media) { int ret = 0; switch_assert(channel != NULL); switch_channel_check_signal(channel, SWITCH_TRUE); if (check_media) { ret = ((switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_core_session_get_read_codec(channel->session) && switch_core_session_get_write_codec(channel->session)); if (!ret) return ret; } if (!check_ready) return ret; ret = 0; if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET && !switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_NOT_READY) && !switch_channel_state_change_pending(channel)) { ret++; } return ret; }
问题2、可不可以在Freeswitch做录制?
建议是方案可以,但不建议用Freeswitch做录制;
原因是Freeswitch擅长做媒体交换,录制会拖累软交换的性能,建议是Freeswitch转一路流出去,给专门做录制和点播的服务;
所以,我的思路是录制通过freeswitch转一路流到rtsp服务器来完成,rtsp服务器选用ZLMediaKit;
Freeswitch的配置:
<action application=\"set\" data=\"execute_on_answer=record_session rtsp://192.168.16.83/live/" . $this->account_id . "_". $destination_number." \"/>
Freeswitch录制时的函数栈和转流到rtsp服务器的日志:
#0 av_file_open (handle=0x7f955c0831a0, path=0x7f95780942b8 "192.168.16.83/live/4444_4002") at avformat.c:1595 #1 0x00007f958b4b622b in switch_core_perform_file_open (file=file@entry=0x7f958b805728 "src/switch_ivr_async.c", func=func@entry=0x7f958b806b40 <__func__.30857> "switch_ivr_record_session_event", line=line@entry=2819, fh=fh@entry=0x7f955c0831a0, file_path=0x7f95780942b8 "192.168.16.83/live/4444_4002", file_path@entry=0x7f955c083178 "rtsp://192.168.16.83/live/4444_4002", channels=channels@entry=2, rate=8000, flags=524298, pool=0x0) at src/switch_core_file.c:356 #2 0x00007f958b5682b0 in switch_ivr_record_session_event (session=session@entry=0x1680628, file=file@entry=0x7f955c083178 "rtsp://192.168.16.83/live/4444_4002", limit=limit@entry=0, fh=0x7f955c0831a0, fh@entry=0x0, vars=0x0) at src/switch_ivr_async.c:2819 #3 0x00007f956d4efea4 in record_session_function (session=0x1680628, data=<optimized out>) at mod_dptools.c:3348 #4 0x00007f958b4c9b5f in switch_core_session_exec (session=0x1680628, application_interface=application_interface@entry=0x12ee208, arg=arg@entry=0x7f955c0830f7 "rtsp://192.168.16.83/live/4444_4002 ") at src/switch_core_session.c:2891 #5 0x00007f958b4ca1ef in switch_core_session_execute_application_get_flags (session=<optimized out>, app=0x7f955c0830e8 "record_session", arg=0x7f955c0830f7 "rtsp://192.168.16.83/live/4444_4002 ", flags=flags@entry=0x0) at src/switch_core_session.c:2756 #6 0x00007f958b49a684 in do_execute_on (variable=<optimized out>, channel=<optimized out>) at src/switch_channel.c:3730 #7 0x00007f958b49f03f in switch_channel_execute_on (channel=channel@entry=0x149b000, variable_prefix=variable_prefix@entry=0x7f958b7e3f67 "execute_on_answer") at src/switch_channel.c:3757 #8 0x00007f958b4a5b05 in switch_channel_perform_mark_answered (line=3748, func=0x7f958b805620 <__func__.21860> "switch_ivr_originate", file=0x7f958b804345 "src/switch_ivr_originate.c", channel=0x149b000) at src/switch_channel.c:3851 #9 switch_channel_perform_mark_answered (channel=0x149b000, file=0x7f958b804345 "src/switch_ivr_originate.c", func=0x7f958b805620 <__func__.21860> "switch_ivr_originate", line=3748) at src/switch_channel.c:3768 #10 0x00007f958b4a5d90 in switch_channel_perform_answer (channel=channel@entry=0x149b000, file=file@entry=0x7f958b804345 "src/switch_ivr_originate.c", func=func@entry=0x7f958b805620 <__func__.21860> "switch_ivr_originate", line=line@entry=3748) at src/switch_channel.c:3904 #11 0x00007f958b55d65c in switch_ivr_originate (session=session@entry=0x1680628, bleg=bleg@entry=0x7f956ddfc1d0, cause=cause@entry=0x7f956ddfbd84, bridgeto=<optimized out>
2022-04-28 15:58:05.440843 [DEBUG] sofia.c:7289 Channel sofia/internal/4444@192.168.16.83 entering state [completed][200] nua.c:366 nua_handle_magic() nua: nua_handle_magic: entering 2022-04-28 15:58:05.440843 [NOTICE] switch_ivr_originate.c:3748 Channel [sofia/internal/4444@192.168.16.83] has been answered EXECUTE [depth=0] sofia/internal/4444@192.168.16.83 record_session(rtsp://192.168.16.83/live/4444_4002 ) 2022-04-28 15:58:05.440843 [DEBUG] avformat.c:1766 sample rate: 8000, channels: 2 2022-04-28 15:58:05.440843 [DEBUG] avformat.c:1914 use video codec: [27] h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10) 2022-04-28 15:58:05.440843 [NOTICE] avformat.c:723 sample_rate: 44100 nb_samples: 1024 2022-04-28 15:58:05.440843 [NOTICE] avformat.c:726 sample_fmt 8 != AV_SAMPLE_FMT_S16, start resampler Output #0, rtsp, to 'rtsp://192.168.16.83/live/4444_4002': Stream #0:0: Unknown: none (aac) 2022-04-28 15:58:05.440843 [INFO] avformat.c:1972 Opening File [rtsp://192.168.16.83/live/4444_4002] 44100hz 2022-04-28 15:58:05.440843 [DEBUG] switch_core_file.c:391 File 192.168.16.83/live/4444_4002 sample rate 44100 doesn't match requested rate 8000 tport.c:2753 tport_wakeup_pri() tport_wakeup_pri(0x7ff19800d3c0): events IN 2022-04-28 15:58:10.460907 [DEBUG] avformat.c:615 colorspace = 1 using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX profile Constrained Baseline, level 4.1, 4:2:0, 8-bit 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0x1:0x111 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=30 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.00 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 2022-04-28 15:58:10.460907 [INFO] avformat.c:2776 use video codec implementation Video: h264 (libx264), yuv420p(pc, bt709/unknown/unknown), 352x288, q=-1--1 Starting connection attempt to 192.168.16.83 port 554 Successfully connected to 192.168.16.83 port 554 SDP: v=0 o=- 0 0 IN IP4 127.0.0.1 s=Recording 400244442022-04-28 15:58 c=IN IP4 192.168.16.83 t=0 0 a=tool:libavformat 58.20.100 m=audio 0 RTP/AVP 96 b=AS:131 a=rtpmap:96 MPEG4-GENERIC/44100/2 a=fmtp:96 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=121056E500 a=control:streamid=0 m=video 0 RTP/AVP 97 a=rtpmap:97 H264/90000 a=fmtp:97 packetization-mode=1; sprop-parameter-sets=Z0LAKdoFglpuBAQCgAAAAwCAAV+QB4wZUA==,aM4PyA==; profile-level-id=42C029 a=control:streamid=1 2022-04-28 15:58:10.481031 [NOTICE] avformat.c:815 video thread start tport.c:2753 tport_wakeup_pri() tport_wakeup_pri(0x7ff19800d3c0): events IN
最后来看看需求:如何录制?由于Freeswitch转的一路流只有一条腿,并不能同时转两条腿的媒体流,所以呢,录制功能只能录单边,这里需要调整下需求:
语音,混合录制 ->aac
视频,单边录制 ->h264?
最后合成一个mp4文件,只录一端,一端的视频,加上两端的音频混合一起录制;
下一步,修改mod_av,实现freeswitch推流给rtsp服务器,由rtsp服务器实现录制和点播功能!
----更新:20221008---
会议如何录制到rtsp,只需要简单配置录制地址到rtsp服务器就可以!
/home/OV500/LB/freeswitch/etc/freeswitch/autoload_configs
[root@abc-VirtualBox autoload_configs]# vim conference.conf.xml
<!-- Profiles are collections of settings you can reference by name. --> <profiles> <!--If no profile is specified it will default to "default"--> <profile name="default"> <!-- <param name="auto-record" value="$${recordings_dir}/${conference_name}_${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/> --> <param name="auto-record" value="rtsp://192.168.16.83/live/${conference_name}" />
-------------------广告线---------------
项目、合作,欢迎勾搭,邮箱:promall@qq.com
本文为呱牛笔记原创文章,转载无需和我联系,但请注明来自呱牛笔记 ,it3q.com
:您好大佬,请教个问题,我在centos7.9上部署了一个freeswitch10.2版本,会议中推了rtsp流出去,但是vlc播放全部是噪音,说话的声音一点听不到。但是我windows版本是正常的,请教一下,这个大概是什么问题,麻烦了
2023-03-27 19:01:37 回复