How do I create an animated gif from still images (preferably with the command line)?












62















I want make a .gif animated picture from a given set of .jpg pictures.



I would prefer to do it from the command line, so command line tools would be very welcome.










share|improve this question




















  • 3





    Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

    – Wilf
    Jul 14 '15 at 11:48


















62















I want make a .gif animated picture from a given set of .jpg pictures.



I would prefer to do it from the command line, so command line tools would be very welcome.










share|improve this question




















  • 3





    Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

    – Wilf
    Jul 14 '15 at 11:48
















62












62








62


29






I want make a .gif animated picture from a given set of .jpg pictures.



I would prefer to do it from the command line, so command line tools would be very welcome.










share|improve this question
















I want make a .gif animated picture from a given set of .jpg pictures.



I would prefer to do it from the command line, so command line tools would be very welcome.







command-line image-processing gif






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 3 at 17:39









pomsky

31.4k1195128




31.4k1195128










asked Jul 14 '15 at 10:57









MaythuxMaythux

51.3k32171218




51.3k32171218








  • 3





    Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

    – Wilf
    Jul 14 '15 at 11:48
















  • 3





    Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

    – Wilf
    Jul 14 '15 at 11:48










3




3





Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

– Wilf
Jul 14 '15 at 11:48







Works, very memory hungry though. There are LOADs of potential dupes though:askubuntu.com/questions/648244/… askubuntu.com/questions/457351/… askubuntu.com/q/573712/178596 askubuntu.com/questions/566476/… askubuntu.com/questions/380875/… askubuntu.com/q/636149/178596

– Wilf
Jul 14 '15 at 11:48












6 Answers
6






active

oldest

votes


















71














You can use ImageMagick package. Install it using the command:



sudo apt-get install imagemagick


Now you can create a gif from number of pictures(jpg) using:



convert -delay 20 -loop 0 *.jpg myimage.gif





share|improve this answer





















  • 5





    Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

    – Léo Léopold Hertz 준영
    Aug 7 '16 at 11:23













  • Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Dec 23 '18 at 16:40











  • ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Dec 23 '18 at 17:48



















40














To complete @Maythux answer:



To avoid generating a very large file, you can use -resize option:



In my case, I have 4608x3456 images and the generated gif was more than 300M for 32 images



convert -resize 20% -delay 20 -loop 0 *.jpg myimage.gif


or



convert -resize 768x576 -delay 20 -loop 0 *.jpg myimage.gif


Take care of *.jpg



*.jpg sucks a bit when dealing with numeric values, you may generate a gif with unsorted pics.



$ ls|cat
21-33-26_1.jpg
21-33-26_10.jpg // <--- this one
21-33-26_2.jpg
21-33-26_3.jpg
21-33-26_4.jpg
21-33-26_5.jpg
21-33-26_6.jpg
21-33-26_7.jpg
21-33-26_8.jpg
21-33-26_9.jpg
21-33-28_1.jpg // <--- should be here
21-33-28_2.jpg
21-33-28_3.jpg
...


As the shots were taken very quickly (10/s) they all have the same modification time and you can't trick using ls -t for example. On ubuntu you can use ls -v instead, something like:



convert -resize 768x576 -delay 20 -loop 0 `ls -v` myimage.gif


Sorting numerically is quite tricky on Mac OS X though, I guess you'll need to build a custom script.






share|improve this answer



















  • 4





    You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

    – bigreddmachine
    Nov 28 '16 at 23:53






  • 2





    There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

    – tjt263
    Jan 23 '17 at 16:28













  • Some users might be interested in editing filenames with massren: github.com/laurent22/massren

    – Graham P Heath
    Nov 30 '17 at 22:09



















18














I don't have enough reputation to comment but instead of modifying file names you can use globbing to get your shell to expand file names



convert -resize 50% -delay 10 -loop 0 image_{0..99}.jpg output.gif





share|improve this answer

































    5














    GIMP



    You can easily do this with GIMP. First install it if it's not installed already with



    sudo apt-get install gimp


    Creating the gif



    From GIMP go to File -> Open as Layers to open all the png's on their own layer.



    Open as Layer



    From here you can perform edits on the layers and, once done, go to File -> Export As. From the dialog be sure to set the file type to GIF.



    Set file type to GIF



    From there you will go to the GIF export options. Tick the 'As Animation' option and set the parameters as required.



    GIF export options






    share|improve this answer

































      3














      You can use a program called convert included in the imagemagick package. It is command line driven, but very easy to use. Install it either through the software center, or go to a command prompt and type



      sudo apt-get install imagemagick


      Now to create the .gif.



      convert -delay 100  -size 100x100 xc:SkyBlue 
      -page +5+10 balloon.gif -page +35+30 medical.gif
      -page +62+50 present.gif -page +10+55 shading.gif
      -loop 0 animation.gif


      *Note the above example is straight from Image Magick Examples






      share|improve this answer


























      • How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

        – BH2017
        Apr 29 '14 at 0:55













      • @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

        – unutbu
        Dec 24 '18 at 0:22



















      1














      ffmeg solution + test data



      As of Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8, I have found that ffmpeg is much faster and uses much less memory.



      The simplest conversion command is:



      ffmpeg 
      -framerate 60
      -pattern_type glob
      -i '*.png'
      -r 15
      -vf scale=512:-1
      out.gif
      ;


      You can get my test data with:



      wget -O opengl-rotating-triangle.zip https://github.com/cirosantilli/media/blob/master/opengl-rotating-triangle.zip?raw=true
      unzip opengl-rotating-triangle.zip
      cd opengl-rotating-triangle




      The test data was generated with: https://stackoverflow.com/questions/3191978/how-to-use-glut-opengl-to-render-to-a-file/14324292#14324292 and contains 256 1024x1024 PNG images.



      The important ffmpeg options I want to highlight are:




      • -patter_type glob: convenient way to select images



      • -framerate 60: assume 60 FPS on input images, and output the same FPS.



        ffmpeg cannot know otherwise since no FPS data in images as in video formats.



        The 256 input frames take about 4 seconds to finish.



        -r 15: optional. Pick one every 4 images so reduce size (4 == 60 / 15).



        With it, identify out.gif says that the GIF contains only 64 frames.



        It still takes 4 seconds to play, so the delay is altered to make things match.



      • -vf scale=512:-1: optional. Set the width, scale height proportionally, usually to reduce size and save space.



      To get ImageMagick to work, I first had to modify its disk and memory limits at /etc/ImageMagick-6/policy.xml as explained at: https://superuser.com/questions/1178666/imagemagick-convert-quits-after-some-pages



      See also:




      • video from images: https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183

      • GIF from video: How to create an animated GIF from MP4 video via command line?


      ImageMagick vs ffmpeg benchmark



      I compared the commands:



      /usr/bin/time -v convert *.png -deconstruct -delay 1.6 out-convert.gif
      /usr/bin/time -v ffmpeg
      -framerate 60
      -pattern_type glob
      -i '*.png'
      out-ffmpeg.gif
      ;


      The commands were constructed to produce outputs that are as close as possible to make the comparison valid:




      • /usr/bin/time -v: used to find the maximum memory usage as explained at: https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process



      • -deconstruct: GIF images can contain just the minimal modified rectangle from the previous frame to make the GIF smaller.



        ffmpeg calculates those diffs by default, but ImageMagick does not, unless -deconstruct is used.



        You will basically want to use that option every time with ImageMagick.



        We can observe the difference with:



        identify out.gif


        With the compressed version, all frames have smaller sizes than the initial one, e.g.:



        out.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
        out.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
        out.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010


        In this example, the second frame is only 516x516 instead of the full 1024x1024, and is placed at an offset of 252+257. It therefore contains just the middle triangle.



        See also: how can I resize an animated GIF file using ImageMagick?



      • -delay: value that matches the 60FPS of ffmpeg. Should not matter for conversion performance, but I don't want to risk it.



      The output GIFs have about the same size and look visually identical.



      We get for ImageMagick:



      Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.16
      Maximum resident set size (kbytes): 2676856


      and for ffmpeg:



      Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.41
      Maximum resident set size (kbytes): 97172


      from which we see that:




      • ImageMagick used 2.6Gb of RAM and took about 1 minute

      • ffmpeg used 100Mb of RAM and took 4 seconds


      Test hardware: Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ, 32GB(16+16) DDR4 2400MHz SODIMM, 512GB SSD PCIe TLC OPAL2.






      share|improve this answer

























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f648244%2fhow-do-i-create-an-animated-gif-from-still-images-preferably-with-the-command-l%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        71














        You can use ImageMagick package. Install it using the command:



        sudo apt-get install imagemagick


        Now you can create a gif from number of pictures(jpg) using:



        convert -delay 20 -loop 0 *.jpg myimage.gif





        share|improve this answer





















        • 5





          Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

          – Léo Léopold Hertz 준영
          Aug 7 '16 at 11:23













        • Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 16:40











        • ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 17:48
















        71














        You can use ImageMagick package. Install it using the command:



        sudo apt-get install imagemagick


        Now you can create a gif from number of pictures(jpg) using:



        convert -delay 20 -loop 0 *.jpg myimage.gif





        share|improve this answer





















        • 5





          Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

          – Léo Léopold Hertz 준영
          Aug 7 '16 at 11:23













        • Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 16:40











        • ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 17:48














        71












        71








        71







        You can use ImageMagick package. Install it using the command:



        sudo apt-get install imagemagick


        Now you can create a gif from number of pictures(jpg) using:



        convert -delay 20 -loop 0 *.jpg myimage.gif





        share|improve this answer















        You can use ImageMagick package. Install it using the command:



        sudo apt-get install imagemagick


        Now you can create a gif from number of pictures(jpg) using:



        convert -delay 20 -loop 0 *.jpg myimage.gif






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 22 '15 at 7:32

























        answered Jul 14 '15 at 10:57









        MaythuxMaythux

        51.3k32171218




        51.3k32171218








        • 5





          Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

          – Léo Léopold Hertz 준영
          Aug 7 '16 at 11:23













        • Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 16:40











        • ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 17:48














        • 5





          Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

          – Léo Léopold Hertz 준영
          Aug 7 '16 at 11:23













        • Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 16:40











        • ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

          – Ciro Santilli 新疆改造中心 六四事件 法轮功
          Dec 23 '18 at 17:48








        5




        5





        Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

        – Léo Léopold Hertz 준영
        Aug 7 '16 at 11:23







        Please, include here how you resize the gif animation etc by 50%. Etc -resize 50%.

        – Léo Léopold Hertz 준영
        Aug 7 '16 at 11:23















        Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

        – Ciro Santilli 新疆改造中心 六四事件 法轮功
        Dec 23 '18 at 16:40





        Ubuntu 18.10 failed with "cache resources exhausted" for these images: github.com/cirosantilli/media/blob/master/… related: superuser.com/questions/1178666/…

        – Ciro Santilli 新疆改造中心 六四事件 法轮功
        Dec 23 '18 at 16:40













        ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

        – Ciro Santilli 新疆改造中心 六四事件 法轮功
        Dec 23 '18 at 17:48





        ImageMagick users will likely also want: -deconstruct. I have also found that ImageMagick is very memory hungry, see benchmarks: askubuntu.com/a/1102183/52975

        – Ciro Santilli 新疆改造中心 六四事件 法轮功
        Dec 23 '18 at 17:48













        40














        To complete @Maythux answer:



        To avoid generating a very large file, you can use -resize option:



        In my case, I have 4608x3456 images and the generated gif was more than 300M for 32 images



        convert -resize 20% -delay 20 -loop 0 *.jpg myimage.gif


        or



        convert -resize 768x576 -delay 20 -loop 0 *.jpg myimage.gif


        Take care of *.jpg



        *.jpg sucks a bit when dealing with numeric values, you may generate a gif with unsorted pics.



        $ ls|cat
        21-33-26_1.jpg
        21-33-26_10.jpg // <--- this one
        21-33-26_2.jpg
        21-33-26_3.jpg
        21-33-26_4.jpg
        21-33-26_5.jpg
        21-33-26_6.jpg
        21-33-26_7.jpg
        21-33-26_8.jpg
        21-33-26_9.jpg
        21-33-28_1.jpg // <--- should be here
        21-33-28_2.jpg
        21-33-28_3.jpg
        ...


        As the shots were taken very quickly (10/s) they all have the same modification time and you can't trick using ls -t for example. On ubuntu you can use ls -v instead, something like:



        convert -resize 768x576 -delay 20 -loop 0 `ls -v` myimage.gif


        Sorting numerically is quite tricky on Mac OS X though, I guess you'll need to build a custom script.






        share|improve this answer



















        • 4





          You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

          – bigreddmachine
          Nov 28 '16 at 23:53






        • 2





          There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

          – tjt263
          Jan 23 '17 at 16:28













        • Some users might be interested in editing filenames with massren: github.com/laurent22/massren

          – Graham P Heath
          Nov 30 '17 at 22:09
















        40














        To complete @Maythux answer:



        To avoid generating a very large file, you can use -resize option:



        In my case, I have 4608x3456 images and the generated gif was more than 300M for 32 images



        convert -resize 20% -delay 20 -loop 0 *.jpg myimage.gif


        or



        convert -resize 768x576 -delay 20 -loop 0 *.jpg myimage.gif


        Take care of *.jpg



        *.jpg sucks a bit when dealing with numeric values, you may generate a gif with unsorted pics.



        $ ls|cat
        21-33-26_1.jpg
        21-33-26_10.jpg // <--- this one
        21-33-26_2.jpg
        21-33-26_3.jpg
        21-33-26_4.jpg
        21-33-26_5.jpg
        21-33-26_6.jpg
        21-33-26_7.jpg
        21-33-26_8.jpg
        21-33-26_9.jpg
        21-33-28_1.jpg // <--- should be here
        21-33-28_2.jpg
        21-33-28_3.jpg
        ...


        As the shots were taken very quickly (10/s) they all have the same modification time and you can't trick using ls -t for example. On ubuntu you can use ls -v instead, something like:



        convert -resize 768x576 -delay 20 -loop 0 `ls -v` myimage.gif


        Sorting numerically is quite tricky on Mac OS X though, I guess you'll need to build a custom script.






        share|improve this answer



















        • 4





          You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

          – bigreddmachine
          Nov 28 '16 at 23:53






        • 2





          There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

          – tjt263
          Jan 23 '17 at 16:28













        • Some users might be interested in editing filenames with massren: github.com/laurent22/massren

          – Graham P Heath
          Nov 30 '17 at 22:09














        40












        40








        40







        To complete @Maythux answer:



        To avoid generating a very large file, you can use -resize option:



        In my case, I have 4608x3456 images and the generated gif was more than 300M for 32 images



        convert -resize 20% -delay 20 -loop 0 *.jpg myimage.gif


        or



        convert -resize 768x576 -delay 20 -loop 0 *.jpg myimage.gif


        Take care of *.jpg



        *.jpg sucks a bit when dealing with numeric values, you may generate a gif with unsorted pics.



        $ ls|cat
        21-33-26_1.jpg
        21-33-26_10.jpg // <--- this one
        21-33-26_2.jpg
        21-33-26_3.jpg
        21-33-26_4.jpg
        21-33-26_5.jpg
        21-33-26_6.jpg
        21-33-26_7.jpg
        21-33-26_8.jpg
        21-33-26_9.jpg
        21-33-28_1.jpg // <--- should be here
        21-33-28_2.jpg
        21-33-28_3.jpg
        ...


        As the shots were taken very quickly (10/s) they all have the same modification time and you can't trick using ls -t for example. On ubuntu you can use ls -v instead, something like:



        convert -resize 768x576 -delay 20 -loop 0 `ls -v` myimage.gif


        Sorting numerically is quite tricky on Mac OS X though, I guess you'll need to build a custom script.






        share|improve this answer













        To complete @Maythux answer:



        To avoid generating a very large file, you can use -resize option:



        In my case, I have 4608x3456 images and the generated gif was more than 300M for 32 images



        convert -resize 20% -delay 20 -loop 0 *.jpg myimage.gif


        or



        convert -resize 768x576 -delay 20 -loop 0 *.jpg myimage.gif


        Take care of *.jpg



        *.jpg sucks a bit when dealing with numeric values, you may generate a gif with unsorted pics.



        $ ls|cat
        21-33-26_1.jpg
        21-33-26_10.jpg // <--- this one
        21-33-26_2.jpg
        21-33-26_3.jpg
        21-33-26_4.jpg
        21-33-26_5.jpg
        21-33-26_6.jpg
        21-33-26_7.jpg
        21-33-26_8.jpg
        21-33-26_9.jpg
        21-33-28_1.jpg // <--- should be here
        21-33-28_2.jpg
        21-33-28_3.jpg
        ...


        As the shots were taken very quickly (10/s) they all have the same modification time and you can't trick using ls -t for example. On ubuntu you can use ls -v instead, something like:



        convert -resize 768x576 -delay 20 -loop 0 `ls -v` myimage.gif


        Sorting numerically is quite tricky on Mac OS X though, I guess you'll need to build a custom script.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 16 '16 at 9:28









        NinsuoNinsuo

        56059




        56059








        • 4





          You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

          – bigreddmachine
          Nov 28 '16 at 23:53






        • 2





          There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

          – tjt263
          Jan 23 '17 at 16:28













        • Some users might be interested in editing filenames with massren: github.com/laurent22/massren

          – Graham P Heath
          Nov 30 '17 at 22:09














        • 4





          You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

          – bigreddmachine
          Nov 28 '16 at 23:53






        • 2





          There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

          – tjt263
          Jan 23 '17 at 16:28













        • Some users might be interested in editing filenames with massren: github.com/laurent22/massren

          – Graham P Heath
          Nov 30 '17 at 22:09








        4




        4





        You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

        – bigreddmachine
        Nov 28 '16 at 23:53





        You can avoid your *.jpg issue by forward padding numbers with zeros. "01.jpg" instead of "1.jpg", and so on. If you get to triple digits, then "001.jpg", "010.jpg", etc.

        – bigreddmachine
        Nov 28 '16 at 23:53




        2




        2





        There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

        – tjt263
        Jan 23 '17 at 16:28







        There are several ways around the filename sequence problem. Including find, sort, brace expansion, and so on. The ls tool is notoriously unsuitable for this kind of thing. Use find. There's a bit of a learning curve, but it's worth it.

        – tjt263
        Jan 23 '17 at 16:28















        Some users might be interested in editing filenames with massren: github.com/laurent22/massren

        – Graham P Heath
        Nov 30 '17 at 22:09





        Some users might be interested in editing filenames with massren: github.com/laurent22/massren

        – Graham P Heath
        Nov 30 '17 at 22:09











        18














        I don't have enough reputation to comment but instead of modifying file names you can use globbing to get your shell to expand file names



        convert -resize 50% -delay 10 -loop 0 image_{0..99}.jpg output.gif





        share|improve this answer






























          18














          I don't have enough reputation to comment but instead of modifying file names you can use globbing to get your shell to expand file names



          convert -resize 50% -delay 10 -loop 0 image_{0..99}.jpg output.gif





          share|improve this answer




























            18












            18








            18







            I don't have enough reputation to comment but instead of modifying file names you can use globbing to get your shell to expand file names



            convert -resize 50% -delay 10 -loop 0 image_{0..99}.jpg output.gif





            share|improve this answer















            I don't have enough reputation to comment but instead of modifying file names you can use globbing to get your shell to expand file names



            convert -resize 50% -delay 10 -loop 0 image_{0..99}.jpg output.gif






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 28 '17 at 5:51









            d a i s y

            3,35282444




            3,35282444










            answered Jul 27 '17 at 18:52









            shankskshanksk

            18113




            18113























                5














                GIMP



                You can easily do this with GIMP. First install it if it's not installed already with



                sudo apt-get install gimp


                Creating the gif



                From GIMP go to File -> Open as Layers to open all the png's on their own layer.



                Open as Layer



                From here you can perform edits on the layers and, once done, go to File -> Export As. From the dialog be sure to set the file type to GIF.



                Set file type to GIF



                From there you will go to the GIF export options. Tick the 'As Animation' option and set the parameters as required.



                GIF export options






                share|improve this answer






























                  5














                  GIMP



                  You can easily do this with GIMP. First install it if it's not installed already with



                  sudo apt-get install gimp


                  Creating the gif



                  From GIMP go to File -> Open as Layers to open all the png's on their own layer.



                  Open as Layer



                  From here you can perform edits on the layers and, once done, go to File -> Export As. From the dialog be sure to set the file type to GIF.



                  Set file type to GIF



                  From there you will go to the GIF export options. Tick the 'As Animation' option and set the parameters as required.



                  GIF export options






                  share|improve this answer




























                    5












                    5








                    5







                    GIMP



                    You can easily do this with GIMP. First install it if it's not installed already with



                    sudo apt-get install gimp


                    Creating the gif



                    From GIMP go to File -> Open as Layers to open all the png's on their own layer.



                    Open as Layer



                    From here you can perform edits on the layers and, once done, go to File -> Export As. From the dialog be sure to set the file type to GIF.



                    Set file type to GIF



                    From there you will go to the GIF export options. Tick the 'As Animation' option and set the parameters as required.



                    GIF export options






                    share|improve this answer















                    GIMP



                    You can easily do this with GIMP. First install it if it's not installed already with



                    sudo apt-get install gimp


                    Creating the gif



                    From GIMP go to File -> Open as Layers to open all the png's on their own layer.



                    Open as Layer



                    From here you can perform edits on the layers and, once done, go to File -> Export As. From the dialog be sure to set the file type to GIF.



                    Set file type to GIF



                    From there you will go to the GIF export options. Tick the 'As Animation' option and set the parameters as required.



                    GIF export options







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 3 at 16:02









                    pomsky

                    31.4k1195128




                    31.4k1195128










                    answered Apr 29 '14 at 4:53









                    chesedochesedo

                    1,3791022




                    1,3791022























                        3














                        You can use a program called convert included in the imagemagick package. It is command line driven, but very easy to use. Install it either through the software center, or go to a command prompt and type



                        sudo apt-get install imagemagick


                        Now to create the .gif.



                        convert -delay 100  -size 100x100 xc:SkyBlue 
                        -page +5+10 balloon.gif -page +35+30 medical.gif
                        -page +62+50 present.gif -page +10+55 shading.gif
                        -loop 0 animation.gif


                        *Note the above example is straight from Image Magick Examples






                        share|improve this answer


























                        • How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                          – BH2017
                          Apr 29 '14 at 0:55













                        • @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                          – unutbu
                          Dec 24 '18 at 0:22
















                        3














                        You can use a program called convert included in the imagemagick package. It is command line driven, but very easy to use. Install it either through the software center, or go to a command prompt and type



                        sudo apt-get install imagemagick


                        Now to create the .gif.



                        convert -delay 100  -size 100x100 xc:SkyBlue 
                        -page +5+10 balloon.gif -page +35+30 medical.gif
                        -page +62+50 present.gif -page +10+55 shading.gif
                        -loop 0 animation.gif


                        *Note the above example is straight from Image Magick Examples






                        share|improve this answer


























                        • How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                          – BH2017
                          Apr 29 '14 at 0:55













                        • @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                          – unutbu
                          Dec 24 '18 at 0:22














                        3












                        3








                        3







                        You can use a program called convert included in the imagemagick package. It is command line driven, but very easy to use. Install it either through the software center, or go to a command prompt and type



                        sudo apt-get install imagemagick


                        Now to create the .gif.



                        convert -delay 100  -size 100x100 xc:SkyBlue 
                        -page +5+10 balloon.gif -page +35+30 medical.gif
                        -page +62+50 present.gif -page +10+55 shading.gif
                        -loop 0 animation.gif


                        *Note the above example is straight from Image Magick Examples






                        share|improve this answer















                        You can use a program called convert included in the imagemagick package. It is command line driven, but very easy to use. Install it either through the software center, or go to a command prompt and type



                        sudo apt-get install imagemagick


                        Now to create the .gif.



                        convert -delay 100  -size 100x100 xc:SkyBlue 
                        -page +5+10 balloon.gif -page +35+30 medical.gif
                        -page +62+50 present.gif -page +10+55 shading.gif
                        -loop 0 animation.gif


                        *Note the above example is straight from Image Magick Examples







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 3 at 16:03









                        pomsky

                        31.4k1195128




                        31.4k1195128










                        answered Apr 29 '14 at 0:15









                        Scott GoodgameScott Goodgame

                        2,352820




                        2,352820













                        • How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                          – BH2017
                          Apr 29 '14 at 0:55













                        • @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                          – unutbu
                          Dec 24 '18 at 0:22



















                        • How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                          – BH2017
                          Apr 29 '14 at 0:55













                        • @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                          – unutbu
                          Dec 24 '18 at 0:22

















                        How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                        – BH2017
                        Apr 29 '14 at 0:55







                        How do I do 40 PNG images in a looping GIF? All in folder /home/fusion809/Documents/Images

                        – BH2017
                        Apr 29 '14 at 0:55















                        @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                        – unutbu
                        Dec 24 '18 at 0:22





                        @BH2017: convert -delay 20 -loop 0 *.png out.gif makes a looping GIF.

                        – unutbu
                        Dec 24 '18 at 0:22











                        1














                        ffmeg solution + test data



                        As of Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8, I have found that ffmpeg is much faster and uses much less memory.



                        The simplest conversion command is:



                        ffmpeg 
                        -framerate 60
                        -pattern_type glob
                        -i '*.png'
                        -r 15
                        -vf scale=512:-1
                        out.gif
                        ;


                        You can get my test data with:



                        wget -O opengl-rotating-triangle.zip https://github.com/cirosantilli/media/blob/master/opengl-rotating-triangle.zip?raw=true
                        unzip opengl-rotating-triangle.zip
                        cd opengl-rotating-triangle




                        The test data was generated with: https://stackoverflow.com/questions/3191978/how-to-use-glut-opengl-to-render-to-a-file/14324292#14324292 and contains 256 1024x1024 PNG images.



                        The important ffmpeg options I want to highlight are:




                        • -patter_type glob: convenient way to select images



                        • -framerate 60: assume 60 FPS on input images, and output the same FPS.



                          ffmpeg cannot know otherwise since no FPS data in images as in video formats.



                          The 256 input frames take about 4 seconds to finish.



                          -r 15: optional. Pick one every 4 images so reduce size (4 == 60 / 15).



                          With it, identify out.gif says that the GIF contains only 64 frames.



                          It still takes 4 seconds to play, so the delay is altered to make things match.



                        • -vf scale=512:-1: optional. Set the width, scale height proportionally, usually to reduce size and save space.



                        To get ImageMagick to work, I first had to modify its disk and memory limits at /etc/ImageMagick-6/policy.xml as explained at: https://superuser.com/questions/1178666/imagemagick-convert-quits-after-some-pages



                        See also:




                        • video from images: https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183

                        • GIF from video: How to create an animated GIF from MP4 video via command line?


                        ImageMagick vs ffmpeg benchmark



                        I compared the commands:



                        /usr/bin/time -v convert *.png -deconstruct -delay 1.6 out-convert.gif
                        /usr/bin/time -v ffmpeg
                        -framerate 60
                        -pattern_type glob
                        -i '*.png'
                        out-ffmpeg.gif
                        ;


                        The commands were constructed to produce outputs that are as close as possible to make the comparison valid:




                        • /usr/bin/time -v: used to find the maximum memory usage as explained at: https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process



                        • -deconstruct: GIF images can contain just the minimal modified rectangle from the previous frame to make the GIF smaller.



                          ffmpeg calculates those diffs by default, but ImageMagick does not, unless -deconstruct is used.



                          You will basically want to use that option every time with ImageMagick.



                          We can observe the difference with:



                          identify out.gif


                          With the compressed version, all frames have smaller sizes than the initial one, e.g.:



                          out.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                          out.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                          out.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010


                          In this example, the second frame is only 516x516 instead of the full 1024x1024, and is placed at an offset of 252+257. It therefore contains just the middle triangle.



                          See also: how can I resize an animated GIF file using ImageMagick?



                        • -delay: value that matches the 60FPS of ffmpeg. Should not matter for conversion performance, but I don't want to risk it.



                        The output GIFs have about the same size and look visually identical.



                        We get for ImageMagick:



                        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.16
                        Maximum resident set size (kbytes): 2676856


                        and for ffmpeg:



                        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.41
                        Maximum resident set size (kbytes): 97172


                        from which we see that:




                        • ImageMagick used 2.6Gb of RAM and took about 1 minute

                        • ffmpeg used 100Mb of RAM and took 4 seconds


                        Test hardware: Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ, 32GB(16+16) DDR4 2400MHz SODIMM, 512GB SSD PCIe TLC OPAL2.






                        share|improve this answer






























                          1














                          ffmeg solution + test data



                          As of Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8, I have found that ffmpeg is much faster and uses much less memory.



                          The simplest conversion command is:



                          ffmpeg 
                          -framerate 60
                          -pattern_type glob
                          -i '*.png'
                          -r 15
                          -vf scale=512:-1
                          out.gif
                          ;


                          You can get my test data with:



                          wget -O opengl-rotating-triangle.zip https://github.com/cirosantilli/media/blob/master/opengl-rotating-triangle.zip?raw=true
                          unzip opengl-rotating-triangle.zip
                          cd opengl-rotating-triangle




                          The test data was generated with: https://stackoverflow.com/questions/3191978/how-to-use-glut-opengl-to-render-to-a-file/14324292#14324292 and contains 256 1024x1024 PNG images.



                          The important ffmpeg options I want to highlight are:




                          • -patter_type glob: convenient way to select images



                          • -framerate 60: assume 60 FPS on input images, and output the same FPS.



                            ffmpeg cannot know otherwise since no FPS data in images as in video formats.



                            The 256 input frames take about 4 seconds to finish.



                            -r 15: optional. Pick one every 4 images so reduce size (4 == 60 / 15).



                            With it, identify out.gif says that the GIF contains only 64 frames.



                            It still takes 4 seconds to play, so the delay is altered to make things match.



                          • -vf scale=512:-1: optional. Set the width, scale height proportionally, usually to reduce size and save space.



                          To get ImageMagick to work, I first had to modify its disk and memory limits at /etc/ImageMagick-6/policy.xml as explained at: https://superuser.com/questions/1178666/imagemagick-convert-quits-after-some-pages



                          See also:




                          • video from images: https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183

                          • GIF from video: How to create an animated GIF from MP4 video via command line?


                          ImageMagick vs ffmpeg benchmark



                          I compared the commands:



                          /usr/bin/time -v convert *.png -deconstruct -delay 1.6 out-convert.gif
                          /usr/bin/time -v ffmpeg
                          -framerate 60
                          -pattern_type glob
                          -i '*.png'
                          out-ffmpeg.gif
                          ;


                          The commands were constructed to produce outputs that are as close as possible to make the comparison valid:




                          • /usr/bin/time -v: used to find the maximum memory usage as explained at: https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process



                          • -deconstruct: GIF images can contain just the minimal modified rectangle from the previous frame to make the GIF smaller.



                            ffmpeg calculates those diffs by default, but ImageMagick does not, unless -deconstruct is used.



                            You will basically want to use that option every time with ImageMagick.



                            We can observe the difference with:



                            identify out.gif


                            With the compressed version, all frames have smaller sizes than the initial one, e.g.:



                            out.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                            out.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                            out.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010


                            In this example, the second frame is only 516x516 instead of the full 1024x1024, and is placed at an offset of 252+257. It therefore contains just the middle triangle.



                            See also: how can I resize an animated GIF file using ImageMagick?



                          • -delay: value that matches the 60FPS of ffmpeg. Should not matter for conversion performance, but I don't want to risk it.



                          The output GIFs have about the same size and look visually identical.



                          We get for ImageMagick:



                          Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.16
                          Maximum resident set size (kbytes): 2676856


                          and for ffmpeg:



                          Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.41
                          Maximum resident set size (kbytes): 97172


                          from which we see that:




                          • ImageMagick used 2.6Gb of RAM and took about 1 minute

                          • ffmpeg used 100Mb of RAM and took 4 seconds


                          Test hardware: Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ, 32GB(16+16) DDR4 2400MHz SODIMM, 512GB SSD PCIe TLC OPAL2.






                          share|improve this answer




























                            1












                            1








                            1







                            ffmeg solution + test data



                            As of Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8, I have found that ffmpeg is much faster and uses much less memory.



                            The simplest conversion command is:



                            ffmpeg 
                            -framerate 60
                            -pattern_type glob
                            -i '*.png'
                            -r 15
                            -vf scale=512:-1
                            out.gif
                            ;


                            You can get my test data with:



                            wget -O opengl-rotating-triangle.zip https://github.com/cirosantilli/media/blob/master/opengl-rotating-triangle.zip?raw=true
                            unzip opengl-rotating-triangle.zip
                            cd opengl-rotating-triangle




                            The test data was generated with: https://stackoverflow.com/questions/3191978/how-to-use-glut-opengl-to-render-to-a-file/14324292#14324292 and contains 256 1024x1024 PNG images.



                            The important ffmpeg options I want to highlight are:




                            • -patter_type glob: convenient way to select images



                            • -framerate 60: assume 60 FPS on input images, and output the same FPS.



                              ffmpeg cannot know otherwise since no FPS data in images as in video formats.



                              The 256 input frames take about 4 seconds to finish.



                              -r 15: optional. Pick one every 4 images so reduce size (4 == 60 / 15).



                              With it, identify out.gif says that the GIF contains only 64 frames.



                              It still takes 4 seconds to play, so the delay is altered to make things match.



                            • -vf scale=512:-1: optional. Set the width, scale height proportionally, usually to reduce size and save space.



                            To get ImageMagick to work, I first had to modify its disk and memory limits at /etc/ImageMagick-6/policy.xml as explained at: https://superuser.com/questions/1178666/imagemagick-convert-quits-after-some-pages



                            See also:




                            • video from images: https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183

                            • GIF from video: How to create an animated GIF from MP4 video via command line?


                            ImageMagick vs ffmpeg benchmark



                            I compared the commands:



                            /usr/bin/time -v convert *.png -deconstruct -delay 1.6 out-convert.gif
                            /usr/bin/time -v ffmpeg
                            -framerate 60
                            -pattern_type glob
                            -i '*.png'
                            out-ffmpeg.gif
                            ;


                            The commands were constructed to produce outputs that are as close as possible to make the comparison valid:




                            • /usr/bin/time -v: used to find the maximum memory usage as explained at: https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process



                            • -deconstruct: GIF images can contain just the minimal modified rectangle from the previous frame to make the GIF smaller.



                              ffmpeg calculates those diffs by default, but ImageMagick does not, unless -deconstruct is used.



                              You will basically want to use that option every time with ImageMagick.



                              We can observe the difference with:



                              identify out.gif


                              With the compressed version, all frames have smaller sizes than the initial one, e.g.:



                              out.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                              out.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                              out.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010


                              In this example, the second frame is only 516x516 instead of the full 1024x1024, and is placed at an offset of 252+257. It therefore contains just the middle triangle.



                              See also: how can I resize an animated GIF file using ImageMagick?



                            • -delay: value that matches the 60FPS of ffmpeg. Should not matter for conversion performance, but I don't want to risk it.



                            The output GIFs have about the same size and look visually identical.



                            We get for ImageMagick:



                            Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.16
                            Maximum resident set size (kbytes): 2676856


                            and for ffmpeg:



                            Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.41
                            Maximum resident set size (kbytes): 97172


                            from which we see that:




                            • ImageMagick used 2.6Gb of RAM and took about 1 minute

                            • ffmpeg used 100Mb of RAM and took 4 seconds


                            Test hardware: Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ, 32GB(16+16) DDR4 2400MHz SODIMM, 512GB SSD PCIe TLC OPAL2.






                            share|improve this answer















                            ffmeg solution + test data



                            As of Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8, I have found that ffmpeg is much faster and uses much less memory.



                            The simplest conversion command is:



                            ffmpeg 
                            -framerate 60
                            -pattern_type glob
                            -i '*.png'
                            -r 15
                            -vf scale=512:-1
                            out.gif
                            ;


                            You can get my test data with:



                            wget -O opengl-rotating-triangle.zip https://github.com/cirosantilli/media/blob/master/opengl-rotating-triangle.zip?raw=true
                            unzip opengl-rotating-triangle.zip
                            cd opengl-rotating-triangle




                            The test data was generated with: https://stackoverflow.com/questions/3191978/how-to-use-glut-opengl-to-render-to-a-file/14324292#14324292 and contains 256 1024x1024 PNG images.



                            The important ffmpeg options I want to highlight are:




                            • -patter_type glob: convenient way to select images



                            • -framerate 60: assume 60 FPS on input images, and output the same FPS.



                              ffmpeg cannot know otherwise since no FPS data in images as in video formats.



                              The 256 input frames take about 4 seconds to finish.



                              -r 15: optional. Pick one every 4 images so reduce size (4 == 60 / 15).



                              With it, identify out.gif says that the GIF contains only 64 frames.



                              It still takes 4 seconds to play, so the delay is altered to make things match.



                            • -vf scale=512:-1: optional. Set the width, scale height proportionally, usually to reduce size and save space.



                            To get ImageMagick to work, I first had to modify its disk and memory limits at /etc/ImageMagick-6/policy.xml as explained at: https://superuser.com/questions/1178666/imagemagick-convert-quits-after-some-pages



                            See also:




                            • video from images: https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg/37478183#37478183

                            • GIF from video: How to create an animated GIF from MP4 video via command line?


                            ImageMagick vs ffmpeg benchmark



                            I compared the commands:



                            /usr/bin/time -v convert *.png -deconstruct -delay 1.6 out-convert.gif
                            /usr/bin/time -v ffmpeg
                            -framerate 60
                            -pattern_type glob
                            -i '*.png'
                            out-ffmpeg.gif
                            ;


                            The commands were constructed to produce outputs that are as close as possible to make the comparison valid:




                            • /usr/bin/time -v: used to find the maximum memory usage as explained at: https://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process



                            • -deconstruct: GIF images can contain just the minimal modified rectangle from the previous frame to make the GIF smaller.



                              ffmpeg calculates those diffs by default, but ImageMagick does not, unless -deconstruct is used.



                              You will basically want to use that option every time with ImageMagick.



                              We can observe the difference with:



                              identify out.gif


                              With the compressed version, all frames have smaller sizes than the initial one, e.g.:



                              out.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                              out.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010
                              out.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.010u 0:00.010


                              In this example, the second frame is only 516x516 instead of the full 1024x1024, and is placed at an offset of 252+257. It therefore contains just the middle triangle.



                              See also: how can I resize an animated GIF file using ImageMagick?



                            • -delay: value that matches the 60FPS of ffmpeg. Should not matter for conversion performance, but I don't want to risk it.



                            The output GIFs have about the same size and look visually identical.



                            We get for ImageMagick:



                            Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.16
                            Maximum resident set size (kbytes): 2676856


                            and for ffmpeg:



                            Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.41
                            Maximum resident set size (kbytes): 97172


                            from which we see that:




                            • ImageMagick used 2.6Gb of RAM and took about 1 minute

                            • ffmpeg used 100Mb of RAM and took 4 seconds


                            Test hardware: Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ, 32GB(16+16) DDR4 2400MHz SODIMM, 512GB SSD PCIe TLC OPAL2.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 23 '18 at 18:56

























                            answered Dec 15 '18 at 20:52









                            Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功

                            9,81944550




                            9,81944550






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f648244%2fhow-do-i-create-an-animated-gif-from-still-images-preferably-with-the-command-l%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                Mangá

                                Eduardo VII do Reino Unido