ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.82k stars 5.4k forks source link

fix mp4 stts box bug. #4190

Closed suzp1984 closed 1 month ago

suzp1984 commented 1 month ago

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.