Create live video of jpeg snapshots using Gstreamer and JavaScript setTimeout()

别等时光非礼了梦想. 提交于 2019-12-25 02:53:40

问题


I am trying to create a live "video" stream using an tag on a web page.

A Gstreamer pipeline continually overwrites a file "snapshot.jpeg" with a new frame grabbed from a webcam using video4linux2 with a framerate of 15 fps.

A web page renders the image without caching every 100 ms.

The problem is that I get ERR_CONTENT_LENGTH_MISMATCH (in browser console) for the image source on many frames. This is shown as a broken link in the browser.

GStreamer 0.10 syntax

gst-launch v4l2src ! video/x-raw-yuv, width=640, height=480, framerate=15/1 ! jpegenc ! multifilesink location=/var/www/video/snapshot.jpeg

HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset='UTF-8' />
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="app.js"></script>
    </head>
    <body>  
        <img id="snapshot" src="snapshot.jpeg"/>
    </body>
</html>

JavaScript

$(function() {
    function refreshImage(){
    $("#snapshot").attr("src", 'snapshot.jpeg?' + Math.random());
    setTimeout(refreshImage, 100);
    }
    refreshImage();
})

回答1:


Try to hook setTimeout to Image.onload:

$(function() {
    function refreshImage(){
        $("#snapshot").attr("src", 'snapshot.jpeg?' + Math.random());
    }
    $("#snapshot").onload = function(){
        setTimeout(refreshImage, 100);
    }
    refreshImage();
})


来源:https://stackoverflow.com/questions/23385516/create-live-video-of-jpeg-snapshots-using-gstreamer-and-javascript-settimeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!