Terminal can generate video from PNG seguence (0001.png, 0002.png, …) via ffmpeg:
ffmpeg -i %04d.png -r 24 -codec prores output.mov
But how can I tell ffmpeg use for input image sequence in Automator? With this variable it's not working:
for f in "$@"
do
/opt/local/bin/ffmpeg -i "$f" -r 24 -codec prores ~/Desktop/output.mov
done
Looks like variable is for file than for sequence … Log list looks like script runs 10 times for sequence of 10 images. Error probably comes from second and all others loops where is asking for overwriting existing. I was able to create video only with full path to image sequence like ~/Desktop/PNG_Folder/%04d.png
, but thats not solution. Script was asking 9 times for overwriting anyway (skipping error with -y
hides error but keep loop process) and I need of course to use files selected from Finder, not specified in full path written in a script 🙂 Here is a screen of Automator just to be sure other things are set right. Thank you for help.
Plus: original Terminal command lets generate video into image sequence directory. Is this possible also with Automator's Shell? Also variable would be better if can be set for any file name and more formats than PNG (JPEG, EXR, …?) t be more versatile. Thank you.
Best Answer
After doing a bit of research, it turns out that the
-i
option forffmpeg
takes a single filename and when converting a number of image files to a .mov file, it has to be in the form of e.g.%05d.png
. Obviously the padding of the sequential numbering can be a different number of digits and the image type extension can vary as well.Then to that end, the following example
bash
code works for me:Method 1:
The following assumes the sequential numbered files are four digits, starting at
0001
, add all files have the same extension.It will process all four digit sequential numbered files in the same directory while overwriting the
output.mov
file, if it already exists.Change Service receives selected
files or folders
inFinder
to:Service receives selected
folders
inFinder
Remove the Get Selected Finder Items action,
Set Pass input: to
as arguments
in the Run Shell Script action.Replace the default code with the following example
bash
code:The example
bash
code above assumes you are selecting only one folder in Finder. For multiple folder selections, use the following examplebash
code:Note: The example
bash
code contains limited error handling. The onus is upon the user to add any error handling as may be appropriate, needed or wanted.Method 2:
Service receives selected
files or folders
inFinder
Remove the Get Selected Finder Items action,
Set Pass input: to
as arguments
in the Run Shell Script action.Assuming the selected image files in Finder are all the same type, in the same folder and the e.g.
output.mov
file will be created in the same folder of the selected image files...Then to that end, the following example
bash
code works for me:Note: The example
bash
code contains limited error handling. The onus is upon the user to add any error handling as may be appropriate, needed or wanted.Method 2 Notes:
output.mov
file already exists, an incremented filename is used, starting at, e.g.output 2.mov
and continuing to increment as needed so the Automator Service doesn't fail because the output file already exists. This is primarily handled in theif...else...then
block; however, the lines of code prior to it are a part of it as well./tmp
, named for the number of seconds since the Unix epoch, e.g./tmp/1574058046
and is handle byfoo="$(date +%s)"
andmkdir "/tmp/${foo}"
.for f in "$@"; do ... done
loop.ffmpeg
then creates the e.g.output.mov
file./tmp/1574058046
is removed.Note: The Get Specified Finder Items action is just for testing purposes and would be deleted before saving the Automator Service.