dav1d.js icon indicating copy to clipboard operation
dav1d.js copied to clipboard

Maybe we can make an I-frame only version for AVIF?

Open wdhwg001 opened this issue 6 years ago • 1 comments

I think maybe it could be much smaller?

In comparison, the BPG's asm.js decoder(bpgdec8a.js) is only ~80KB gzipped.

wdhwg001 avatar Apr 01 '19 19:04 wdhwg001

Hi! Thank you for your interest.

dav1d.wasm currently takes ~150kb gzipped:

$ gzip -c dav1d.wasm | wc -c
154596
$ echo $((154596/1024))
150

And it's much easier and faster to parse WebAssembly binary format than JavaScript (asm.js), it was specially designed for that.

Though I agree that this might be improved. For example I'm using upstream LLVM WebAssembly backend instead of Emscripten's fastcomp backend and latter is known to produce a bit more compact code. Though upstream backend improves pretty fast (and even has experimental SIMD support) so we may get smaller size soon. Or try fastcomp backend. Also -Oz emcc option (optimize for size) gives size ~70kb smaller, but works 2 times slower in my tests. There're many things worth testing here.

Regarding I-frame only decoder: there were discussions about that on #dav1d IRC channel:

2019-03-17 18:57:15     j-b     Do we do a special version of dav1d for AVIF?
2019-03-17 19:00:38     BBB     if there's interest, it can certainly be done
2019-03-17 19:00:39     kagami  what means special? ifdefing out code not needed for still picture decoding?
2019-03-17 19:00:43     BBB     yes
2019-03-17 19:01:16     kagami  that might be useful for WASM port, in order to minimize build size

Emscripten should already do most of the work via dead code elimination process, but special support in dav1d's code may greatly help too.

Btw, have you seen avif.js polyfill? It uses decode capabilities of <video> element by default and fallbacks to dav1d.js if there is no support for AV1 codec in a browser. It's ~4kb tiny JS library.

Kagami avatar Apr 01 '19 20:04 Kagami