GIF vs WebP

Hi all,
Not sure if you can answer this, but I’m intrigued.
I’ve integrated Pixlet with my custom LED Matrix project. At the moment I’m rendering the apps to GIF and playing them on my LED panel, powered by an ESP32, using SmartMatrix and GifDecoder libraries.
I was wondering, are you guys using WebP instead of GIF to play the animations on the ESP32?
I couldn’t find any public library similar to GifDecoder/AnimatedGIF but for WebP. Did you develop your own library to do so?

It works pretty well using GIFs, but I guess WebP would reduce a bit the size of the images.

Thanks!

Yup, we’re using WebP, both because it’s smaller and sometimes faster to encode/decode. Another big reason though is that libwebp (the reference WebP implementation) is small, well-maintained, and easily portable. So we can use the same C library on the device and the server, and I’m much less worried about crashes or security vulnerabilities than with GIF’s.

1 Like

For the library, we’re actually just building libwebp without any changes whatsoever. Here’s the PlatformIO build configuration that we use in the firmware:

{
    "name": "libwebp",
    "build": {
        "srcFilter": [
            "+<src/**/*.c>"
        ],
        "includeDir": "libwebp/src",
        "srcDir": "libwebp",
        "unflags": [
            "-DHAVE_CONFIG_H"
        ]
    }
}

Basically, just build libwebp without the -DHAVE_CONFIG_H flag and you’re good to go!

Here’s an example of how to use the API to iterate through all the frames in a WebP, which you can then draw with SmartMatrix:

1 Like

Thanks @rohan! I’ll take a look to the libwebp library.

Hi @rohan,
I’ve been trying to implement libwebp into my project, using PlatformIO, but I can’t seem to be able to even build it. My firmware is arduino based, although I’ve tried using just espidf and have similar errors at linking time.

I understand this might go well beyond the purpose of this forum, so it’s ok if you can’t/won’t point me to the right direction.

I’m basically having this error (this is for arduino code, but espidf gives me similar undefined reference errors):

Compiling .pio/build/webp/src/main.cpp.o
Linking .pio/build/webp/firmware.elf
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x4): undefined reference to `WebPAnimDecoderOptionsInitInternal'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x8): undefined reference to `WebPAnimDecoderNewInternal'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0xc): undefined reference to `WebPAnimDecoderGetInfo'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x10): undefined reference to `WebPAnimDecoderHasMoreFrames'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x14): undefined reference to `WebPAnimDecoderGetNext'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x18): undefined reference to `WebPAnimDecoderReset'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x1c): undefined reference to `WebPAnimDecoderDelete'
.pio/build/webp/src/main.cpp.o: In function `testWebp()':
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderOptionsInitInternal'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderNewInternal'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderGetInfo'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderHasMoreFrames'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderGetNext'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderReset'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderDelete'
collect2: error: ld returned 1 exit status
*** [.pio/build/webp/firmware.elf] Error 1

my directory structure looks like:

test-webp
├── .pio
├── include
│   └── README
├── lib
│   ├── README
│   └── libwebp
│       ├── library.json
│       └── src
│           ├── Makefile.am
│           ├── dec
│           ├── demux
│           ├── dsp
│           ├── enc
│           ├── libwebp.pc.in
│           ├── libwebp.rc
│           ├── libwebpdecoder.pc.in
│           ├── libwebpdecoder.rc
│           ├── mux
│           ├── utils
│           └── webp
├── platformio.ini
├── src
│   └── main.cpp

The code is very simple and based on google’s example, as I just created a new project to try to get this working, before implementing in on my code.
library.json

{
    "name": "libwebp",
    "build": {
        "srcFilter": [
            "+<src/**/*.c>"
        ],
        "unflags": [
            "-DHAVE_CONFIG_H"
        ]
    }
}

I’m including demux.h

#include <webp/demux.h>

I’ve also tried including decode.h, and using extern "C" notation, but none of that made any difference

extern "C" {
    #include <webp/decode.h>
    #include <webp/demux.h>
}

Are you using any additional building scripts or configuration that I might be missing?

Any suggestions would be much appreciated.

Thanks!

Never mind, found the solution already!

Sorry I didn’t get back to you! Glad you have it working :slight_smile:

How is your project going ? I’m interesting writing my own firmware as well. Would you be willing to share your arduino based webp display code ?