New issue
Advanced search Search tips

Issue 605750 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Apr 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

MediaStreamRecorder bitrate configuration does not work

Reported by jnor...@hirevue.com, Apr 21 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36

Example URL:
https://webrtc.github.io/samples/src/content/getusermedia/record/

Steps to reproduce the problem:
1. Go to the above URL.
2. Put a breakpoint in this code:
function startRecording() {
  var options = {mimeType: 'video/webm'};
  recordedBlobs = [];
  try {
    mediaRecorder = new MediaRecorder(window.stream, options); // BREAKPOINT HERE
3. Start recording; breakpoint will be hit
4. In the console, type:

options.videoBitsPerSecond = 120000
options.audioBitsPerSecond = 120000

5.  Continue execution
6. After a bit of time, hit stop recording, and download the file

What is the expected behavior?
The file has a bitrate that is roughly ~240 kbps

What went wrong?
The file actually has an _extremely_ high bitrate; much higher than had I actually specified nothing at all.  This can be observed by remuxing the file with ffmpeg ("ffmpeg -i input.webm -c:v copy -c:a copy output.webm") and then examining the bitrate with ffprobe ("ffprobe output.webm"), or just computing the bitrate based on file size.  The test I did resulted in a bitrate of roughly ~4.8 mbit/sec for a VGA clip.  I've attached that file here.

Had I specified nothing, I would have had a file with a bitrate around 1 mbit/sec.

Did this work before? N/A 

Is it a problem with Flash or HTML5? HTML5

Does this work in other browsers? N/A 

Chrome version: 50.0.2661.86  Channel: stable
OS Version: OS X 10.9.5
Flash Version: Shockwave Flash 21.0 r0

I've also tried setting the bitrate via MediaRecorder.videoBitsPerSecond/MediaRecorder.audioBitsPerSecond; that doesn't appear to do anything.
 
test_3_remuxed.webm
7.2 MB Download

Comment 1 by jnor...@hirevue.com, Apr 21 2016

I'm currently building chrome so I can debug.  Examining the codebase, I don't see where I'm running into trouble.

Comment 2 by jnor...@hirevue.com, Apr 21 2016

Oh, I should also mention I tried in Canary; same result.

Comment 3 by ajha@chromium.org, Apr 22 2016

Cc: mcasas@chromium.org
Components: -Internals>Media Blink>MediaStreamRecording
Adding proper label and Cc'ing 	mcasas@ for help in investigating this further.

Thank you!

Comment 4 by jnor...@hirevue.com, Apr 22 2016

I'm not positive, but I think the issue is in video_track_recorder.cc:

  if (bits_per_second_ > 0) {
    codec_config_.rc_target_bitrate = bits_per_second_;
  } else {
    codec_config_.rc_target_bitrate = size.GetArea() *
                                      codec_config_.rc_target_bitrate /
                                      codec_config_.g_w / codec_config_.g_h;
  }

However, reading the VP9 documentation, http://www.webmproject.org/docs/webm-sdk/structvpx__codec__enc__cfg.html#ab8339685175d66710f482706cc9f0aed , rc_target_bitrate is in *kilobits*, which would explain why I'm getting massive file sizes.

I tested this code, and it correctly creates a file that's roughly the size I would expect:

  if (bits_per_second_ > 0) {
    codec_config_.rc_target_bitrate = bits_per_second_ / 1000;
  } else {
    codec_config_.rc_target_bitrate = size.GetArea() *
                                      codec_config_.rc_target_bitrate /
                                      codec_config_.g_w / codec_config_.g_h;
  }

Comment 5 by jnor...@hirevue.com, Apr 22 2016

Also, one other question: assuming ^^^ is the bug, what's the possibility of hoisting this to Chrome 50?  Without the ability to set bitrate, it makes it really hard to make small recordings for screen sharing, so it's going to seriously hurt my ability to use this feature.

Comment 6 by mcasas@chromium.org, Apr 22 2016

Labels: M-52
Owner: mcasas@chromium.org
Status: Assigned (was: Unconfirmed)
jnoring@ good analysis. First, note that in [1] the bitrates
are clamped and checked for consistency, so keep that in 
mind if you go for settings |bitsPerSecond| in the options
dictionary. Also note that the bitrates must be set before
creating the MediaRecorder. You probably know those things,
but is good to mention just in case.

On #4, this is probably the case. Could you make a CL and
upload for review? See [2] for the process. Note that you
might need to add your name to the AUTHORS file (see the
Legal lines in [3].

M50 is in stable right now so only uber important security
fixes could be landed AFAIK. If your CL would land, it'd
be in M52 and could be merged back to M51.

[1] https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/modules/mediarecorder/MediaRecorder.cpp&sq=package:chromium&type=cs&q=mediarecorder.cpp&l=52
[2] https://www.chromium.org/developers/contributing-code#TOC-Create-a-change-list-CL-
[3] https://www.chromium.org/developers/contributing-code#TOC-Get-your-code-ready

Comment 7 by jnor...@hirevue.com, Apr 22 2016

Okay, I've taken my first stab at a CL: https://codereview.chromium.org/1913233002/

I probably did _something_ wrong so apologies in advance.  Thank you so much for the prompt reply, @mcasas!

Comment 8 by jnor...@hirevue.com, Apr 23 2016

mcasas@ I believe my CL was approved?  What's the process for that getting into Canary, and potentially getting it on 51?

Thanks again for all your help, hugely appreciated.
Project Member

Comment 9 by bugdroid1@chromium.org, Apr 25 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0a58e7128c0559027991ae4671fb7b16274b7ba3

commit 0a58e7128c0559027991ae4671fb7b16274b7ba3
Author: jnoring <jnoring@hirevue.com>
Date: Mon Apr 25 03:15:04 2016

Fix MediaRecorder bitrate configuration bug

The MediaRecorder API specifies that bitrates be communicated in bits
per second, which is correctly plumbed through Chrome.  However, VPx
encoders expect its arguments to be specified in kilobits per second.
This resulted in specifying any bitrate via the javascript API to be
off by a thousand, resulting in enormous files.  Change it so we
convert bits -> kilobits by dividing by 1000
BUG= 605750 

R=mcasas@chromium.org

Review URL: https://codereview.chromium.org/1913233002

Cr-Commit-Position: refs/heads/master@{#389411}

[modify] https://crrev.com/0a58e7128c0559027991ae4671fb7b16274b7ba3/AUTHORS
[modify] https://crrev.com/0a58e7128c0559027991ae4671fb7b16274b7ba3/content/renderer/media/video_track_recorder.cc

jnoring@ could you please confirm that the change
works in the latest Canary? If so, I can request 
the merge back to M51 since is a small patch with
limited risk.
Project Member

Comment 11 by bugdroid1@chromium.org, Apr 25 2016

Labels: merge-merged-2716
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0a58e7128c0559027991ae4671fb7b16274b7ba3

commit 0a58e7128c0559027991ae4671fb7b16274b7ba3
Author: jnoring <jnoring@hirevue.com>
Date: Mon Apr 25 03:15:04 2016

Fix MediaRecorder bitrate configuration bug

The MediaRecorder API specifies that bitrates be communicated in bits
per second, which is correctly plumbed through Chrome.  However, VPx
encoders expect its arguments to be specified in kilobits per second.
This resulted in specifying any bitrate via the javascript API to be
off by a thousand, resulting in enormous files.  Change it so we
convert bits -> kilobits by dividing by 1000
BUG= 605750 

R=mcasas@chromium.org

Review URL: https://codereview.chromium.org/1913233002

Cr-Commit-Position: refs/heads/master@{#389411}

[modify] https://crrev.com/0a58e7128c0559027991ae4671fb7b16274b7ba3/AUTHORS
[modify] https://crrev.com/0a58e7128c0559027991ae4671fb7b16274b7ba3/content/renderer/media/video_track_recorder.cc

mcasas@ yes, I'll confirm tomorrow when Canary is updated; I must have missed the nightly build for today.
Okay, it appears fixed in Canary.  I've attached a file that correctly recorded at roughly ~251 kbit/sec after setting the bitrate on audio and video.
test_remuxed.webm
390 KB Download
mcasas@, do you need me to do anything to help get this into 51?
Labels: Merge-Request-51
thanks jnoring@ I'll take the merge back (it's easy
if you're a committer).

Comment 16 by tin...@google.com, Apr 26 2016

Labels: -Merge-Request-51 Merge-Approved-51 Hotlist-Merge-Approved
Your change meets the bar and is auto-approved for M51 (branch: 2704)
Please merge your change before 5:00 PM PST today to M51 branch 2704, so we can take it for this week beta. Thank you.
Project Member

Comment 18 by bugdroid1@chromium.org, Apr 26 2016

Labels: -merge-approved-51 merge-merged-2704
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/60b153f48f8581bc4a781a2d9fa22efdbbedad02

commit 60b153f48f8581bc4a781a2d9fa22efdbbedad02
Author: mcasas <mcasas@google.com>
Date: Tue Apr 26 21:27:56 2016

Fix MediaRecorder bitrate configuration bug

The MediaRecorder API specifies that bitrates be communicated in bits
per second, which is correctly plumbed through Chrome.  However, VPx
encoders expect its arguments to be specified in kilobits per second.
This resulted in specifying any bitrate via the javascript API to be
off by a thousand, resulting in enormous files.  Change it so we
convert bits -> kilobits by dividing by 1000
BUG= 605750 

R=mcasas@chromium.org

Review URL: https://codereview.chromium.org/1913233002

Cr-Commit-Position: refs/heads/master@{#389411}
(cherry picked from commit 0a58e7128c0559027991ae4671fb7b16274b7ba3)

NOTRY=true
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1925443002

Cr-Commit-Position: refs/branch-heads/2704@{#253}
Cr-Branched-From: 6e53600def8f60d8c632fadc70d7c1939ccea347-refs/heads/master@{#386251}

[modify] https://crrev.com/60b153f48f8581bc4a781a2d9fa22efdbbedad02/AUTHORS
[modify] https://crrev.com/60b153f48f8581bc4a781a2d9fa22efdbbedad02/content/renderer/media/video_track_recorder.cc

Status: Fixed (was: Assigned)
Marking as resolved, jnoring@hirevue.com,
reopen if not WAI. Thanks!
Components: -Blink>MediaStreamRecording Blink>MediaStream>Recording
Renamed component Blink>MediaStreamRecording to Blink>MediaStream>Recording. Moving issues to the new component. 
Components: Blink>MediaRecording
Components: -Blink>MediaStream>Recording

Sign in to add a comment