Convert mpg / mp4 to gif with ffmpeg
#include <stdio.h>
int main() {
const char *input_file = "input.mp4";
const char *output_file = "output.gif";
// Run ffmpeg command to convert mp4 to gif
char command[1000];
snprintf(command, sizeof(command), "ffmpeg -i %s -vf palettegen=stats_mode=diff -y palette.png", input_file);
system(command);
snprintf(command, sizeof(command), "ffmpeg -i %s -i palette.png -filter_complex paletteuse -y %s", input_file, output_file);
system(command);
return 0;
}