How to convert video to GIF using FFmpeg

ffmpeggifvideo conversion

I installed FFmpeg on my XAMPP for converting stream of video to GIF images.

I used the below code but it doesn't work.

ffmpeg -ss 00:00:05.0 -t 00:00:10.0 -i input.wmv -acodec copy -vcodec copy -async 1 output.gif

Best Answer

Your problem is: You cannot simply copy the input video and audio streams to a GIF. GIFs need to be encoded differently. Basically you're telling FFmpeg to actually not convert anything.

Try this instead:

ffmpeg -ss 5 -i input.wmv -t 10 -pix_fmt rgb24 output.gif

Notes:

  • I shortened the timestamps. If you just need seconds, it's enough to specify those.
  • -t is an output option and should go between -i and your output file name.
  • GIFs need an RGB pixel format, which you have to specify as well.
  • You may need to downscale your video so the GIF doesn't become unnecessarily large. Try adding -filter:v "scale=-1:320" or similar to downscale the output to 320 pixels height (and adjust the width automatically (-1).

Tip: "It doesn't work" is not a specific enough problem description. Please always include the full, uncut FFmpeg command output when asking FFmpeg questions.

Related Question