ffmpegrenpy

FFMPEG images to video with reverse sequence with other filters


Similar to this ffmpeg - convert image sequence to video with reversed order

But I was wondering if I can create a video loop by specifying the image range and have the reverse order appended in one command.

Ideally I'd like to combine it with this Make an Alpha Mask video from PNG files

What I am doing now is generating the reverse using https://stackoverflow.com/a/43301451/242042 and combining the video files together.

However, I am thinking it would be similar to Concat a video with itself, but in reverse, using ffmpeg

My current attempt was assuming 60 images. which makes vframes x2

ffmpeg -y -framerate 20 -f image2 -i \
  running_gear/%04d.png -start_number 0 -vframes 120 \
  -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" \
  -filter_complex alphaextract[a]
  -map 0:v -b:v 5M -crf 20 running_gear.webm 
  -map [a] -b:v 5M -crf 20 running_gear-alpha.web

Without the alpha masking I can get it working using

ffmpeg -y -framerate 20 -f image2 -i running_gear/%04d.png \
  -start_number 0 -vframes 120 \
  -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" \
  -map "[v]" -b:v 5M -crf 20 running_gear.webm

With just the alpha masking I can do

ffmpeg -y -framerate 20 -f image2 -i running_gear/%04d.png \
  -start_number 0 -vframes 120 \
  -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [vc];[vc]alphaextract[a]"
  -map [a] -b:v 5M -crf 20 alpha.webm

So I am trying to do it so the alpha mask is done at the same time.

Although my ultimate ideal would be to take the images, reverse it get an alpha mask and put it side-by-side so it can be used in Ren'py


Solution

  • Got it after a few trial and error. Not really my ultimate desire but still works.

    ffmpeg -y -framerate 20 -f image2 -i running_gear/%04d.png \
      -start_number 0 -vframes 120 \
      -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [vc];[vc]split[v][av];[av]alphaextract[a]" 
      -map [v] -b:v 5M -crf 20 running_gear.webm 
      -map [a] -b:v 5M -crf 20 running_gear-alpha.webm
    

    After checking some of the other filters (after learning about it from concat) I found hstack so the one that can put it side-by-side so it works better with Ren'Py is.

    ffmpeg -y -framerate 20 -f image2 -i running_gear/%04d.png \
      -start_number 0 -vframes 120 \
      -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [vc];[vc]split[v][av];[av]alphaextract[a];[v][a]hstack[m]" 
      -map [m] -b:v 5M -crf 20 running_gear.webm