英文:
How to make MediaRecorder outputs streambale?
问题
I am using MediaRecorder to record the webcam like this:
我正在使用MediaRecorder来录制网络摄像头,像这样:
let options
如果(MediaRecorder.isTypeSupported('video/webm; codecs=h264')) {
options = { mimeType: 'video/webm; codecs=h264' };
} else if (MediaRecorder.isTypeSupported('video/webm; codecs=vp9')) {
options = { mimeType: 'video/webm; codecs=vp9' };
} else if (MediaRecorder.isTypeSupported('video/webm; codecs=vp8')) {
options = { mimeType: 'video/webm; codecs=vp8' };
} else {
options = {
mimeType: 'video/mp4', audioBitsPerSecond: 128 * 1000,
videoBitsPerSecond: 1 * 1000 * 1000
};
}
recorder = new MediaRecorder(canvasStream, options);
recorder.start(500)
And I am not able to use video/mp4
as mime type because is not supported by the browsers so I am using video/webm
instead. The output file is in chunks and the playback is really smooth yet I am not able to play it online unless it is fully loaded. I decided to add FFMPEG into the process and used ffmpeg -i input.webm -c copy -movflags +faststart output.mp4
but the result is the same. My understanding is that MediaRecorder
is recording in chunks that has no MOOV atom to begin with therefore there is no MOOV to be brought to the beginning of the file. How can I generate MOOV for video/webm
? Will having MOOV make my file streamable or playable at buffer at all?
我无法使用video/mp4
作为媒体类型,因为浏览器不支持,所以我改用了video/webm
。输出文件是分块的,播放非常顺畅,但除非完全加载,否则无法在线播放。我决定将FFMPEG添加到流程中,使用了ffmpeg -i input.webm -c copy -movflags +faststart output.mp4
,但结果仍然相同。我理解的是,MediaRecorder
以没有MOOV原子开头的块方式记录,因此没有MOOV可以移动到文件的开头。如何为video/webm
生成MOOV?拥有MOOV会使我的文件能够流式传输或在缓冲区中播放吗?
Here is a sample of my file:
这是我的文件示例:
英文:
I am using MediaRecorder to record the webcam like this :
let options
if (MediaRecorder.isTypeSupported('video/webm; codecs=h264')) {
options = { mimeType: 'video/webm; codecs=h264' };
} else if (MediaRecorder.isTypeSupported('video/webm; codecs=vp9')) {
options = { mimeType: 'video/webm; codecs=vp9' };
} else if (MediaRecorder.isTypeSupported('video/webm; codecs=vp8')) {
options = { mimeType: 'video/webm; codecs=vp8' };
} else {
options = {
mimeType: 'video/mp4', audioBitsPerSecond: 128 * 1000,
videoBitsPerSecond: 1 * 1000 * 1000
};
}
recorder = new MediaRecorder(canvasStream, options);
recorder.start(500)
And I am not able to use video/mp4
as mime type because is not supported by the browsers so I am using video/webm
instead. The output file is in chunks and the playback is really smooth yet I am not able to play it online unless it is fully loaded. I decided to add FFMPEG into the process and used ffmpeg -i input.webm -c copy -movflags +faststart output.mp4
but the result is the same. My understanding is that MediaRecorder
is recording in chunks that has no MOOV atom to begin with therefore there is no MOOV to be brought to the beginning of the file. How can I generate MOOV for video/webm
? Will having MOOV make my file streambale or playable at buffer at all?
Here is a sample of my file :
答案1
得分: 1
我不能使用video/mp4作为媒体类型,因为浏览器不支持,所以我改用video/webm。
你在十六进制编辑器中显示的文件明显是MP4/ISOBMFF,而不是WebM/Matroska。你是说这是经过FFmpeg处理后得到的文件,还是直接从MediaRecorder获取的文件?
输出文件是分块的,播放非常流畅,但除非完全加载,否则无法在线播放。
通常情况下,不需要寻找就可以正常播放...问题在于寻找,因为播放器不知道这些元素的长度/大小,由于MediaRecorder输出是流式传输的,它们具有无限大小。与MP4一样,你可以使用WebM进行相同的操作:
ffmpeg -i original.webm -c copy fixed.webm
如何为video/webm生成MOOV?
在WebM/Matroska中没有这样的东西。
英文:
> And I am not able to use video/mp4 as mime type because is not supported by the browsers so I am using video/webm instead.
Well, the file you show in your hex editor is definitely MP4/ISOBMFF, and not WebM/Matroska. Are you saying that's the file you're getting after your FFmpeg process, or the one straight out of MediaRecorder?
> The output file is in chunks and the playback is really smooth yet I am not able to play it online unless it is fully loaded.
Normally, playback will be fine without seeking... it's seeking that's the problem since the player doesn't know how long/big the elements are as they have indefinite size due to the MediaRecorder output being streamed. Much like you're doing with MP4, you can do the same with WebM:
ffmpeg -i original.webm -c copy fixed.webm
> How can I generate MOOV for video/webm?
There is no such thing in WebM/Matroska.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论