4

我使用 MediaRecorder api 成功录制了我的网络摄像头,生成的文件大小对于它们的质量来说似乎太大了。

例如,对于 480x640 的 8 秒视频,我得到了 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 应该大大减少文件大小。

4

1 回答 1

5

Chrome 的 VP9 单通道编码器用于通过 Media Recorder API 捕获的视频,您不会看到 VP9 和 H.264 之间的主要区别。

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

  • 低光 => 低 fps => 低比特率
  • 但是在低光照条件下的噪声很难有效编码
  • 更好的网络摄像头在任何光线条件下都能以更少的噪音捕获更多数据
  • 说话的头需要比大量运动更低的比特率

但是每 8-10s @ 640x480 30fps 1MB 符合我的发现。我使用了这个演示,它尝试使用 VP9、H.264 和 VP8(按此顺序)。

VP9 应该大大减少文件大小。

与 H.264 相比,VP9 确实减少了大约 30% 的大小,但要看到减少,您需要使用 2 pass 编码、非常好的编码器(它们不同)和大量的 CPU 能力。该过程也将花费更长的时间。

于 2017-05-25T09:21:22.143 回答