【发布时间】:2015-02-12 23:54:54
【问题描述】:
我目前正在开发一个组件,它允许您制作网络摄像头视频并将它们直接上传到 amazon s3。为此,我使用 RecordRTC 库和 Amazon S3 存储。我发现了一个奇怪的问题,我不确定它是否与 RecordRTC blob 或亚马逊配置有关。当文件大小超过 1MB 时,Amazon 服务器会挂起,并在 20 秒后返回超时错误。谁能帮我解决这个问题?这是我的记录器组件代码(p()与console.log()相同):
navigator.record_function = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.record_function) {
navigator.record_function(videoObj, function (stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
$("#stop_recording").click(function () {
stream.stop();
});
// init recorders
audio_recorder = RecordRTC(stream, {type: "audio", bufferSize: 16384});
video_recorder = RecordRTC(stream, videoOptions);
}, errBack);
}
$("#start_recording").click(function () {
// record the audio and video
video_recorder.startRecording();
audio_recorder.startRecording();
});
对于上传器组件:
// Populate the Post paramters.
fd.append('key', "users/" + Main.current_user.id + "/test.webm");
fd.append('AWSAccessKeyId', msg.access_key_id);
fd.append('acl', 'private');
fd.append('policy', msg.policy);
fd.append('signature', msg.signature);
fd.append('Content-Type', '$Content-Type');
fd.append('x-amz-server-side-encryption', 'AES256');
fd.append('success_action_status', '201');
fd.append('name', 'test.webm');
fd.append('Filename', 'test.webm');
fd.append("file", file);
xhr.open('POST', 'https://' + msg.bucket + '.s3.amazonaws.com', true);
xhr.upload.addEventListener('progress', function (e) {
p(e);
}, false);
xhr.onreadystatechange = function () {
p(xhr.readyState);
};
xhr.send(fd);
$("#stop_recording").click(function () {
// stop recorders
audio_recorder.stopRecording(function () {
var audio_blob = audio_recorder.getBlob();
p(audio_blob);
// VideoUploader.upload_user_audio(audio_blob);
}
);
video_recorder.stopRecording(function () {
var video_blob = video_recorder.getBlob();
p(video_blob);
VideoUploader.upload_user_video(video_blob);
});
});
超时的错误信息是:
Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
感谢我能得到的任何帮助,我真的迷路了。 提前致谢。
【问题讨论】:
-
你可以试试这个:github.com/rjmackay/recordly.io 或者这个:github.com/andrewrk/node-s3-client 你甚至可以使用“bufferSize:0”让 Chrome 决定音频缓冲区的大小(例如 2048)。更小的 bufferSize 会产生更小的 WAV。您甚至可以使用“leftChannel:true”来仅录制左(单声道)通道。它会减少一半/大小。您甚至可以尝试 MediaStreamRecorder.js 来获取基于间隔的 blob:github.com/streamproc/MediaStreamRecorder
-
感谢您的意见。与此同时,我发现问题与 S3 无关,因为即使我尝试将大于 1MB 的文件上传到本地服务器,它仍然存在。我测试的浏览器是firefox。我将尝试使用媒体流记录器,看看它的行为是否有所不同。
-
这是一个有趣的现象。我尝试使用 MediaStreamRecorder,同样的错误仍然存在。如果录制大于 1MB,则上传挂起。有趣的是,该错误不会在 Chrome 上发生!只有 Firefox 似乎有这个问题。是否存在特定于 Firefox 或某些其他浏览器的某种缓冲区问题?
-
您可能需要尝试使用 jQuery 上传器,而不是直接使用 XHR。
-
根据我的观察,S3 并不总是返回响应,有时它会挂起并仅返回 400。您提供的解决方案解决了问题 - 非常感谢!
标签: javascript amazon-s3 html5-video webrtc video-capture