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 mp4 stts box bug. #4190

Closed
wants to merge 5 commits into from
Closed

Conversation

suzp1984
Copy link
Contributor

@suzp1984 suzp1984 commented Sep 29, 2024

How to reproduce?

  1. ./objs/srs -c conf/dvr.mp4.conf
  2. ffmpeg -re -i output.flv -c copy -f flv rtmp://localhost/live/livestream
    the output.flv is recorded from a DJI drone, download from this google drive link: https://drive.google.com/file/d/1IVoDXI-WYoIlKiyzs65fCsDRRt0z-EuU/view?usp=sharing
  3. after finished publish this video, play the livestream.*.mp4 located in trunk/objs/nginx/html/live.
  4. the video playback is 2x slower than the original file.

Cause

The Mp4 frame rate is determined by mp4 box: mdhd and stts. But the stts encoding in srs has bugs. The above output.flv video file has a lot of SEI type of nalu, which is not video samples, SRS can't calculate the stts correctly.

How to calculate stts?

check doc ISO/IEC 14496-12:2012(E) 8.6.1.2 Decoding Time to Sample Box.

https://ossrs.net/lts/zh-cn/assets/files/ISO_IEC_14496-12-base-format-2012-b70dd5f101daecd072700609842c9649.pdf

video source generated by OBS with ultrafast + zerolatency

https://drive.google.com/file/d/1rXipV93EWmtZ-rPShwE66f5aO85ugiIc/view?usp=sharing
Use this source, with video frames split to multi slices, to verify the dvr recorded mp4.

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Sep 29, 2024
@suzp1984 suzp1984 marked this pull request as draft September 29, 2024 11:11
@suzp1984 suzp1984 marked this pull request as ready for review September 29, 2024 16:46
@suzp1984 suzp1984 closed this Sep 30, 2024


// skip any SEI type nalus
if (format->vcodec->id == SrsVideoCodecIdAVC) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need process HEVC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HEVC added.

if (stts && previous) {
if (sample->dts >= previous->dts && previous->nb_subsamples > 0) {
uint32_t delta = (uint32_t)(sample->dts - previous->dts) / previous->nb_subsamples;
stts_entry.sample_count = previous->nb_subsamples;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample in samples is an audio/video frame, nb_subsamples is the nalu count of this frame.
In most cases, it is always one nalu in one frame, but in multi-slice frames, there is more than one nalu in one video frame.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nb_subsamples is a mistake. revert this code.

1. fix stts box calculation;
2. filter nalu SEI for h.265 codec.
@suzp1984 suzp1984 reopened this Oct 13, 2024
@suzp1984 suzp1984 closed this Oct 13, 2024

if (avc_nalu_type == SrsAvcNaluTypeSEI) {
return err;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the video frame is [SEI P], will it drop? SEI always appears in Harward encoders like video toolbox, Nvidia enc, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed on #4201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EnglishNative This issue is conveyed exclusively in English.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants