2

I have a (random selection) of JPG images that I want to use to make into an APNG animation using ffmpeg (to test the process). They are all the same dimensions (256x256). But I cannot seem to get the correct syntax to control the frame delay and loop control (to loop forever). Is it possible to set these parameters using ffmpeg when creating an APNG from a sequence of images? If so, can someone provide the proper syntax and/or show an example command? I have searched the ffmpeg documentation and cannot seem to find relevant syntax.

I can do the following, but it will not accept -delay nor -loop. I use Imagemagick to pipe in the images.

This works, but does not loop, and runs very fast.

magick lena.jpg mandril3.jpg monet2.jpg zelda1.jpg PNG:- | ffmpeg -i - x.apng

This gives errors about delay and/or loop:

magick lena.jpg mandril3.jpg monet2.jpg zelda1.jpg PNG:- | ffmpeg -i - -delay 1000 -loop -1 x.apng

I am also curious to know if it is possible to specify a sequence of images directly in ffmpeg as input without using ImageMagick.

Sorry, I am a relative novice with ffmpeg. I am using ffmpeg 4.2.1.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Fred, part of the answer is here... https://stackoverflow.com/a/43797017/2836621 – Mark Setchell Sep 23 '20 at 06:09
  • You can probably set the delay like this https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video but I'm not near anything I can test on. – Mark Setchell Sep 23 '20 at 06:45
  • Thanks `Mark`. The -plays works to control the looping. But the second link does not provide a valid method for doing the delay using `setpts`. – fmw42 Sep 23 '20 at 17:09
  • If you wish to loop, you can't pipe the images*. Use the demuxer method at https://trac.ffmpeg.org/wiki/Slideshow#Concatdemuxer. *technically, you can but it's memory consuming. – Gyan Sep 23 '20 at 18:17
  • `@Gyan` Thanks, but that is not what I want. But your link does tell me what to do for the delay -- use the input framerate. That works. – fmw42 Sep 23 '20 at 18:38

1 Answers1

5

Looping

You can set looping with the -plays output option. 0 is infinite, 1 is no loop, 2 will play twice, etc.

-plays is an option specific (aka a private option) for the APNG muxer. You can see private options for a specific muxer with ffmpeg -h muxer=apng. See What are all codecs and formats supported by FFmpeg? for more examples.

Another private option for APNG is -final_delay to force delay after the last frame. Accepts a value in seconds.

Providing images to ffmpeg

Image demuxer

The most common method is to use the image demuxer.

It accepts a numbered sequence such as image_001.png, image_002.png, etc:

ffmpeg -framerate 3 -i image_%03d.png -plays 0 output.apng

Or a glob (at least on Linux & macOS):

ffmpeg -framerate 1 -pattern_type glob -i "*.png" output.apng

Set delay/timing with the -framerate input option as shown in the examples above. This is a private option of the image demuxer.

Pipe

You can pipe the images to ffmpeg like you do in your question. Can be useful in combination with other tools to provide the order you prefer.

For example, using sort is helpful your image series uses natural/version numbering such as 1.png, 2.png, ..., 10.png, etc. Otherwise ffmpeg would order them as 1.png, 10.png, 2.png.

cat $(find . -name '*.png' -print | sort -V) | ffmpeg -framerate 1 -i - -plays 1 output.apng

Concat demuxer

Or use the concat demuxer if you want to provide a list of files. Each image can have its own duration.

  1. Create input.txt containing:

    file 'lena.jpg'
    duration 1
    file 'mandril3.jpg'
    duration 0.5
    file 'monet2.jpg'
    duration 3
    file 'zelda1.jpg'
    duration 2
    

    Duration value is in seconds.

  2. Concatenate:

    ffmpeg -f concat -i input.txt -plays 0 output.apng
    

If you omit duration, and want an even delay/timing between images you can use the -r input option. This example will play at 1 frame per second.

ffmpeg -r 1 -f concat -i input.txt -plays 0 output.apng

Also see FFmpeg Wiki: Concatenate.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • `@llogan`Thanks. The -framerate is what I wanted. I found that out myself as well, just before you posted. With regard to input file specification, how can I provide a list of images without using wild cards or piping, especially if the names and suffixes are different. Will ffmpeg permit a list of files in some way? – fmw42 Sep 23 '20 at 18:43
  • @fmw42 Another option is the concat demuxer as mentioned by Gyan. See updated answer. – llogan Sep 23 '20 at 22:48
  • Thanks all for your help. I think I have what I need using -framerate and -plays. – fmw42 Sep 23 '20 at 23:27
  • A good page for information about using image input is at https://trac.ffmpeg.org/wiki/Slideshow – fmw42 Sep 24 '20 at 00:01