How do I batch convert a gif to apng using ffmpeg

842 Views Asked by At

How to I convert a gif to an animated png file without increasing the file size. When I convert the gif on ezgif it increases the files size. And what would be the for loop command that would convert multiple files? I have all the files in numerical file names.

1

There are 1 best solutions below

0
Michael Kruglos On

There isn't much you can do about file size increase. APNG files are going to be bigger than GIFs. That's the file format, and that's how it works.

The simplest way to convert a GIF to APNG using ffmpeg is to run the command ffmpeg -i input.gif output.apng.

If you want to do it in a loop you can use bash or any other shell or programming language.

Here's an example of converting all .gif files into .apng with bash and ffmpeg:

#!/usr/bin/env bash

for file in input*.gif
do
    ffmpeg -i $file ${file%.gif}.apng
done

If you have files with numeric names like input1.gif, input2.gif, ..., input100.gif you can use the following piece of code:

#!/usr/bin/env bash

for i in $(seq 1 100)
do
    ffmpeg -i "input$i.gif" "input$i.apng"
done