diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index f56c06da07..670a43caae 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -638,11 +638,49 @@ srs_error_t SrsDvrPlan::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* f srs_error_t SrsDvrPlan::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format) { srs_error_t err = srs_success; + uint32_t sei_count = 0; if (!dvr_enabled) { return err; } - + + // count SEI type nalu + if (format->vcodec->id == SrsVideoCodecIdAVC) { + for (int i = 0; i < format->video->nb_samples; ++i) { + SrsSample* sample = &format->video->samples[i]; + SrsAvcNaluType avc_nalu_type; + + if ((err = SrsVideoFrame::parse_avc_nalu_type(sample, avc_nalu_type)) != srs_success) { + return srs_error_wrap(err, "parse avc nalu_type"); + } + + if (avc_nalu_type == SrsAvcNaluTypeSEI) { + sei_count++; + } + } + } else if (format->vcodec->id == SrsVideoCodecIdHEVC) { +#ifdef SRS_H265 + for (int i = 0; i < format->video->nb_samples; ++i) { + SrsSample* sample = &format->video->samples[i]; + SrsHevcNaluType hevc_nalu_type = SrsHevcNaluTypeParse(sample->bytes[0]); + if (hevc_nalu_type == SrsHevcNaluType_SEI || hevc_nalu_type == SrsHevcNaluType_SEI_SUFFIX) { + sei_count++; + } + } +#endif + } + + // If all the nalu are SEI type, then skip this frame. + if (sei_count > 0 && format->video->nb_samples == sei_count) { + return err; + } + + // quicktime player compatible: skip the packet without any nalu. + if (!format->is_avc_sequence_header() && format->video->nb_samples == 0) { + srs_warn("skip video segment has empty samples and is not sequence header."); + return err; + } + if ((err = segment->write_video(shared_video, format)) != srs_success) { return srs_error_wrap(err, "write video"); }