ThibaultBee / StreamPack

SRT/RTMP/RTMPS live streaming libraries for Android
https://thibaultbee.github.io/StreamPack/index.html
Apache License 2.0
196 stars 70 forks source link

RTMP data timestamp not correct #58

Closed clacladev closed 1 year ago

clacladev commented 1 year ago

I've been using StreamPack on Android via api.video-reactnative-live-stream. Running on device or simulator the broadcasting service livepeer.studio is not able to show the broadcasted camera content on Android. Even though I am able to see it if I broadcast to a local ffplay -listen 1 -i rtmp://0.0.0.0:1935/s/streamKey.

After talking with a colleague of mine at Livepeer, he debugged the RTMP stream received content. His feedback is:

The RTMP content is completely corrupt:
[124+0] 58 bytes of H264 video keyframe header
[124+0] 4020 bytes of H264 video keyframe NALU
[158+0] 1476 bytes of H264 video iframe NALU
[191+0] 1060 bytes of H264 video iframe NALU
[224+0] 1412 bytes of H264 video iframe NALU
[235+0] 1524 bytes of H264 video iframe NALU
[221+0] 1476 bytes of H264 video iframe NALU
[231+0] 1540 bytes of H264 video iframe NALU
[219+0] 1412 bytes of H264 video iframe NALU
[229+0] 1572 bytes of H264 video iframe NALU
[238+0] 1588 bytes of H264 video iframe NALU
[226+0] 2116 bytes of H264 video iframe NALU
[212+0] 2404 bytes of H264 video iframe NALU
[222+0] 1156 bytes of H264 video iframe NALU
[233+0] 1572 bytes of H264 video iframe NALU
[220+0] 1588 bytes of H264 video iframe NALU
[229+0] 1956 bytes of H264 video iframe NALU
[217+0] 1780 bytes of H264 video iframe NALU
[227+0] 2036 bytes of H264 video iframe NALU
[213+0] 2052 bytes of H264 video iframe NALU
[224+0] 2228 bytes of H264 video iframe NALU
[211+0] 2228 bytes of H264 video iframe NALU
[220+0] 1476 bytes of H264 video iframe NALU
[208+0] 1828 bytes of H264 video iframe NALU
[218+0] 1956 bytes of H264 video iframe NALU
[204+0] 2036 bytes of H264 video iframe NALU
[215+0] 1284 bytes of H264 video iframe NALU
[225+0] 1348 bytes of H264 video iframe NALU
[235+0] 1428 bytes of H264 video iframe NALU
[245+0] 964 bytes of H264 video iframe NALU
[209+0] 868 bytes of H264 video iframe NALU

Numbers in front are timestamps in milliseconds. They're all over the place!

Do you know why this is happening? Thanks

ThibaultBee commented 1 year ago

Hi, I am quite surprised that video frame timestamp are not in order. I know that audio and video frames are not in order because the audio and the video encoders are executed in separate threads and it is too complicated to synchronize. That is not supported by the RTMP format but most of modern RTMP server support that now (Youtube, ffmpeg,...). Could you test with video only?

ThibaultBee commented 1 year ago

Hi,

I just implemented a way to synchronise audio and video frames for RTMP. Could you test the sample in the feature/rtmp_av_sync branch? APK is here: https://github.com/ThibaultBee/StreamPack/suites/10072532349/artifacts/490517994

clacladev commented 1 year ago

Hello! I will happily test it as soon as I am back in early January. Thanks for the ping

clacladev commented 1 year ago

Hey @ThibaultBee I have been able to test the change and it works! Thanks a lot for it

ThibaultBee commented 1 year ago

Hi. Glad to hear that. Sorry I took my time to find a clean way to do do. Other open source librairies changes the timestamp but there is no way I will implement a machanism that changes timestamps.

Aldo, I might add a static variable to enable/disable this mechanism. Not sure yet

ThibaultBee commented 1 year ago

Released in 2.5.2