我在本地托管了一个.mjpeg文件http://127.0.0.1/web/Images/Stream/somevideo.mjpeg
我在cshtml页面中尝试了几个代码。
1。视频标记方法
<video src="http://127.0.0.1/web/Images/Stream/somevideo.mjpeg" controls></video>
2。 img标签方法
<img src="http://127.0.0.1/web/Images/Stream/somevideo.mjpeg"/>
第3。 motionjpeg javascript方法
以下代码从here
复制<img id="motionjpeg" src="http://127.0.0.1/web/Images/Stream/somevideo.mjpeg" />
<script>
//Using jQuery for simplicity
function motionjpeg(id) {
var image = $(id), src;
if (!image.length) return;
src = image.attr("src");
if (src.indexOf("?") < 0) {
image.attr("src", src + "?"); // must have querystring
}
image.on("load", function() {
// this cause the load event to be called "recursively"
this.src = this.src.replace(/?[^\n]*$/, "?") +
(new Date()).getTime(); // 'this' refers to the image
});
}
$(document).ready(function() {
motionjpeg("#motionjpeg"); // Use the function on the image
});
</script>
4。 clipchamp javascript方法
唯一有效的code,但仅适用于Chrome但不适用于IE
<div id="mjpeg_player" style="width:600px;"></div>
<script src='http://127.0.0.1/web/Scripts/jquery-clipchamp-mjpeg-player-plugin-master/src/jquery.clipchamp.mjpeg.player.js'></script>
<script>
$(document).ready(function() {
var mjpegUrl = "http://127.0.0.1/web/Images/Stream/somevideo.mjpeg";
var fps = 20;
var autoloop = true;
$('#mjpeg_player').clipchamp_mjpeg_player(mjpegUrl, fps, autoloop,
function(wrapperElement, playerInterface) {
/*
$('#mjpeg_player_stop').click(function(){
playerInterface.finish();
});
*/
});
});
</script>
仅供参考,我将.mpjeg的MIME类型配置为application / octet-stream
答案 0 :(得分:0)
可能是M-JPEG的正确mime类型,即Motion JPEG
video/x-motion-jpeg
答案 1 :(得分:0)
你试过multipart/x-mixed-replace
吗?
您还必须提供边界参数,因此它看起来像这样:multipart/x-mixed-replace; boundary=--boundary
您必须确定在托管的mjpeg文件上使用哪个边界来分隔单独的帧内容。