'ffmpeg wasm gif output size too big

I'm using "@ffmpeg/ffmpeg" for browsers with React, when I convert videos to GIF I'm getting too big file sizes.

Main problem is in web I cant optimize/compresss gif, so I need some methods to optimize output GIFs in browser.

Input Output
7.34 MB 29.55 MB
202.59 KB 1.21 MB
3.41 MB 52.04 MB

await ffmpeg.run(
  "-i",
  "video.mp4",
  "-vf",
  `fps=30,scale=640:360:flags=lanczos`,
  "video.gif",
);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source