From a9b0ca9cddbcf5ee6a31c4377402a1802e3dd08b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 1 Aug 2020 20:56:34 +0800 Subject: [PATCH] =?UTF-8?q?hls=E6=94=AF=E6=8C=81opus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/media-server | 2 +- README.md | 6 ++-- README_en.md | 62 ++---------------------------------------- src/Record/TsMuxer.cpp | 5 ++++ src/Rtp/Decoder.cpp | 20 ++++++++++++++ 5 files changed, 31 insertions(+), 64 deletions(-) diff --git a/3rdpart/media-server b/3rdpart/media-server index 43facc34..94142587 160000 --- a/3rdpart/media-server +++ b/3rdpart/media-server @@ -1 +1 @@ -Subproject commit 43facc343afc2b5b70bbbc3c177f20dfa936f2bf +Subproject commit 94142587a615cfb588bbfc663bc05a1c4a82d1cb diff --git a/README.md b/README.md index 709bff45..ae021bbf 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ - 提供完整的[MediaServer](https://github.com/xia-chu/ZLMediaKit/tree/master/server)服务器,可以免开发直接部署为商用服务器。 - 提供完善的[restful api](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer%E6%94%AF%E6%8C%81%E7%9A%84HTTP-API)以及[web hook](https://github.com/xia-chu/ZLMediaKit/wiki/MediaServer%E6%94%AF%E6%8C%81%E7%9A%84HTTP-HOOK-API),支持丰富的业务逻辑。 - 打通了视频监控协议栈与直播协议栈,对RTSP/RTMP支持都很完善。 -- 全面支持H265/H264/AAC/G711。 +- 全面支持H265/H264/AAC/G711/OPUS。 ## 项目定位 @@ -55,7 +55,7 @@ - 支持HLS文件生成,自带HTTP文件服务器 - 通过cookie追踪技术,可以模拟HLS播放为长连接,可以实现HLS按需拉流、播放统计等业务 - 支持HLS播发器,支持拉流HLS转rtsp/rtmp/mp4 - - 支持H264/H265/AAC/G711编码 + - 支持H264/H265/AAC/G711/OPUS编码 - HTTP[S]与WebSocket - 服务器支持`目录索引生成`,`文件下载`,`表单提交请求` @@ -68,7 +68,7 @@ - GB28181与RTP推流 - 支持UDP/TCP国标RTP(PS或TS)推流,可以转换成RTSP/RTMP/HLS等协议 - - 支持H264/H265/AAC/G711编码 + - 支持H264/H265/AAC/G711/OPUS编码 - MP4点播与录制 - 支持录制为FLV/HLS/MP4 diff --git a/README_en.md b/README_en.md index 6eae5565..db0ba7a1 100644 --- a/README_en.md +++ b/README_en.md @@ -20,7 +20,7 @@ - RTSP[S] player and pusher. - RTP Transport : `rtp over udp` `rtp over tcp` `rtp over http` `rtp udp multicast` . - Basic/Digest/Url Authentication. - - H264/H265/AAC/G711 codec. + - H265/H264/AAC/G711/OPUS codec. - Recorded as mp4. - Vod of mp4. @@ -28,7 +28,7 @@ - RTMP[S] server,support player and pusher. - RTMP[S] player and pusher. - Support HTTP-FLV player. - - H264/H265/AAC/G711 codec. + - H265/H264/AAC/G711/OPUS codec. - Recorded as flv or mp4. - Vod of mp4. - support [RTMP-H265](https://github.com/ksvc/FFmpeg/wiki) @@ -56,62 +56,6 @@ - Support TS / PS streaming push through RTP,and it can be converted to RTSP / RTMP / HLS / FLV. - Support real-time online screenshot http api. - -- Protocol conversion: - -| protocol/codec | H264 | H265 | AAC | other | -| :------------------------------: | :--: | :--: | :--: | :---: | -| RTSP[S] --> RTMP/HTTP[S]-FLV/FLV | Y | Y | Y | N | -| RTMP --> RTSP[S] | Y | Y | Y | N | -| RTSP[S] --> HLS | Y | Y | Y | N | -| RTMP --> HLS | Y | Y | Y | N | -| RTSP[S] --> MP4 | Y | Y | Y | N | -| RTMP --> MP4 | Y | Y | Y | N | -| MP4 --> RTSP[S] | Y | Y | Y | N | -| MP4 --> RTMP | Y | Y | Y | N | -| HLS --> RTSP/RTMP/MP4 | Y | Y | Y | N | - -- Stream generation: - -| feature/codec | H264 | H265 | AAC | other | -| :-----------: | :--: | :--: | :--: | :---: | -| RTSP[S] push | Y | Y | Y | Y | -| RTSP proxy | Y | Y | Y | Y | -| RTMP push | Y | Y | Y | Y | -| RTMP proxy | Y | Y | Y | Y | - -- RTP transport: - -| feature/transport | tcp | udp | http | udp_multicast | -| :-----------------: | :--: | :--: | :--: | :-----------: | -| RTSP[S] Play Server | Y | Y | Y | Y | -| RTSP[S] Push Server | Y | Y | N | N | -| RTSP Player | Y | Y | N | Y | -| RTSP Pusher | Y | Y | N | N | - - -- Server supported: - -| Server | Y/N | -| :-----------------: | :--: | -| RTSP[S] Play Server | Y | -| RTSP[S] Push Server | Y | -| RTMP | Y | -| HTTP[S]/WebSocket[S] | Y | - -- Client supported: - -| Client | Y/N | -| :---------: | :--: | -| RTSP Player | Y | -| RTSP Pusher | Y | -| RTMP Player | Y | -| RTMP Pusher | Y | -| HTTP[S] | Y | -| WebSocket[S] | Y | -| HLS player | Y | - - ## System Requirements - Compiler support c++11,GCC4.8/Clang3.3/VC2015 or above. @@ -191,8 +135,6 @@ git submodule update --init ``` - - ### Build on Android Now you can open android sudio project in `Android` folder,this is a `aar library` and damo project. diff --git a/src/Record/TsMuxer.cpp b/src/Record/TsMuxer.cpp index 40bee618..e57fa8c6 100644 --- a/src/Record/TsMuxer.cpp +++ b/src/Record/TsMuxer.cpp @@ -73,6 +73,11 @@ void TsMuxer::addTrack(const Track::Ptr &track) { break; } + case CodecOpus: { + _codec_to_trackid[track->getCodecId()].track_id = mpeg_ts_add_stream(_context, PSI_STREAM_AUDIO_OPUS, nullptr, 0); + break; + } + default: WarnL << "mpeg-ts 不支持该编码格式,已忽略:" << track->getCodecName(); break; } diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index 3b86a64d..a4f77715 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -15,6 +15,7 @@ #include "Extension/H265.h" #include "Extension/AAC.h" #include "Extension/G711.h" +#include "Extension/Opus.h" #if defined(ENABLE_RTPPROXY) || defined(ENABLE_HLS) #include "mpeg-ts-proto.h" @@ -91,6 +92,7 @@ static const char *getCodecName(int codec_id) { SWITCH_CASE(PSI_STREAM_AUDIO_G722); SWITCH_CASE(PSI_STREAM_AUDIO_G723); SWITCH_CASE(PSI_STREAM_AUDIO_G729); + SWITCH_CASE(PSI_STREAM_AUDIO_OPUS); default : return "unknown codec"; } } @@ -198,6 +200,24 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d onFrame(std::make_shared(codec, (char *) data, bytes, dts)); break; } + + case PSI_STREAM_AUDIO_OPUS: { + if (!_codecid_audio) { + //获取到音频 + _codecid_audio = codecid; + InfoL << "got audio track: opus"; + auto track = std::make_shared(); + onTrack(track); + } + + if (codecid != _codecid_audio) { + WarnL << "audio track change to opus from codecid:" << getCodecName(_codecid_audio); + return; + } + onFrame(std::make_shared(CodecOpus, (char *) data, bytes, dts)); + break; + } + default: if(codecid != 0){ WarnL<< "unsupported codec type:" << getCodecName(codecid) << " " << (int)codecid;