如何压缩使用 HTML5 MediaRecorder API 录制的网络摄像头视频?

4
我成功地使用MediaRecorder API录制了我的网络摄像头,但是生成的文件大小与其质量相比似乎太大了。
例如,对于一个8秒长、分辨率为480x640的视频,我得到了1MB的文件大小。这似乎不正确。
我的录制()代码:
navigator.mediaDevices.getUserMedia({video: true, audio: true})
    .then(function(stream){
        var options = {
            mimeType : "video/webm;codecs=vp9"
            //I don't set bitrate here even if I do the quality is too bad
        }
        var media_recorder = new MediaRecorder(media_stream, options);
        var recorded_data = [];
        media_recorder.ondataavailable = function(e){
             recorded_data.push(e.data);
        }
        media_recorder.onstop = function(e){
            recorded_data.push(e.data);
            var recorded_blob = new Blob(recorded_data, { 'type' : 'video/webm; codecs=vp9' });
            var recorded_video_url = window.URL.createObjectURL(recorded_blob);
            //here I write some code to download the blob from this url through a href
        }
    })

通过这种方法获取的文件过大,让我怀疑VP9编码时是否进行了压缩?一个7秒的视频大小约为870kB!

使用mediainfo工具检查该文件,得到以下结果:

General
Count                                    : 323
Count of stream of this kind             : 1
Kind of stream                           : General
Kind of stream                           : General
Stream identifier                        : 0
Count of video streams                   : 1
Count of audio streams                   : 1
Video_Format_List                        : VP9
Video_Format_WithHint_List               : VP9
Codecs Video                             : V_VP9
Video_Language_List                      : English
Audio_Format_List                        : Opus
Audio_Format_WithHint_List               : Opus
Audio codecs                             : Opus
Audio_Language_List                      : English
Complete name                            : recorded_video.webm
File name                                : recorded_video
File extension                           : webm
Format                                   : WebM
Format                                   : WebM
Format/Url                               : http://www.webmproject.org/
Format/Extensions usually used           : webm
Commercial name                          : WebM
Format version                           : Version 2
Internet media type                      : video/webm
Codec                                    : WebM
Codec                                    : WebM
Codec/Url                                : http://www.webmproject.org/
Codec/Extensions usually used            : webm
File size                                : 867870
File size                                : 848 KiB
File size                                : 848 KiB
File size                                : 848 KiB
File size                                : 848 KiB
File size                                : 847.5 KiB
File last modification date              : UTC 2017-05-19 05:48:00
File last modification date (local)      : 2017-05-19 17:48:00
Writing application                      : Chrome
Writing application                      : Chrome
Writing library                          : Chrome
Writing library                          : Chrome
IsTruncated                              : Yes

Video
Count                                    : 332
Count of stream of this kind             : 1
Kind of stream                           : Video
Kind of stream                           : Video
Stream identifier                        : 0
StreamOrder                              : 1
ID                                       : 2
ID                                       : 2
Unique ID                                : 62101435245162993
Format                                   : VP9
Commercial name                          : VP9
Codec ID                                 : V_VP9
Codec ID/Url                             : http://www.webmproject.org/
Codec                                    : V_VP9
Codec                                    : V_VP9
Width                                    : 640
Width                                    : 640 pixels
Height                                   : 480
Height                                   : 480 pixels
Pixel aspect ratio                       : 1.000
Display aspect ratio                     : 1.333
Display aspect ratio                     : 4:3
Frame rate mode                          : VFR
Frame rate mode                          : Variable
Language                                 : en
Language                                 : English
Language                                 : English
Language                                 : en
Language                                 : eng
Language                                 : en
Default                                  : Yes
Default                                  : Yes
Forced                                   : No
Forced                                   : No

Audio
Count                                    : 272
Count of stream of this kind             : 1
Kind of stream                           : Audio
Kind of stream                           : Audio
Stream identifier                        : 0
StreamOrder                              : 0
ID                                       : 1
ID                                       : 1
Unique ID                                : 32224324715799545
Format                                   : Opus
Format/Url                               : http://opus-codec.org/
Commercial name                          : Opus
Internet media type                      : audio/opus
Codec ID                                 : A_OPUS
Codec ID/Url                             : http://opus-codec.org
Codec                                    : Opus
Codec                                    : Opus
Codec/Family                             : PCM
Channel(s)                               : 1
Channel(s)                               : 1 channel
Channel positions                        : Front: C
Channel positions                        : 1/0/0
Sampling rate                            : 48000
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Compression mode                         : Lossy
Delay                                    : 718
Delay                                    : 718ms
Delay                                    : 718ms
Delay                                    : 718ms
Delay                                    : 00:00:00.718
Delay, origin                            : Container
Delay, origin                            : Container
Language                                 : en
Language                                 : English
Language                                 : English
Language                                 : en
Language                                 : eng
Language                                 : en
Default                                  : Yes
Default                                  : Yes
Forced                                   : No
Forced                                   : No

我做错了什么?在追加块后,我需要重新编码吗?我是否缺少某些属性?VP9应该大幅减小文件大小。

1个回答

5

在使用Media Recorder API记录视频时,Chrome的VP9单通道编码器并不会让您看到VP9和H.264之间的主要区别。

当录制网络摄像头视频时,摄像头质量、可用光线以及您正在录制的内容比您使用的视频编解码器更具影响力:

  • 低光条件 => 低帧率 => 更低的比特率
  • 但是在低光条件下噪声比较难有效地进行编码
  • 更好的网络摄像头在任何光照条件下都能捕获更少的噪声数据
  • 谈话需要比大量运动需要更低的比特率

但是以640x480分辨率,30fps为例,每8-10秒需要1MB,这与我的研究结果一致。我使用了此演示文稿,其中尝试使用VP9、H.264和VP8(按顺序)。

VP9应该可以大幅减小文件大小。

与H.264相比,VP9可以减小约30%,但要看到减小的大小,您需要使用双通道编码器(它们不同)和大量的CPU功率。这个过程也将花费更长的时间。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接