Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

Looping back and forth through frames

Discussions about problems encountered using ffmpeg.
Forum rules
FFmpeg is in a state of perpetual development and we do not currently have the person power to backport fixes to official releases. As such, if you wish to query or report a bug, you must try with the latest development branch revision of FFmpeg to confirm the issue still exists. The latest FFmpeg can be downloaded from here: http://www.ffmpeg.org/download.html

Looping back and forth through frames

Postby supermichel » Fri May 19, 2017 8:49 am

Hi everyone,

I have a set of ten PNG frames that I'd like to convert to a "boomerang style" mp4 file (i.e go from frame 1 to frame 10, then from 9 to 2). I'd like to find something similar to ImageMagick's patrol cycle, but can't figure out how to to it with ffmpeg.

I thought it would be possible to do this using `concat` but :

- I think it's dirty
- My command simply does not work :)

Here's what I've used so far :

Code: Select all
-framerate 5 -i "concat:01.png|02.png|03.png|04.png|05.png|06.png|07.png|08.png|09.png|10.png|09.png|08.png|07.png|06.png|05.png|04.png|03.png|02.png" -pix_fmt yuv420p output.mp4


I get a video file but it just goes from 1 to 10 once.

Here's ffmpeg's saying hello :

Code: Select all
    ffmpeg version N-86098-g3fefaea Copyright (c) 2000-2017 the FFmpeg developers
   
      built with gcc 6.3.0 (GCC)
   
      configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
   
      libavutil      55. 63.100 / 55. 63.100
   
      libavcodec     57. 96.101 / 57. 96.101
   
      libavformat    57. 72.101 / 57. 72.101
   
      libavdevice    57.  7.100 / 57.  7.100
   
      libavfilter     6. 89.101 /  6. 89.101
   
      libswscale      4.  7.101 /  4.  7.101
   
      libswresample   2.  8.100 /  2.  8.100
   
      libpostproc    54.  6.100 / 54.  6.100


Anyone has an idea ?

Thanks :)
supermichel
 
Posts: 4
Joined: Mon Jul 04, 2016 10:56 am

Re: Looping back and forth through frames

Postby supermichel » Fri Jun 02, 2017 10:15 am

No one ?
supermichel
 
Posts: 4
Joined: Mon Jul 04, 2016 10:56 am

Re: Looping back and forth through frames

Postby mulvya » Sat Jun 03, 2017 7:42 am

If you want a telescoping sequence, template is

For a sequence with X frames:

Code: Select all
ffmpeg -i img%d.png -filter_complex "[0]reverse[r];[0][r]concat,loop=ceiling(X/2):2X:0,select='between(n,floor(n/X)*X+floor(n/X),floor(n/X)*X+X-1-floor(n/X))',setpts=N/FPS/TB" -r FPS telescoped.mp4


e.g. for a sequence with 10 frames, and final output at 5 fps, this is the substituted command to use

Code: Select all
ffmpeg -i img%d.png -filter_complex "[0]reverse[r];[0][r]concat,loop=5:20:0,select='between(n,floor(n/10)*10+floor(n/10),floor(n/10)*10+10-1-floor(n/10))',setpts=N/5/TB" -r 5 telescoped10.mp4


----------------------------

If you just want a full loop of Y times without doubled frames, template is

template is

Code: Select all
ffmpeg -i img%d.png -filter_complex "[0]trim=start_frame=1,reverse,trim=start_frame=1,setpts=N/25/TB[r];[0][r]concat,loop=Y-1:2X-2:0,setpts=N/5/TB" -r 5 patroloop.mp4


e.g. for a sequence with 10 frames, with 6 cycles and final output at 5 fps, this is the substituted command to use

Code: Select all
ffmpeg -i img%d.png -filter_complex "[0]trim=start_frame=1,reverse,trim=start_frame=1,setpts=N/25/TB[r];[0][r]concat,loop=5:18:0,setpts=N/5/TB" -r 5 patroloop10.mp4
mulvya
 
Posts: 565
Joined: Mon Oct 26, 2015 6:58 am

Re: Looping back and forth through frames

Postby supermichel » Tue Jun 06, 2017 1:04 pm

Works like a charm, thanks :)
supermichel
 
Posts: 4
Joined: Mon Jul 04, 2016 10:56 am


Return to ffmpeg

Who is online

Users browsing this forum: Bing [Bot] and 4 guests