Skip to content

Video encoder behavior is under specified #241

Closed

Description

@youennf

The current spec is shy on how encoders are expected to work.
In particular, it is unclear whether they should favour latency, i.e output a chunk as soon as possible or on the contrary buffer several frames and try to optimise.
Similarly, it is unclear whether encoders should be able to use things like bi-predictive frames to improve compression, at the expense of decoding latency.

If we look at existing APIs, VideoToolbox has a number of flags such as kVTCompressionPropertyKey_RealTime or kVTCompressionPropertyKey_AllowFrameReordering.

The same can be said about bitrate.
https://w3c.github.io/webcodecs/#dictdef-videoencoderconfig has a bitrate which is defined as an average bitrate.
Some encoders might decide to have a loose definition of bitrates, some encoders might decide to drop frames to strictly respect the average bitrate, VBR vs. CBR...

If we look at existing APIs, VideoToolbox has two APIs for bitrate, kVTCompressionPropertyKey_AverageBitRate and kVTCompressionPropertyKey_DataRateLimits.

Depending on the usecases, it might be good to:

  • provide guidelines for implementors on a common encoder strategy selection (favour latency?).
  • provide API, for instance hints, for a web page to communicate what encoder strategy to use.

Activity

  1. padenot commented on May 11, 2021

    @padenot
    Collaborator

    #206 is a bit about this (started about the decode side though).

  2. chcunningham commented on May 11, 2021

    @chcunningham
    Collaborator

    We plan to add a number of knobs to the API for rate control generally. Tracked in #56. I think strategy hints (like discussed in #206) are also reasonable to consider.

    In the interim, I agree that the spec should provide guidelines to implementers for common encoder selection strategy. Chrome has tried to pick reasonable defaults considering the most common use cases. I'd like to produce a longer answer with the details on those decisions. Stand by.

  3. added
    extension
    on May 12, 2021
  4. chcunningham commented on May 21, 2021

    @chcunningham
    Collaborator

    I'm back to talk about common encoder (and decoder) selection strategy.

    After lots of discussion, we propose the following principle: don't constrain features/quality unless the user asks for it.

    For encoder defaults, this would mean:

    • don't constrain quality for the sake of latency
    • don't constrain bitrate unless requested (VBR by default)
    • allow b-frames

    For decoders:

    • don't sacrifice bandwidth for the sake of latency

    Of course, we also intend to propose knobs to make all of the above configurable.

    • We are already proposing a latency knob. Currently just in the context of decoding, but seems encoding needs something too. Symmetry would be nice if reasonable.
    • I will shortly propose a new knob for explicit CBR vs VBR mode
    • For B frames, codec profile already provides a good means to opt-out. Open to adding an additional knob though.
  5. padenot commented on May 21, 2021

    @padenot
    Collaborator

    I think I generally agree with having defaults this way. To paraphrase, most of the case you care about the size and quality, and when you care about other aspects, you'll be able to get what you want.

    don't sacrifice bandwidth for the sake of latency

    You mean throughput ? I agree in any case.

    I will shortly propose a new knob for explicit CBR vs VBR mode

    That's absolutely required for security, when sending the video in an encrypted channel.

  6. youennf commented on May 21, 2021

    @youennf
    ContributorAuthor

    These defaults look good to me as well.

    CBR for audio seems good as well as an option like done for MediaRecorder.

    Ideally, implementations would be able to just use OS defaults or do minimal setup. That might be a good way to validate these defaults.

    We might still want to add some guidelines like: a video encoder when receiving a frame is expected to output the compressed frame without having to wait for another frame to be received.

  7. chcunningham commented on Jun 2, 2021

    @chcunningham
    Collaborator

    We might still want to add some guidelines like: a video encoder when receiving a frame is expected to output the compressed frame without having to wait for another frame to be received.

    I think, aligning with the principle above (don't constrain features/quality unless the user asks for it), the default would be to fill the underlying encoding pipeline to achieve maximum bandwidth. Users would then flush() whenever they need to push out all pending chunks. But I am very supportive of having a mode/knob whereby users can enable a 'low latency' or 'realtime' mode that behaves as you described.

  8. aboba commented on Jun 11, 2021

    @aboba
    Collaborator

    @youennf @alvestrand content-hints "hints... what encoder strategy to use". It is a property of a MediaStreamTrack, but not of a VideoFrame. So there has to be an explicit way for the hint to be provided to the encoder.

  9. chcunningham commented on Jan 18, 2022

    @chcunningham
    Collaborator

    I think we can probably close this. Defaults are now established in the spec per our plan above. Please re-open if more to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions