Slow GIF Generation
Posted: 2016-04-09T08:29:54-07:00
It appears this topic has come up before, so I apologize if I've missed the answer.
I have some code that decodes frames from an ffmpeg steam, loads them into a magickwand via ConstituteImage, calls OptimizeImageLayers, then OptimizeImageTransparency, and finally gets the bytes via GetImagesBlob. Some pseudocode:
Obviously most of the variable declarations are removed there, but the gist is hopefully clear. In the preceding case adding 100 frames takes about 400ms (this includes some decode time and memory copying so I'm not worried about that), optimizing layers ~250ms, optimizing transparency ~350ms, and getting the bytes via MagickGetImagesBlob ~2s. These numbers can vary quite a bit depending on what 100 frames are provided. I've seen the final step take > 3s.
Is there any way to speed this up without compromising quality (or at least not compromising it significantly)? I believe much of the time is spent quantizing the images, but it's unclear to me if there's a better way to do this.
As an aside, does anyone know if this code generates a global color palette or one per frame?
Thanks!
Edit: I forgot to mention I'm using the latest imagemagick compiled from source (6.9.3-7) Q16 no HDRI with OpenMP enabled. The numbers are from a 10 core Xeon server I'm using for testing.
I have some code that decodes frames from an ffmpeg steam, loads them into a magickwand via ConstituteImage, calls OptimizeImageLayers, then OptimizeImageTransparency, and finally gets the bytes via GetImagesBlob. Some pseudocode:
Code: Select all
mw = NewMagickWand()
for(i=0;i < frameCount;i++) {
MagickConstituteImage(mw, cols, rows, cspmap, stype, ptr)
MagickSetImageFuzz(mw, fuzz)
MagickSetImageDelay(mw, delay)
}
mw = MagickOptimizeImageLayers(mw)
MagickOptimizeImageTransparency(mw)
MagickSetImageFormat(mw, "gif")
data = MagickGetImagesBlob(mw, &clen)
Is there any way to speed this up without compromising quality (or at least not compromising it significantly)? I believe much of the time is spent quantizing the images, but it's unclear to me if there's a better way to do this.
As an aside, does anyone know if this code generates a global color palette or one per frame?
Thanks!
Edit: I forgot to mention I'm using the latest imagemagick compiled from source (6.9.3-7) Q16 no HDRI with OpenMP enabled. The numbers are from a 10 core Xeon server I'm using for testing.