Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dvr mp4 bugs #4201

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Loading