swissspidy / media-experiments

WordPress media experiments
GNU General Public License v2.0
87 stars 1 forks source link

Evaluate libheif alternative #483

Open swissspidy opened 5 months ago

swissspidy commented 5 months ago

If we'd want to bundle the script with the project, then we might need to find a GPL 2.0 compatible alternative, to libheif-js

See https://www.gnu.org/licenses/gpl-faq.html#GPLStaticVsDynamic and https://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynamic

swissspidy commented 5 months ago

Related #322

swissspidy commented 4 months ago

Related: https://core.trac.wordpress.org/ticket/53645

Due to the license issue with libheif, using the server to convert images could be an alternative route. One could "upload" a HEIF image and get a JPEG in return, and then continue processing from there.

There is also https://github.com/nokiatech/heif/tree/gh-pages with a proprietary license

swissspidy commented 3 months ago

ffmpeg added some support for decoding still images, see https://trac.ffmpeg.org/ticket/6521 / https://github.com/FFmpeg/FFmpeg/commit/a0821345eb31b727d93c9c3ed7d74d2774c73afa

So this could be an alternative.

Caveat: only available in ffmpeg 7.0, while ffmpeg.wasm is still on 5.1.x

Related:

Could try forking https://github.com/ffmpegwasm/ffmpeg.wasm if this path is viable.

swissspidy commented 3 months ago

There is also https://github.com/dlemstra/magick-wasm but it's under Apache 2.0, so not compatible either

swissspidy commented 3 months ago

So I was very excited about https://github.com/FFmpeg/FFmpeg/commit/a0821345eb31b727d93c9c3ed7d74d2774c73afa as it was mentioned that it worked fine for all the still test images from Nokia.

I updated my ffmpeg to version 7.0.1 for testing and even forked ffmpeg.wasm to patch together a version running with ffmpeg v7. Both worked well for those test images

However, photos from my iPhone (both still images and live photos) didn't decode properly, or I'm simply using it wrong.

I've tried simple ffmpeg -i input.heic output.jpg but also the -man 0 option (stream selection) or -vframes 1 with no luck. Either I am getting like 50 small pieces of the whole image, or it is grayscale/super dark.


An alternative could perhaps be converting https://github.com/NeverMendel/heif-convert to wasm.

swissspidy commented 3 months ago

An alternative could perhaps be converting NeverMendel/heif-convert to wasm.

Briefly tried this with py2wasm and wasmer, but to no avail. Getting RuntimeError: indirect call type mismatch

Edit: also, heif-convert uses pollow, which in turn uses libheif, but they say the binaries are GPLv2, soo... 🤔 🤷

swissspidy commented 3 months ago

Also worth noting that the example apps at https://github.com/strukturag/libheif are distributed under MIT, so maybe that means those could be converted to WASM and used in a GPL context? 🤔

swissspidy commented 3 months ago

Closing for now in favor of #578

swissspidy commented 2 months ago

Reopening for visibility