Corion has asked for the wisdom of the Perl Monks concerning the following question:

In my latest side-project, I'm generating pretty animated pictures as a side effect. I want to show them off to a larger public, but publishing animated GIFs is somewhat disappointing as the GIFs are unreasonably large, weighing in at 10 MB or so.

I'm already using Prima and Imager or ScreenToGif to get the single frames for the animation, mostly as separate PNG images, and I'm looking for a good Perl API to combine the single frames into a .webm and .mp4 video to get vast gains of quality while vastly reducing file size at the same time. A quick test showed me a file size of 80kb for .webm with a file that was 7MB as a .gif.

Writing a script or module that runs ffmpeg over a set of frames is easy to do.

My main question is if there are known and used APIs for converting multiple still frames into an animation. Imager has the ->write_multi() API to write multiple frames to an animated .gif, and I could shim my "run-ffmpeg" module as another file type for Imager. But maybe there is a better API out there already?

What module do you use to combine multiple image frames into another file?

What module do you use to access single frames of a video?

Is somebody aware of ffmpeg as a statically linkable library so that instead of shelling out to ffmpeg, the black magic happens within Perl?

If there are no suggestions, I will likely try to implement the ffmpeg-writer as a filetype for Imager, much in the way that ImageMagick calls out to other modules.

Replies are listed 'Best First'.
Re: Searching for an API for writing sequential images into a file ("Movie")
by BrowserUk (Patriarch) on Nov 07, 2016 at 16:23 UTC
    Is somebody aware of ffmpeg as a statically linkable library so that instead of shelling out to ffmpeg, the black magic happens within Perl?

    I must admit I'm a little bemused by your desire to replace a well tried and tested executable with all the built-in logic to perform the gif-to-mpeg conversion -- things like a switches: to ensure the frame sizes are powers of two; adjust the bitrate and quality; choose the frequency of keyframes et al; -- in favour of a library that would probably require you re-create all that logic yourself.

    The ability to easily shell out to well tried and tested tools is one of Perl's great assets as far as I'm concerned.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Searching for an API for writing sequential images into a file ("Movie")
by pryrt (Abbot) on Nov 07, 2016 at 15:45 UTC
  • Alternate API: GD::Image::AnimatedGif; I doubt it's "better", especially given you already use Imager, but it's at least another API to consider...
  • this SO question has some info on static-linking of ffmpeg
Re: Searching for an API for writing sequential images into a file ("Movie")
by robby_dobby (Hermit) on Nov 07, 2016 at 13:10 UTC
    Hello Corion,

    I cannot tell if there are perl bindings for generating GIFs, but there's Gifshot from Yahoo! Sports and Giphy API. Not sure if these are what you are looking for. My cursory search on CPAN did not yield anything - you may well have some fun with these! :-)

      Yeah - I'm basically looking for pre-existing Perl APIs for local movie creation. I'm no fan of the cloud and cloud services and prefer to be self-reliant. But maybe the Giphy API is a module for another day, to provide automatic upload of new movies.