Page 1 of 1
How to remove every second frame from an animated gif?
Posted: 2013-09-02T12:23:18-07:00
by hellocatfood
I have a video (avi) that I want to convert to an animated gif. ffmpeg/avconv does a bad job of doing it directly, so I instead convert it to a gif by first outputting each frame as a png and then converting back to gif using iamgemagick. The problem is that this results in a large gif in terms of file size. To solve this I want to "drop" every second or nth frame from the gif, either by skipping every image file when converting to a gif or by removing frames from a gif. How can I do this?
Re: How to remove every second frame from an animated gif?
Posted: 2013-09-02T13:37:01-07:00
by fmw42
As far as I know, IM has no special command to skip frames. It would be a nice addition for an enhancement.
You would most likely have to write a script loop to select the list of all the png images you wanted and then use the list as input for convert to make the gif animation.
However, I am surprised to hear that ffmpeg won't do that, simply by specifying some argument like frames per second to export from the video. However, I am not a expert using ffmpeg.
Perhaps one of the user's who has more experience with ffmpeg can help further.
Re: How to remove every second frame from an animated gif?
Posted: 2013-09-02T14:03:07-07:00
by hellocatfood
fmw42 wrote:As far as I know, IM has no special command to skip frames. You would most likely have to write a script loop to select the list of all the png images you wanted and then use the list as input for convert to make the gif animation.
However, I am surprised to hear that ffmpeg won't do that, simply by specifying some argument like frames per second to export from the video. However, I am not a expert using ffmpeg.
Perhaps one of the user's who has more experience with ffmpeg can help further.
ffmpeg/avconv can specify frame rate but it seems like it's not working when the output is pictures.
In the end I used a modified version of
this script
Code: Select all
#!/bin/bash
for file in *.avi
do
avconv -i $file image_%05d.png
cnt=0;
for file in image_*.png
do
let cnt=cnt+1;
if [ $cnt -eq 3 ]; //change this number to specify every nth file to delete
then rm $file;
cnt=0;
fi
done
convert image_*.png output.gif
done
Re: How to remove every second frame from an animated gif?
Posted: 2013-09-02T15:00:10-07:00
by snibgo
I think the usual way to skip frames with ffmpeg is by messing with framerates. Eg if the input is 60 fps and the output is 30 fps, every second frame will be dropped.
I've never used ffmpeg to create gif annimations, and don't know how well it works.
Re: How to remove every second frame from an animated gif?
Posted: 2013-09-02T17:59:39-07:00
by glennrp
Presuming you have included frame numbers in the names of the PNG files, just remove the odd ones before converting them
to GIF:
Re: How to remove every second frame from an animated gif?
Posted: 2013-09-29T19:27:06-07:00
by anthony
Now that is a neat and simple solution.
Afterwards you can also use some helper scripts "mv_reseq" (renamed "mv_renum" script) and "mv_perl" scripts to renumber and rename files. That will remove the 'gaps' in the counts you just removed.
The Scripts are in my personal software export
http://www.ict.griffith.edu.au/anthony/ ... /#mv_renum