NodeJS Streaming MJPEG for browser, some images not showing

I am just sending 5 jpegs to the browser. (Actually, the code below may be more elegant, but this is just to show the idea)

    im[0] = fs.readFileSync("banner1.jpg");
    im[1] = fs.readFileSync("banner2.jpg");
    im[2] = fs.readFileSync("banner3.jpg");
    im[3] = fs.readFileSync("banner4.jpg");
    im[4] = fs.readFileSync("banner5.jpg");

    app.get("/image", function(req,res){
        res.setHeader('Content-type', 'multipart/x-mixed-replace; boundary=--myboundary');
        res.write("Content-Type: image/jpeg\r\n\r\n");
        res.write(im[0]);
        res.write("\r\n--myboundary\r\n");
        var time = 1000;
        setTimeout(function(){
            res.write("Content-Type: image/jpeg\r\n\r\n");
            res.write(im[1]);
            res.write("\r\n--myboundary\r\n");
        },time*1);
        setTimeout(function(){
            res.write("Content-Type: image/jpeg\r\n\r\n");
            res.write(im[2]);
            res.write("\r\n--myboundary\r\n");
        },time*2);
        setTimeout(function(){
            res.write("Content-Type: image/jpeg\r\n\r\n");
            res.write(im[3]);
            res.write("\r\n--myboundary\r\n");
        },time*3);
        setTimeout(function(){
            res.write("Content-Type: image/jpeg\r\n\r\n");
            res.write(im[4]);
            res.write("\r\n--myboundary\r\n");
            res.end();
        },time*4);
    });

      

But the problem is it doesn't show im[3]

even if I change the time, so what's the problem? Is Chrome data buffering or NodeJS?

+3
http node.js video buffer mjpeg


source to share


No one has answered this question yet

Check out similar questions:

25
Create MJPEG video stream in C #
7
HttpWebResponse with MJPEG and multipart / x-mixed-replace; border = - content type myboundary response from security camera not working
7
create your own MJPEG stream
3
For an mjpeg stream created with node.js, how do I encode it in a different format and then a stream?
2
MJPEG Stream Header File
2
Registration of glass delivery time notification using the node
1
file upload using multer doesn't work completely (nodejs)
1
MJPEG (?) How smart is the browser?
0
How to post a jpeg image to Facebook me / staging_resources?
0
Use nodejs express to respond with an existing image file that the browser can cache?



All Articles
Loading...
X
Show
Funny
Dev
Pics