I am trying to encode a sequence of images generated in my c++ code into animated images to make viewing them easier. I picked webp and followed some code examples from the official document. I would not need to tune any parameters. As long as it is animated, it is great. The code (https://developers.google.com/speed/webp/docs/container-api) is like this:

WebPAnimEncoderOptions enc_options;
// Tune 'enc_options' as needed.
WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
while(<there are more frames>) {
  WebPConfig config;
  // Tune 'config' as needed.
  WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config);
WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
WebPAnimEncoderAssemble(enc, webp_data);

However, even though the input frames are double-checked and time stamp increasing, in my output file only the first frame is encoded. By setting

enc_options.verbose = true;

I see that only the first time WebPAnimEncoderAdd() ran did the coder warn my on converting YUV to rgba with loss. Am I following the wrong example or what?

Much appreciated.

1 Answers

Jason M On

This is likely what happened: only for the first time did WebPAnimEncoderAdd() triggered conversion from YUV to argb so the rgba values stays constant, even though the YUV values are changed later. To solve it, I set

frame.use_argb = true;



then copy in the argb bytes for each frame and it works now.