Slow WebP
I tried WebP to store 256x256 thumbnails. But it appears to be almost 15 times slower than PNG. 1800 thumbnails takes additional 8 to 12 seconds on SaveToStreamAs(ThumbStream, ifPNG), but over 110-120 seconds with SaveToStreamAs(ThumbStream, ifWebP). I tried to compile most recent version of llbwebp, which made little fast to those 110-120 seconds. It was even longer with older library from here. Is there any way to play with WebP settings?
if ThumbBitmap = nil then
ThumbBitmap := GetFileThumbnail(AFileName, AThumbWidth, AThumbHeight, BGRAPixelTransparent, True);
ThumbStream := TMemoryStream.Create;
try
...
ThumbBitmap.SaveToStreamAs(ThumbStream, ifWebP);
...
finally
ThumbStream.Free;
end;
Well, i managed with explicitly using a writer with lossy encoding, which support alpha channel as well. Much faster and smaller.
var
WriterWebP: TBGRAWriterWebP;
...
begin
...
ThumbStream := TMemoryStream.Create;
WriterWebP := TBGRAWriterWebP.Create;
try
...
WriterWebP.Lossless := False;
WriterWebP.QualityPercent := 60;
ThumbBitmap.SaveToStream(ThumbStream, WriterWebP);
...
finally
WriterWebP.Free;
ThumbStream.Free;
end;
...
end;
By the way, implementation is a little old. libwebp now support method and compression for lossless.
Hello @regs01
Thanks for popping by.
Indeed, WebP writer is by default lossless and with 100% quality. This way, it is as good as PNG to that regard. However, it is indeed a bit slow.
Creating your own writer is indeed a way to specify the quality. Good to know it is faster and suits the thumbnail generation.
Thanks for letting us know about additional parameters. I found the method parameter in WebPConfig the documentation (quality over speed trade-off from 0=fast-draft to 6=slower-better). I am not sure however what compression parameter is. Would you like to expand on that?
Regards