Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I do some kind of real-time media decoding with JavaScript?

I have implemented an MJPEG/AVI1 parser which extracts JPEG-formatted frames from a MJPEG file.

I can draw an image with extracted JPEG file on DOM with <canvas> element and I can also export image pixel data from it with context.getImageData.

Can I make some kind of video stream and append those extracted data in real-time so that user can play it without long delay? I know I can manually make an <video>-like UI with <canvas> element, but I found that Media Source Extensions currently allows native <video> tag receive encoded byte stream format. I'm curious if I can do that with raw pixel data.

like image 280
Kagami Sascha Rosylight Avatar asked Feb 21 '14 18:02

Kagami Sascha Rosylight


1 Answers

That is an interesting idea.

So first, you need to create to mp4 initialization segment. From there you can convert the decoded jpg YUV frame to an h.264 frame. Then create a MSE fragment out of the frames. But you don't need to 'encode' to h.264, you can use raw slices, like what is outlined in this article.

http://www.cardinalpeak.com/blog/worlds-smallest-h-264-encoder/

THis should all be doable in javascript, in the browser, with enough work.

like image 50
szatmary Avatar answered Sep 27 '22 22:09

szatmary