From fb3603b4335c20b438c079db9d05a64b607a78b0 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 28 Feb 2021 20:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=80=E4=BA=9B=E4=B8=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=9A=84=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/H264.cpp | 10 ++++++++-- src/Extension/H264Rtmp.cpp | 4 ++++ src/Extension/H265.cpp | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Extension/H264.cpp b/src/Extension/H264.cpp index 7a7acd33..ec220ea7 100644 --- a/src/Extension/H264.cpp +++ b/src/Extension/H264.cpp @@ -15,7 +15,10 @@ using namespace toolkit; namespace mediakit{ -static bool getAVCInfo(const char * sps,size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){ +static bool getAVCInfo(const char *sps, size_t sps_len,int &iVideoWidth, int &iVideoHeight, float &iVideoFps){ + if (sps_len < 4) { + return false; + } T_GetBitContext tGetBitBuf; T_SPS tH264SpsInfo; memset(&tGetBitBuf,0,sizeof(tGetBitBuf)); @@ -157,7 +160,10 @@ void H264Track::inputFrame(const Frame::Ptr &frame) { } void H264Track::onReady(){ - getAVCInfo(_sps,_width,_height,_fps); + if (!getAVCInfo(_sps, _width, _height, _fps)) { + _sps.clear(); + _pps.clear(); + } } Track::Ptr H264Track::clone() { diff --git a/src/Extension/H264Rtmp.cpp b/src/Extension/H264Rtmp.cpp index 3cd4d04f..ca58472a 100644 --- a/src/Extension/H264Rtmp.cpp +++ b/src/Extension/H264Rtmp.cpp @@ -221,6 +221,10 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) { } void H264RtmpEncoder::makeVideoConfigPkt() { + if (_sps.size() < 4) { + WarnL << "sps长度不足4字节"; + return; + } int8_t flags = FLV_CODEC_H264; flags |= (FLV_KEY_FRAME << 4); bool is_config = true; diff --git a/src/Extension/H265.cpp b/src/Extension/H265.cpp index db670bc5..48132a1d 100644 --- a/src/Extension/H265.cpp +++ b/src/Extension/H265.cpp @@ -186,7 +186,11 @@ void H265Track::inputFrame_l(const Frame::Ptr &frame) { } void H265Track::onReady() { - getHEVCInfo(_vps, _sps, _width, _height, _fps); + if (!getHEVCInfo(_vps, _sps, _width, _height, _fps)) { + _vps.clear(); + _sps.clear(); + _pps.clear(); + } } Track::Ptr H265Track::clone() {