Create a Macro or Workflow and apply to many files sequentially

Hello. A friend suggested I should try to solve my problem using KM. I downloaded the trial version, tried in many different ways, but did not manage any result. I also spent many hours searching the internet trying to try find out if Keyboard Maestro can do what I need. So I decided to post y problem here. I hope someone can give me some light.

What I am trying to automate the extraction of all frames from a list of hundreds of video file (.avi) using VLC. All video files have around 50 frames each and they are named sequentially (video001.avi video002.avi ....) . The workflow I need to create is as follows:

1- Open a file: video001.avi (for example) in VLC.
then VLC will automatically extract all frames from this clip and save them to a designated folder: /ClipFrames (for example). (this extraction takes about 5 seconds)
2- Move all frames from /ClipFrames to a newly created folder named video001 (same name as the file that was opened in VLC) So the new folder must be created and then all files from /ClipFrames should be moved there.
3- Open next file video002.avi in VLC
Repeat 2- and 3-

And so on for all files in that folder.

if I open all files sequentially, VLC will overwrite the frames with new ones from the new file. that's why I need to move them to a new folder before running the new file for frame extraction.

The result is that I will have A list of folders named as the video files (video001.avi video002.avi ....) and in each folder I will have all frames from each video.

Does anyone know if I can do this with Keyboard Maestro? Is it possible to do it without using applescript or javascript?

I hope I was not confusion and cream enough in my description. English is clearly not my mother language.

Thank you so much in advance.

I presume you mean video002.avi?

Yes, you can do this in Keyboard Maestro.

First, backup your computer, because if you are going to automate anything with files, you really really want to ensure you have solid backups.

Then:

  • use the For Each action and the Folder Contents collection to iterate through the folder of avi files.

  • use the Split Path action to get the extension and the basename.

  • use the If Then Else action and Variable condition to check that the extension is avi.

  • assuming it is, use the Open a File action to open the file in VLC.

  • Use the Pause action and pause long enough that all the frames are extracted. Perhaps 10 seconds? Maybe more. You can go have a coffee so it doesn't really matter if it is longer than necessary, but it will matter if it is too short.

  • Use the Move or Rename a File action to move the /ClipFrames folder to the target folder, using the basename you got from the Split Path above to set the name of the file (move /ClipFrames to /My/Folder/%Variable%Basename%).

  • If necessary, re-create the /ClipFrames folder - or maybe VLC creates it automatically in which case you might not need to create it.

Something like that.

Are you set on using VLC for some reason (other than it has a graphical user interface)? Because ffmpeg will do this job quicker and, generally, better than VLC. Yes, you'll have to use the command line or a KM "Execute Shell Script" action, but it's only one command into which you can plug in your source file and destination folder.

Plus there's plenty of example macros on the Forum that use ffmpeg :wink:

1 Like

Thank you so much! I will definitely try that an will get back to you.

HI. I am using VLC because it was how I managed to extract the files. I tried using ffmpeg but for some reason it didn't work. This .avi files I need to extract frames from don't open on QuickTime because of its codec I imagine. Maybe that's why it is not working? I should try extracting frames from a files that I can open on QuickTime. I guess would be a good idea to insist more on making fame to work. Wi will do some more research on the forums and try some of the existing macros.

Really appreciate the help and directing me a better solution.

1 Like

I removed the answer here and added to the post

This is a followup to te original posI on top.

I finally had so time to work on this automation. I took Nigels_S suggestion and tried using ffmpeg. I did manage to extract all frames from one of the clips I have. It was very fast and also very simple to do it:
ffmpeg -I (origin path)/Foto4.avi (destination path)/frame%06d.png
All frames were extracted to the destination folder that was already created.

I Tried following the suggestion from peternlewis but I didn't manage to understand how to do it and after I while I gave up. Since I really think using ffmpeg is a better option I decided to start a new workflow for this macro: I first create folders based on the name of the files I want to extract the frames from. And after I run the ffmpeg Script to extract the frames to those newly created folders. Seams much simpler...

I have now 2 main issues:
1- How to write the ffmpeg script in the KM Shell script action? I read two of your posts on the matter. I think ffmpeg path in my machine is: /usr/local/bin/ffmpeg. I did used homebrew to install it, but when I use the command locate ffmpeg in terminal the path I get is: /usr/local/bin/ffmpeg
2- How to tell KM to apply the shell script actions to all files.... I am very lost at the moment.

I managed to create new folders based on the filenames I wish to extract the frames from. When I try to run the ffmpeg script it doesn't work.
so this original path:
fmpeg -i /Users/leopardi/Documents/Fernando\ Brisolla/Timelapse/AVIs\ 2/Foto\ (1).AVI /Users/leopardi/Documents/Fernando\ ffmpeg -I (origin path)/video001.avi (destination path)/frame%06d.pngBrisolla/Timelapse/Frames/frame%06d.png
Turned into this:
/usr/local/bin/ffmpeg -i "$KMVAR_local_/Users/leopardi/Documents/Fernando\ Brisolla/TimelapseTest/AVIs\ test/Foto4.AVI” "$KMVAR_local_/Users/leopardi/Documents/Fernando\ Brisolla/TimelapseTest/Frames/Foto4//frame%06d.png”

Can anyone see the mistakes I made, and there is maybe an easier and better approach to solve this?

I really appreciate any help.

I want to thank again Nigel_S and peternlewis!
Here is the Macro I have until now:
Make folder from File name and Run ffmpeg.kmmacros (23.2 KB)