1

I know I can create a video from files in a folder like so:

ffmpeg -f image2 -i %*.png out.avi

But if the folder I am in have sub-folders can i use some sort of switch to read those image files in those sub-folders? At the moment I am having to copy these image files into 1 folder, create the video and then delete those copied image files. Which is time consuming .

Is there a way please?

Thanks

2
  • 1
    The image reader won't recurse folders. Instead of copying the images, create symlinks in one folder. Much faster. Or use the concat demuxer. See trac.ffmpeg.org/wiki/Slideshow#Concatdemuxer
    – Gyan
    Commented May 11, 2020 at 11:16
  • many thanks only had the time now to look at this:) Commented May 16, 2020 at 11:26

1 Answer 1

1

While you can go with the links approach, suggested by Gyan in the comments. You could also generate a list of files that you want to use for encoding, and then use -f concat. I have tried it with the following:

find . -name '*.jpeg' -exec echo "file '"{}"'" >> list.text \;
ffmpeg  -f concat -r 25 -safe 0 -i list.text -c:v libtheora -q:v 8 out.ogv

Let's take it apart.

First we generate the list of all the files matching '*.jpeg' name starting with the current directory ., we do not want to output that list as is, because ffmpeg for whatever reason cannot default to lines being files, and expects us to say it each and every line. So rather than my_image_001.jpeg we want file 'my_image_001.jpeg'. So we do a trick with the -exec of find piping the echo command into a file. list.text in this example.

Now we get to ffmpeg. You tell it that you wish to concatenate all of the files, by providing -f concat as the format of the file it is about to read. Note that you will need to specify the frame rate, since images do not have this at all. The -safe 0 is needed so that ffmpeg does not crash and burn with Unsafe file name error message. I believe that is because we are using paths relative to the current directory. It makes little sense, but you just need to do this. After this, the line is the same as if you were just re-encoding another video.

1
  • Thanks. Good to see an alternative. But I did follow the link from Gyan May and it offers a cleaner solution for my business case. Commented Dec 5, 2021 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.