Technology Sharing

ffmpeg and imagemagick to create gif animation

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

from: https://blog.csdn.net/hufang360/article/details/107291163?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167876076516800186587476%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=167876076516800186587476&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogsobaiduend~default-1-107291163-null-null.blog_rank_default&utm_term=PNG%E5%BA%8F%E5%88%97%E5%90%88%E6%88%90gif&spm=1018.2226.3001.4450

1. NopngThe picture or image ispngFormat but without transparencypngpicture

ffmpegandimagemagickIt will be all right

ffmpeg -i %04d.png merge.gif 

or

ffmpeg -y -i %04d.png -r 12 -filter_complex "[0:v]split[a][b]; [a]palettegen=transparency_color=ffffff[p]; [b][p]paletteuse" merge.gif 

or

magick -delay 10 -loop 0 '*.png' -set dispose background +repage merge.gif 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

1. With transparent effectpngpicture

magick -delay 10 -loop 0 '*.png' -set dispose background +repage merge.gif
  • 1

This is a command using the ImageMagick tool to merge all PNG images in the current directory into a GIF animation. The specific parameters are explained as follows:

  • magick: Command-line tool for ImageMagick.
  • -delay 10: Sets the animation frame delay to 10 milliseconds.
  • -loop 0: Set the animation loop to infinite times.
  • '*.png': means all PNG files in the current directory.
  • -set dispose background: Sets the image processing method. When the animation frame is replaced, the background will be cleared.
  • +repage: Resize the image to fit the target dimensions, preserving the aspect ratio.
  • merge.gif: The output GIF animation file name.