Page 1 of 1

MagickWand and Animation

Posted: 2006-02-25T14:56:05-07:00
by el_supremo
I've written a simple C program which uses MagickWand to convert 11 successive GIF images into a single animated GIF file. This is the code for the function which does that:

Code: Select all

#include <windows.h>
#include <wand/MagickWand.h>
#include "animate.h"

char *flist[] = {
"animate-00.gif",
"animate-01.gif",
"animate-02.gif",
"animate-03.gif",
"animate-04.gif",
"animate-05.gif",
"animate-06.gif",
"animate-07.gif",
"animate-08.gif",
"animate-09.gif",
"animate-10.gif",
// The list must end with a NULL pointer
NULL
};

MagickWand *mw,*rw;

void do_animation(void)
{
	char **ptr;
	//char temp[128];

	MagickWandGenesis();
	mw = NewMagickWand();

	for(ptr = flist;*ptr;ptr++) {
		rw = NewMagickWand();
		MagickReadImage(rw,*ptr);
		MagickSetImageDelay(rw,10);
		MagickAddImage(mw,rw);
		DestroyMagickWand(rw);
	}
	MagickWriteImages(mw,"animate.gif",MagickTrue);

	mw = DestroyMagickWand(mw);
	MagickWandTerminus();
}
This works fine when it outputs to animate.gif but I also tried an MPG file with "animate.mpg" and, although it called the mpeg2enc.exe program and produced its output in a Command Prompt window, the resulting output file is zero length. Although there are 11 frames, the command prompt window output from mpeg2enc goes up to something like 32 or 33 frames.
And since the GIF animation had worked, I also tried to convert it to an MPG with the command line:
convert animate.gif animate.mpg
and it produces the same results as my program, a zero length file.

Am I missing any MagickWand Incantations required to get an MPG?


Pete
[edit] I forgot to mention that each gif input image is 580x480 pixels.