Best way to add gif over static image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Best way to add gif over static image

Post by agriz »

I haven't done the coding part yet.
Before that i want to confirm this.

I have one gif image with transparent background.
I have one static image.

The static image is bigger than the gif.
So, I plan to resize(tile) the gif to the size of static first and then i want to mingle them.

Is it good way to do it?
Later i want to convert that gif to mp4 using ffmpeg.

I am using ffmpeg to convert gif to mp4. But the movie is not running in the same speed of the gif. Is it possible to make it run in the same speed?

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Best way to add gif over static image

Post by snibgo »

Resize isn't the same as tiling.

I don't know if ffmpeg can read animated GIFs. I would do it as ...

Code: Select all

convert in.gif -coalesce frame_%03d.png
ffmepg -i frame_%03d.png -r 10 out.mp4
... where "10" is the desired framerate.
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Best way to add gif over static image

Post by agriz »

snibgo wrote:Resize isn't the same as tiling.

I don't know if ffmpeg can read animated GIFs. I would do it as ...

Code: Select all

convert in.gif -coalesce frame_%03d.png
ffmepg -i frame_%03d.png -r 10 out.mp4
... where "10" is the desired framerate.
How do i find the framerate of an gif image?

I found the scenes and delay time using identify function of imagemagick.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Best way to add gif over static image

Post by snibgo »

Add the delays to get the total duration. Calculate the average delay for a framerate.

GIF files don't have a steady framerate. To get an MP4 from a GIF, you should replicate frames as needed so each one is on screen for the same time. I don't know if ffmpeg can do this automatically. If not, you coud replicate frames with ImageMagick, in a suitable script.
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Best way to add gif over static image

Post by agriz »

snibgo wrote:Add the delays to get the total duration. Calculate the average delay for a framerate.

GIF files don't have a steady framerate. To get an MP4 from a GIF, you should replicate frames as needed so each one is on screen for the same time. I don't know if ffmpeg can do this automatically. If not, you coud replicate frames with ImageMagick, in a suitable script.

If there are 10 scenes and the delay is 5, i think the average is 5 after adding 5 for every scene.
(10 * 5) / 10 = 5

Did you mean something else. I didn't clearly get the point. It will be great to get any video format. Not just mp4.
The gif images are just 4 or 5 seconds in length. So after getting the mp4, I convert them to mpg and then i duplicate the mpg for 10 times and finally i convert them to mp4 to get some 30 sec or 1 min video. Is it the right way? Or will it work more better in other formats?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Best way to add gif over static image

Post by snibgo »

The delay is shown as {ticks}x{ticks-per-seconds}. See http://www.imagemagick.org/script/comma ... .php#delay

So "5x100" means 5 hundredths of a second, 0.05s. If all the frames have this delay, then you have a steady framerate, which is 100/5 = 20 frames per second.

ffmpeg can create mpg, mp4, avi or many other formats. mpg files can be directly concatenated:

Unix: cat x.mpg x.mpg x.mpg x.mpg x.mpg >x5.mpg
Windows: copy /B x.mpg+x.mpg+x.mpg+x.mpg+x.mpg x5.mpg
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Best way to add gif over static image

Post by agriz »

As i said, I am planning to use static image and one glitter to create animated image.
Using PHP GD, Using Imagemagick which is best in resource usage wise?

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Best way to add gif over static image

Post by snibgo »

I don't use PHP, and don't know what "GD" is. In general, using more tools (such as a web browser with PHP interpreter) will also use more resources.
snibgo's IM pages: im.snibgo.com
Post Reply