我使用 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 应该大大减少文件大小。