3

I am trying to get individual frames of an animated webp file. However, the frames obtained in this way has different image sizes and some frames have alpha channels:

WebPData rawData = { webpData.data() , webpData.size() };
struct WebPDemuxer* dmuxer = WebPDemux(&rawData);

int frame_idx = 1;
WebPIterator iter;
uint8_t* decode_data;

while (true) {

    WebPDemuxGetFrame(dmuxer, frame_idx, &iter);

    decode_data = WebPDecodeBGRA(iter.fragment.bytes, iter.fragment.size, &width, &height);
    if (decode_data == NULL)
        break;

    //do something with decode_data

    WebPDemuxReleaseIterator(&iter);

    frame_idx++;
}

Is there a way to get the fully rendered frame(using cwebp) instead of the different sized images with alpha channels(like the coalesce option in imagemagick)?

  • Move the `int ret` and `uint8_t* decode_data` declarations out of the infinite loop. (and pick either `C` or `C++`. Either will work, but should only tag one. You've switched the code to `C` now, so probably want to remove the `C++` tag.) – ryyker Jun 20 '22 at 12:55
  • @ryyker I have now. I will ultimately make a c++ list of the images(and my actual code is in c++) for other purposes but that does not affect what I am asking for. –  Jun 20 '22 at 13:04
  • `WebPData rawData = { webpData.data() , webpData.size() };` I think forces you to stick with `C++`. passing functions as function arguments is not allow in this way. ([only function pointers can be passed as arguments](https://stackoverflow.com/q/9410/645128) in `C`) – ryyker Jun 20 '22 at 13:07
  • @ryyker yes that part is in c++ because at the beginning I copied all the binary content of a webp file into an std::vector of chars. The data() method returns the pointer to the first entry and the size() method gives the number of chars, as required in the initialisation of WebPData struct. I could have used a regular array but i took this shortcut because my code is in c++ anyway. I know this is unsafe because std::vector can be resized and relocated in memory but I am not concerned about that. –  Jun 20 '22 at 13:23
  • Also i tagged it as c because cwebp library is written in c. And i am asking for a method within cwebp that lets me get fully rendered individual frames. –  Jun 20 '22 at 13:33

0 Answers0