3 ms·
I once did it for a closed-source CAM/CAE software. We wanted to generate high resolution and decent quality GIFs visualizing a progress of a numerical optimiza
by Const-me 1y ago
I once did it for a closed-source CAM/CAE software. We wanted to generate high resolution and decent quality GIFs visualizing a progress of a numerical optimization in a few hundred animation frames. I wasn’t able to find a library which would deliver both reasonable size and good quality, so I made my own.
The trickiest part wasn’t the encoder; it’s computing the palette from RGB images. To minimize the output file size, I wanted a single palette shared by all frames.
The key piece of research was in that sample code from early 90-s https://www.ece.mcmaster.ca/~xwu/cq.c https://www.ece.mcmaster.ca/~xwu/cq.c However, I had to rework it heavily because global variables and C language are too old school, also because FP32 precision is insufficient for the count of input pixels in my use case. 200 FullHD frames contain approximately 400M pixels, FP32 numbers don’t have the precision to accumulate that many of them. And the number is dangerously close to int32 limit, I have also upgraded the integer counters to int64.
- triknomeister 1y agoThis is very interesting that you did the visualization using a GIF. I have only generated mp4 videos for vidoes till now using ffmpeg and png images or through something equivalent. Was there any advantage of GIF that you found? Like may be it was easier to do on the fly or was just simple enough?
- Const-me 1y agoI believe the reason why management specifically asked for animated GIFs was compatibility. The GIF format is ancient and supported by everything, makes it trivial to share or embed these animation files. Ignoring the compatibility, modern video codecs like h264 or h265 are substantially better than animated GIFs, in terms of both size and quality. BTW I supported them as well. The only target platform of that software is modern versions of Windows. It only took couple pages of straightforward C++ because the OS includes a functional equivalent of libavcodec and libavformat libraries. Moreover, GPU drivers install and register the components to leverage the codecs implemented by hardware of these GPUs. The high-level API to encode compressed video files from a sequence of frames is MFCreateSinkWriterFromURL function.
- triknomeister 1y agoVery cool Thanks!