Skip to content
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

Add audioConstantBitRate flag to MediaRecorderOptions. #185

Merged
merged 7 commits into from Feb 4, 2020
Merged

Add audioConstantBitRate flag to MediaRecorderOptions. #185

merged 7 commits into from Feb 4, 2020

Conversation

ghost
Copy link

@ghost ghost commented Sep 5, 2019

This pull request is to add the ability to specify that a constant bitrate audio file should be encoded, as detailed in #183

@ghost
Copy link
Author

ghost commented Sep 5, 2019

WRT IPR checks, this PR is a follow on from https://chromium-review.googlesource.com/c/chromium/src/+/1731907

@alvestrand
Copy link
Contributor

Unfortunately the IPR check is the W3C IPR check, not the Google IPR check.
Is your company a W3C member?

@ghost
Copy link
Author

ghost commented Sep 9, 2019

No it isn't, sorry.

@ghost
Copy link
Author

ghost commented Sep 13, 2019

So what do I need to do WRT IPR?

@dontcallmedom
Copy link
Member

hi @sizeak, can you get in touch with me at dom@w3.org? This will help explore the possibilities.

@dontcallmedom
Copy link
Member

Thank you @sizeak for providing separately the proper IPR commitment - the IPR error can be safely ignored for this pull request at this time (I'll work in actually clearing it, but don't want to block this discussion on this)

@ghost
Copy link
Author

ghost commented Oct 3, 2019

Thanks for helping with the IPR stuff.

Does anyone have any thoughts on adding the flag?

@ghost
Copy link
Author

ghost commented Oct 18, 2019

Hi,

Sorry to keep pestering, but this is something causing us pain in live. How do we move this forward?

Thanks

@dontcallmedom
Copy link
Member

@henbos @Pehrsons @jan-ivar any input on the substance of the proposed change?

@henbos
Copy link
Contributor

henbos commented Nov 13, 2019

It seems innocent to me, but I don't know about implementation details. An audio MediaStreamTrack is something playing live, do we always have enough samples and can we always transform it to a constant bitrate. @ivocreusen Can you comment on the idea of recording (through the MediaRecorder API) i.e. encoding at a constant bitrate? Context: general API about encoding a track, not specific to WebRTC.

@jan-ivar
Copy link
Member

Can't this be set with mimeType already? E.g. "audio/webm; codecs=opus.cbr"

@ghost
Copy link
Author

ghost commented Nov 13, 2019

That was my suggestion to the Chrome team in the PR linked at the top of this thread, but the file owner said it was a hack.

Here is the relevant quote from the PR:

Hey, apologies, I'm gonna be a major wet blanket here. Simon, this isn't directed at you - you followed the advice of the Chrome folks.

Using mime type to encode CBR is hack. Codecs strings are formally specified and following the specification is the best way to keep UAs interoperable and reduces pain for the whole ecosystem. The MediaRecorder spec is already looser than I'd like on mime-types (e.g. codecs="h264") and its bad to open up more exceptions.

The best path forward is to to change the spec (strawman: add 'bool cbr;' to MediaRecorderOptions). This is also much more discoverable.

@jan-ivar
Copy link
Member

My inclination is to say this is a supported feature, not a hack. Open to hear arguments to the contrary. @Pehrsons thoughts?

@jan-ivar
Copy link
Member

To clarify: adding API surface to cover everything that can already be set through mimeType seems redundant.

@ghost
Copy link
Author

ghost commented Nov 15, 2019

I'll feed back the reaction here to the original Chrome PR and see if the developer that objected would like to weigh in, unless you would be willing to make the case for the mimeType suggestion on that PR yourself?

@jan-ivar
Copy link
Member

@sizeak Feel free to point them here.

@chcunningham
Copy link

Hi group, the comment was from me. I maintain the media mime parsing code in Chrome and I work on the MediaCapabilities spec where mime/codec strings are a key input.

Both recording and playback operate on codecs in containers. Right now, when it comes to opus at least, we are unified in the the way its described.

To date, "opus.cbr" is not a valid codec string. All UAs that support opus playback implicitly support both cbr and vbr, but querying any playback API's (canPlayType(), MediaCapabilities, isTypeSupported()) with "opus.cbr" will get a return value that indicates non-support (because they don't recognize it).

The need to signal CBR support is specific to the domain of MediaRecorder, and not necessarily specific to opus.

Adding an attribute that is external to the codec string solves the issue and avoids the pitfalls above.

MediaRecorder.bs Outdated
@@ -580,6 +580,7 @@ dictionary MediaRecorderOptions {
unsigned long audioBitsPerSecond;
unsigned long videoBitsPerSecond;
unsigned long bitsPerSecond;
boolean audioConstantBitRate;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe call it BitsPerSecond to match the other members

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BitsPerSecond is a bit verbose, especially in the case of audioConstantBitsPerSecond, but you are right that it would be better to be consistent. Will update.

@jan-ivar
Copy link
Member

To date, "opus.cbr" is not a valid codec string.

@chcunningham Thanks for clarifying. I was missing this important detail. In that case I agree mimeType is not sufficient as an API here.

@ghost
Copy link
Author

ghost commented Nov 15, 2019

Thanks for commenting @chcunningham, I think I'm in agreement too now. I hadn't considered this:

The need to signal CBR support is specific to the domain of MediaRecorder, and not necessarily specific to opus.

While I don't think there is an official spec for the Opus mimetype (although there may be something browser specific), I interpreted https://tools.ietf.org/html/rfc6381#page-8 as allowing "opus.cbr", but I hadn't stopped to consider that it would be meaningless specifying it in regards to anything other than an encoder, which does make it feel a bit hacky.

@Pehrsons
Copy link
Collaborator

I'm a bit torn about adding attributes this way because if one were to add support for all encoder capabilities we'd get a very large struct, without any apparent structure.

Unfortunately there's precedence through the BitsPerSecond attributes.

To be pragmatic and to set a precedence that hopefully avoids painting us too far into potential future corners, I suggest we change it to audioBitrateControl (or some such, bikeshedding on the name welcome), which can take the values cbr and vbr, at least. Do we need more?

Likewise for video since we're adding the spec language for this anyway.

I think this should use slots in the ctor algorithm like is done for the BitsPerSecond init dict attributes, because the start algorithm (where these attributes should be used to constrain the configuration of the recorder) doesn't have access to the init dict.

We should probably say something on what is allowed if the UA for some reason does not support a given mode.

@sizeak
Copy link
Contributor

sizeak commented Dec 3, 2019

So would everybody be happy with this:

enum AudioBitrateMode {
  "cbr",
  "vbr"
};
dictionary MediaRecorderOptions {
  DOMString mimeType;
  unsigned long audioBitsPerSecond;
  unsigned long videoBitsPerSecond;
  unsigned long bitsPerSecond;
  AudioBitrateMode audioBitrateMode;
};

@Pehrsons
Copy link
Collaborator

Pehrsons commented Dec 9, 2019

I want to see

enum BitrateMode, and

BitrateMode audioBitrateMode;
BitrateMode videoBitrateMode;

Otherwise LGTM at a high level.

@chcunningham
Copy link

BitrateMode sounds good to me.

Replace the single audioConstantBitsPerSecond field with a BitrateMode
enum and fileds for audio and video bitrate mode using this enum.
Copy link
Member

@jan-ivar jan-ivar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept lgtm. Just need to flesh out some details.

MediaRecorder.bs Outdated Show resolved Hide resolved
MediaRecorder.bs Show resolved Hide resolved
@sizeak
Copy link
Contributor

sizeak commented Jan 22, 2020

Are you happy with the changes @Pehrsons ?

@jan-ivar
Copy link
Member

@simoncent he's going to be out for a while, but I don't think he would object. Will try to get this merged Thursday.

@sizeak
Copy link
Contributor

sizeak commented Jan 22, 2020

Ah sorry, I didn't realise. That would be great, thanks!

@jan-ivar
Copy link
Member

Ran out of time during the editor's meeting unfortunately. I'm ok with merging this. @henbos @alvestrand do you see any reasons we shouldn't?

@youennf
Copy link
Contributor

youennf commented Jan 30, 2020

I am fine with CBR for audio, I am less sure about video.
Can we split the PR for now?

@jan-ivar jan-ivar self-assigned this Jan 30, 2020
MediaRecorder.bs Outdated
@@ -283,6 +303,14 @@ interface MediaRecorder : EventTarget {
the value might be surpassed, not achieved, or only be achieved over a long
period of time.</li>

<li>Constrain the configuration of |recorder| to encode using the
{{BitrateMode}} specified by the value of |recorder|'s {{videoBitrateMode}}
attribute for all video tracks |recorder| will be recording.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense for video?

@alvestrand
Copy link
Contributor

I think CBR is fairly widespread for audio, but more rare wrt video (most encoders require heavy dynamic tuning to produce CBR). I'm happy with merging the audio CBR value now, and revisitng the question of whether we want video CBR later.

@jan-ivar
Copy link
Member

jan-ivar commented Jan 30, 2020

will split out video for now, fix order bug, and merge.

@jan-ivar jan-ivar merged commit 6a558be into w3c:master Feb 4, 2020
@sizeak
Copy link
Contributor

sizeak commented Jul 20, 2020

Fixes #183

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

Successfully merging this pull request may close these issues.

None yet

8 participants