Frame animation to mp4

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
johnfl68
Posts: 33
Joined: 2012-07-09T18:31:26-07:00
Authentication code: 13

Frame animation to mp4

Post by johnfl68 »

Hello:

Can anyone provide any samples for converting a set of images to a mp4 using perl?

I am currently using ImageMagick in perl for some simple compositing.

What I am looking for, I have 5 PNG images, I want to display each for 1/2 second and hold on the last for 3 seconds.

I have not found any examples on animating and writing to a mp4.

Any help in pointing me in the right direction would be appreciated!

Thanks!

John
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Frame animation to mp4

Post by anthony »

Read all images into a single image list (actually a perl array in perlmagick), set delay on each image as you wish and save to mp4

I am not certain mp4 allows variable delays on each frame as GIF does, (not that familar with the format) but you can try.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
johnfl68
Posts: 33
Joined: 2012-07-09T18:31:26-07:00
Authentication code: 13

Re: Frame animation to mp4

Post by johnfl68 »

Well - for one I can't find any perl examples to even animate a gif, except for 1:

Code: Select all

#!/usr/bin/perl
use Image::Magick;

        $q = Image::Magick->new;
        $x = $q->Read("B1.png", "B2.png", "B3.png", "B4.png", "B5.png");
        warn "$x" if $x;


        $x = $q->Write("B.gif");
        warn "$x" if $x;
Which works, but I can't find any means of adding delay to that that will work.

And then, if I change the Write to "B.mp4" I get this:

Code: Select all

Exception 415: delegate failed `"ffmpeg" -v -1 -mbd rd -flags +4mv+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -pass 1/2 -i "%M%%d.jpg" "%u.%m" 2> "%Z"' @ error/delegate.c/InvokeDelegate/1061 at animate.pl line 10.
I need to be able to able to take a radar image sequence and convert to MPEG-2, MP4, or MOV, for a device that can play those, but not animated gif. And then script this to happen every 10 minutes via Cron.

I find it odd that ImageMagick is supposed to be able to do this, but nowhere on the web have I found any examples to do this, just lots of similar posts from people trying to do this, and getting similar errors.

Oh well, I will keep searching. Someone out there has to have done something like this and have it working.

John
johnfl68
Posts: 33
Joined: 2012-07-09T18:31:26-07:00
Authentication code: 13

Re: Frame animation to mp4

Post by johnfl68 »

Ok, a little farther.

I changed images to gif, and then could do command line convert of gifs to animated gif with delay.

Then I tried the same command line changing output to mov - and it chugged for a second and seemed to write a file, looked in directory, file with about the same size as animated gif, ok. But, quicktime wont play it, and VLC will play it, but it is all black. So why is it all black? Anyone know?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Frame animation to mp4

Post by fmw42 »

johnfl68 wrote:Ok, a little farther.

I changed images to gif, and then could do command line convert of gifs to animated gif with delay.

Then I tried the same command line changing output to mov - and it chugged for a second and seemed to write a file, looked in directory, file with about the same size as animated gif, ok. But, quicktime wont play it, and VLC will play it, but it is all black. So why is it all black? Anyone know?

I don't know much about Perlmagick or any API, but I think you cannot create an animation directly to any format other than gif. Then you need to take the gif and convert it to MOV or any other format. There was a similar question on the User's forum today about something similar going to MPEG (see viewtopic.php?f=1&t=21496&p=87972#p87965). I don't think IM can convert the animation properties to the output video format, probably just the images. The other person was able to convert to MPEG, but it did not loop. I suspect that one needs to either use the video delegate library or some other tool to convert animations. But again I am not an expert on this.

Have you tried (assuming on unix and you have FFMPEG installed),

convert -delay XX image1 image2 ... imageN -loop 0 GIF:- | convert - animation.mov

or

convert -delay XX image1 image2 ... imageN -loop 0 MIFF:- | convert - animation.mov

Does that work at all in command line?
strikeph
Posts: 1
Joined: 2012-09-13T09:56:22-07:00
Authentication code: 67789

Re: Frame animation to mp4

Post by strikeph »

I know it's low tech, but in this instance, what if you just added the last file six times for the 3 seconds? since it's the same file, you shouldn't see any change anyway.
Post Reply