caffeinetv / libcaffeine

A library for broadcasting to Caffeine.tv
https://www.caffeine.tv
GNU General Public License v2.0
16 stars 5 forks source link

Support 60fps #96

Closed davidc604 closed 4 years ago

davidc604 commented 4 years ago

This PR adds 60 fps support to broadcasting.

If a broadcaster is allowed to broadcast at 60fps, this will set the video capturer to allow up to 60fps input. In addition, the encoder will dynamically adjust the encoding fps based on the input capturer fps. If the input goes above the high threshold (50) it will switch to 60fps; likewise, if it drops below the low threshold (35) it will switch down to encoding at 30fps.


This change is Reviewable

davidc604 commented 4 years ago

Looks good to me. We might want to reduce framerate if the bitrate drops too low in the future, as 2mbit 720p30 looks much better than 2mbit 720p60, but for now this works well.

Thanks! That's a good callout. I will have another PR after this to address that probably in the capture part- prevent capturing at 60fps if current target bitrate is only 2Mbps.

Xaymar commented 4 years ago

As a general guideline, it's best to limit the framerate using bits-per-macroblock or bits-per-pixel. Ideally you want 0.1 bits-per-pixel or higher, which is about 26 bits-per-macroblock. To calculate macroblocks/sec you use the following formulae: (Width*Height*TargetFramerate)/(16*16). Then divide the bitrate in bits/sec by Macroblocks/sec and you have an integer or float that you can use to limit framerate.

Edit: For example, at 720p60 this would result in a minimum of 5.3mbit, and at 540p60 it's around 3.0mbit