admin 管理员组文章数量: 1086019
indicates that Google Chrome is pliant with MediaSource Extensions & H.264.
I make a simple test checking that my video is supported by Chromium, using the <video id='player' autoplay='true'> <source src='/test.mp4' type='video/mp4' /> </video>
The video plays smoothly.
A second alternative that also works fine consists in loading through AJAX the byte chain and converting the buffer to a URI object. Then asigning such URI to the (video) source.src attribute.
Finally I try to load the same video through AJAX and inject it into a MediaSource Buffer. It fails with the error 4. (Source Not supported).
The code used is similar to:
var mediaSource = new (window.MediaSource || window.WebKitMediaSource)();
window.video = document.getElementById('video1');
window.video.addEventListener("error", function onError(err) {
alert("window.video error detected:");
console.dir(window.video.error); window.worker.terminate();
});
window.video.pause();
window.video.src = URL.createObjectURL(mediaSource);
var onMediaSourceOpen = function (e) {
mediaSource.removeEventListener('sourceopen', onMediaSourceOpen);
window.videoSource = mediaSource.addSourceBuffer('video/mp4;codecs="avc1.4d001e,mp4a.40.2"');
injectVideoIntoBuffer();
}
mediaSource.addEventListener('sourceopen', onMediaSourceOpen);
var injectVideoIntoBuffer = function onResponse() {
var xhr = new XMLHttpRequest();
xhr.open('GET', "test.mp4");
xhr.responseType = 'arraybuffer';
xhr.addEventListener("readystatechange", function () {
// Next line raises a MediaError, code: 4, (MEDIA_ERR_SRC_NOT_SUPPORTED)
videoSource.appendBuffer(new Uint8Array(xhr.response));
...
}, false);
xhr.send();
}
I tried different mp4 files, generated either with ffmpeg/avconv or MP4Box. Not luck at this moment. A similar code works fine with VP8/WebM test files.
Thanks in advance for any help/hint or link!
Enrique
http://www.youtube./html5 indicates that Google Chrome is pliant with MediaSource Extensions & H.264.
I make a simple test checking that my video is supported by Chromium, using the <video id='player' autoplay='true'> <source src='/test.mp4' type='video/mp4' /> </video>
The video plays smoothly.
A second alternative that also works fine consists in loading through AJAX the byte chain and converting the buffer to a URI object. Then asigning such URI to the (video) source.src attribute.
Finally I try to load the same video through AJAX and inject it into a MediaSource Buffer. It fails with the error 4. (Source Not supported).
The code used is similar to:
var mediaSource = new (window.MediaSource || window.WebKitMediaSource)();
window.video = document.getElementById('video1');
window.video.addEventListener("error", function onError(err) {
alert("window.video error detected:");
console.dir(window.video.error); window.worker.terminate();
});
window.video.pause();
window.video.src = URL.createObjectURL(mediaSource);
var onMediaSourceOpen = function (e) {
mediaSource.removeEventListener('sourceopen', onMediaSourceOpen);
window.videoSource = mediaSource.addSourceBuffer('video/mp4;codecs="avc1.4d001e,mp4a.40.2"');
injectVideoIntoBuffer();
}
mediaSource.addEventListener('sourceopen', onMediaSourceOpen);
var injectVideoIntoBuffer = function onResponse() {
var xhr = new XMLHttpRequest();
xhr.open('GET', "test.mp4");
xhr.responseType = 'arraybuffer';
xhr.addEventListener("readystatechange", function () {
// Next line raises a MediaError, code: 4, (MEDIA_ERR_SRC_NOT_SUPPORTED)
videoSource.appendBuffer(new Uint8Array(xhr.response));
...
}, false);
xhr.send();
}
I tried different mp4 files, generated either with ffmpeg/avconv or MP4Box. Not luck at this moment. A similar code works fine with VP8/WebM test files.
Thanks in advance for any help/hint or link!
Enrique
Share Improve this question asked Mar 3, 2014 at 21:16 earizonearizon 2,24820 silver badges32 bronze badges3 Answers
Reset to default 4Thanks all for your answers. Looks like newer versions of Chrome fix the problem.
I wrongly assumed that if a codec is supported by the browser, it will automatically be supported by MSE. In practice, that's not the case. A browser can support a set of video codecs (h264/webM/theora/...), it can also support MSE, but just a subset of video codecs when "injecting" the video into MSE buffers.
The patibility matrix between MSE and codecs doesn't only depends on the browser but also on the OS. So for example, Google Chrome Supports MSE+h264 on Windows and Android but not (yet?) on Linux. VP9+MSE is supported on Windows and Linux but not on Android.
Youtube has a very useful test page to check browser support for MSE & h264/VP9 codecs:
https://www.youtube./html5
Try this:
var injectVideoIntoBuffer = function onResponse() {
var xhr = new XMLHttpRequest();
xhr.open('GET', "test.mp4");
xhr.responseType = 'arraybuffer';
xhr.addEventListener("readystatechange", function () {
if (xhr.readyState == xhr.DONE) {
videoSource.appendBuffer(new Uint8Array(xhr.response));
}
...
}, false);
It could be that you're only appending a fragment of the mp4. This would be fine if the fragment from the AJAX request is in whole mp4 atoms, i.e moov, moof, mdat. But i'm thinking that might not be the case.
If it still fails, you could try to transcode the movie again with: (NOTE! This will remove the sound)
ffmpeg -an -codec:v libx264 -profile:v baseline -level 3 -b:v 2000k -i in.mp4 out.mp4
and MP4Box with:
MP4Box -dash 10000 -rap -frag-rap out.mp4
Just to see if the movie works.
I think Chrome might only support WebM with media source extensions for now.
本文标签:
版权声明:本文标题:javascript - H264 video works using src attribute. Same video fails using the MediaSource API (Chromium) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744096783a2533041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论