aruntj / mjpeg-readable-stream

Code to read an Mjpeg stream using the Readable stream api.
MIT License
52 stars 13 forks source link

MJPEG.TYPE_JPEG #5

Open vegalou opened 2 years ago

vegalou commented 2 years ago

Thanks for your help on read MJPEG streaming in JS!!

Ran index.html, add basic auth and found a SMALL bug. (Line:72)

type: MJPEG.TYPE_JPEG

MIME description should be :

type: "video/x-motion-jpeg"

If there is basic authentication need, mod FETCH to:

fetch(url, {
    Authorization: "Basic "+btoa("YourName"+":"+"YourPass")
}).then(response => {

works in Firefox, but error shows in Chrome

net::ERR_FILE_NOT_FOUND

Thanks!

aiex718 commented 1 year ago

For the error net::ERR_FILE_NOT_FOUND in Chrome, I think it's because revokeObjectURL execute earlier than rendering image.

let frame = URL.createObjectURL(new Blob([imageBuffer])) 
image.src = frame;
URL.revokeObjectURL(frame)

Delay revoke seems resolve the issue.

let frame = URL.createObjectURL(new Blob([imageBuffer])) 
image.src = frame;
window.setTimeout(function () {
    URL.revokeObjectURL(frame)
}, 1000);