-
-
Notifications
You must be signed in to change notification settings - Fork 9k
obs-outputs: Preserve signedness of FLV timestamp #11013
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
base: master
Are you sure you want to change the base?
obs-outputs: Preserve signedness of FLV timestamp #11013
Conversation
|
The timestamp in RTMP is unsigned, so this would result in invalid or out-of-order timestamps being sent. Based on advice from one of the authors of the Enhanced FLV/RTMP spec, we should never send negative or non-monotonic timestamps (he also believes the Since we already start the presentation at a non-0 time to compensate for b-frame delay, it follows that doing the same for audio encoder delay is probably the right approach, hence #10999. |
|
As RTMP timestamps are unsigned like you said, and they are wrapped around when they overflow, the most significant bit in the timestamp value no longer represents signedness. Also discarding the MSB results the timestamp to roll over every 2,147,483,647 miliseconds, while the RTMP specification says it rolls over every 4,294,967,295 milliseconds. Maybe this could be an off-topic, but I think a timestamp in RTMP does not have to start from zero as long as it rolls over at 4,294,967,295 milliseconds, though doing so would improve compatibility with broken implementations. |
|
Even if OBS is going to count RTMP timestamp from zero when it starts streaming, there still might be a slight possibility that one might keep streaming longer than about 50 days, which the timestamp will overflow eventually. Adobe RTMP Specification(HTML ver, PDF ver) covers such situation:
Also I suspect the following code of librtmp will not work as expected, if the MSB is dropped. obs-studio/plugins/obs-outputs/librtmp/rtmp.c Line 4134 in 2fa77c4
|
|
With #10999 merged, is this still needed? |
|
I think so because this is not only related to the initial timestamp, which was already handled by #10999, but also covers RTMP timestamp overflow. Discarding the MSB, which is the identical bit that represents signedness in case of signed integers, limits its maximum value up to (2^31)-1 (==0x7FFF FFFF), and therefore results the timestamp resets to 0 after 0x7FFF FFFF. This behavior does not comply RTMP specification as it specifies that 0 comes after 0xFFFF FFFF. Only few users would be affected because it matters when they streams over 0x7FFF FFFF miliseconds or about 24 days approximately. If you don't think it counts, this PR can be closed without merging. |
Description
obs-outputs: Preserve signedness of FLV timestamp
Motivation and Context
Video File Format Specification Version 10 states that a timestamp in FLV format is a signed 32-bit integer, which are composed of two integers.
How Has This Been Tested?
Inspected RTMP packets with Wireshark.
Types of changes
Checklist: