xiph / rav1e

The fastest and safest AV1 encoder.
BSD 2-Clause "Simplified" License
3.73k stars 253 forks source link

Add support for variable framerate encodings #3381

Open sdroege opened 6 months ago

sdroege commented 6 months ago

Describe the bug

Currently rav1e assumes that every frame's duration is one unit of time_base. This is only correct for fixed framerate streams.

To Reproduce

Using rav1e to encode a stream coming from a normal webcam or some other source with a variable framerate causes rate control to not work correctly.

Expected behavior

It should be possible to provide timestamps for each frame (in time_base units) and this would be used by rate control to figure out how much time each frame represents.

Prior art can be found in aom (aom_codec_encode() PTS and duration parameters) or libvpx (vpx_codec_encode() PTS and duration parameters). Both seem to work correctly if the duration is just an estimate (you don't necessarily know it yet without waiting for the next frame) and use the PTS as main source of truth.

lu-zero commented 6 months ago

Passing the information would be easy either adding fields to FrameParameters or adding yet another IntoFrame implementation. But it requires the rate control to deal correctly with that change.