What command would I use to convert an mp4 or mv4 video file to an animated gif, and vice versa. That is, convert a animated gif to a mp4 or mv4.
How to do I convert an animated gif to an mp4 or mv4 on the command line
conversionvideo
Related Solutions
You can use ffmpeg
to do this. There are several examples over on the ffmpeg website.
Here are a few of them:
This will create one thumbnail image every minute, named
img001.jpg
,img002.jpg
,img003.jpg
, ... (%03d
means that ordinal number of each thumbnail image should be formatted using 3 digits)$ ffmpeg -i myvideo.avi -f image2 -vf fps=fps=1/60 img%03d.jpg
This will create one thumbnail image every 10 minutes, named
thumb0001.bmp
,thumb0002.bmp
,thumb0003.bmp
, ...$ ffmpeg -i test.flv -f image2 -vf fps=fps=1/600 thumb%04d.bmp
If you want to make them into a short video you can again enlist the help of ffmpeg
. It's discussed on this page of their website.
Here are a few more examples:
Here, each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). By telling FFmpeg to set the input file's FPS option (frames per second) to some very low value, we made FFmpeg duplicate frames at the output and thus we achieved to display each image for some time on screen:
$ ffmpeg -f image2 -r 1/5 -i img%03d.png -c:v libx264 -r 30 out.mp4
If you don't have images numbered and ordered in series (
img001.jpg
,img002.jpg
,img003.jpg
) but rather random bunch of images, ffmpeg also supports bash-style globbing (* represents any number of any characters):$ ffmpeg -f image2 -r 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4
or for png images:
$ ffmpeg -f image2 -r 1 -pattern_type glob -i '*.png' -c:v libx264 out.mp4
To make the resulting video into an animated gif you could use the steps outlined int his SO Q&A titled: How to generate gif from avi using ffmpeg?:
$ ffmpeg -i video.avi -t 10 out%02d.gif
then:
$ gifsicle --delay=10 --loop *.gif > anim.gif
Here's the link to the tool gifsicle
.
You don't mention in your post if you've tried the most basic command that should accomplish this:
ffmpeg -i input.swf output.gif
Assuming that works there are going to be quality problems with it, because GIF is a 256-color format. (Imgur recently extended the file format for GIFV which uses WebM video, but that's a separate topic)
If that didn't work, it's because you don't have a SWF decoder or a GIF encoder. You can run this command to see what codecs/formats are supported by your version of FFMpeg:
ffmpeg -formats
The output of that is pretty verbose (it will list everything) and you can use grep
to cut it down for you:
ffmpeg -formats | grep -i GIF
ffmpeg -formats | grep -i SWF
For me I get this:
DE gif GIF Animation
E avm2 SWF (ShockWave Flash) (AVM2)
DE swf SWF (ShockWave Flash)
This shows that my version of FFMpeg supports decoding and encoding GIF and SWF.
You may also want to test converting it to an AVI before converting it to GIF, to see the quality before any GIF problems:
ffmpeg -i input.swf -sameq output.avi
It may get mad about trying to use the -sameq
flag because SWF doesn't have a "quality". You could also try -b:v 900k
to set the video bitrate to pretty high.
Update
The source you linked to can easily be compiled on any Linux system that has GCC and the "zlib" library (almost everything has that) Here is how I compiled it:
sudo apt-get install build-essential zlib-dev
wget -o main.c "http://svn.perian.org/ffmpeg/tools/cws2fws.c"
gcc main.c -lz
You can now run the tool to convert like this:
./a.out input.swf decompressed.swf
Cheers
Best Answer
Here's what worked for me:
movflags – This option optimizes the structure of the MP4 file so the browser can load it as quickly as possible.
pix_fmt – MP4 videos store pixels in different formats. We include this option to specify a specific format which has maximum compatibility across all browsers.
vf – MP4 videos using H.264 need to have a dimensions that are divisible by 2. This option ensures that’s the case.
Source: http://rigor.com/blog/2015/12/optimizing-animated-gifs-with-html5-video