Yahweasel / libav.js

This is a compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil, libswresample, and libswscale—for emscripten, and thus the web.
288 stars 18 forks source link

A complete example for browser use #8

Closed bil-ash closed 1 year ago

bil-ash commented 1 year ago

Please add a complete example for use of this library in the browser to play video. By complete, I mean- 1) The browser fetches a video file from a url(using xhr/fetch) and keeps it in memory. 2) The file is demuxed to get video and audio streams. 3) The streams are decoded and the decoded: i) video packets(RGB/RGBA) are displayed using html canvas ii)audio packets are played using webaudio

Ability to seek to a particular time would be an added bonus

Yahweasel commented 1 year ago

Although someone could make such a program out of libav.js, it would not be a simple or straightforward example to make; that would be a fairly sophisticated webapp using libav.js as a library, not a usage example. I'd be delighted to see that made, but won't be making it myself, as it would be a lot of work with no personal benefit. libav.js is a low-level en/decoding library, and has no functionality related to output.

I would suggest looking into uses of the WebCodecs API, as it has (some) output capability, and there's a libav.js-based polyfill of the WebCodecs API (also by me): https://github.com/ennuicastr/libavjs-webcodecs-polyfill

There are lots of examples of your steps one and two and the decoding part of three among the tests.

bil-ash commented 1 year ago

Thanks for pointing out to the appropriate examples. The example at https://github.com/ennuicastr/libavjs-webcodecs-polyfill/tree/master/samples/video-decoder-vp8-opus has almost everything that I need