【发布时间】:2011-05-25 19:33:58
【问题描述】:
我正在尝试使用 JavaScript 中的图像流合成视频。 问题是“视频”要么是生涩的,而是通过使用各种缓冲区来解决的。然而现在的问题是,图像的下载速度实际上远快于它们的渲染速度。
如果您的图像源发生变化,例如 IP 摄像机,您可以尝试以下示例。我注意到的是,“视频”的更新速度仍然很慢,但是在查看数据包嗅探器时,我可以看到图像实际上被完全检索到的速度比渲染速度要快得多。
示例如下:
<HTML>
<HEAD>
<SCRIPT SRC="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</SCRIPT>
<SCRIPT>
function startVideo()
{
//when the buffer image is loaded, put it in the display
$('#image-buffer').load(function()
{
var loadedImage = $(this).attr('src');
$('#image-displayed').attr('src', loadedImage);
$(this).attr('src',
'http://path.to/image.jpg?nocache=' + Math.random());
});
$('#image-buffer').attr('src',
'http://path.to/image.jpg?nocache=' + Math.random());
}
function stopVideo()
{
$('#image-buffer').unbind('load');
$('#image-buffer').attr('src', '');
$('#image-displayed').attr('src', '');
}
</SCRIPT>
</HEAD>
<BODY>
<BUTTON ONCLICK="startVideo();">Start Video</BUTTON><BR/>
<BUTTON ONCLICK="stopVideo();">Stop Video</BUTTON><BR/>
<IMG ID="image-displayed"/>
<IMG ID="image-buffer" STYLE="visibility: hidden;"/>
</BODY>
</HTML>
【问题讨论】:
标签: javascript jquery image video