This project provides a script (convert_video_to_gif.sh) designed to be used with macOS's Automator to automatically convert video files into animated GIFs when they are added to a specific folder.
The convert_video_to_gif.sh script is triggered by an Automator "Folder Action." When you drop a video file into the designated folder, the script:
- Converts the video to a GIF using
ffmpeg. - Places the resulting
.giffile into anoutputfolder. - Moves the original video file into a
processedfolder to prevent reprocessing. - Logs all its actions to a
conversion.logfile for easy debugging.
The folder structure is organized as follows:
input/: This is the folder you will set up the Automator Folder Action on. Drop your videos here.output/: Converted.giffiles are saved here.processed/: Original videos are moved here after successful conversion.conversion.log: A log file that records the script's activity.
You must have FFmpeg installed on your system. If you don't have it, you can install it using Homebrew:
brew install ffmpegFollow these steps carefully to set up the automated conversion.
Before setting up Automator, you need to ensure the script is correctly configured.
A. Make the script executable: Open your terminal, navigate to the project directory, and run the following command:
chmod +x convert_video_to_gif.shB. Verify the ffmpeg path:
The script needs to know the exact location of the ffmpeg executable. The script has been pre-configured with the path /opt/homebrew/bin/ffmpeg, which is common for Homebrew on Apple Silicon Macs.
To confirm this is correct for your system, run which ffmpeg in your terminal. If the output is different, open convert_video_to_gif.sh and update the FFMPEG_CMD variable with the correct path.
-
Open Automator (you can find it in your Applications folder or search with Spotlight).
-
Create a new document by selecting File > New.
-
Choose Folder Action as the document type.
-
At the top of the workflow window, click the dropdown menu next to "Folder Action receives files and folders added to" and select "Other...". Navigate to and choose the
inputfolder within this project directory. -
In the Actions library on the left, find the Run Shell Script action and drag it into the workflow area on the right.
-
In the Run Shell Script action box:
- Set the "Pass input" dropdown to "as arguments".
- Paste the following code into the text area. Make sure to replace
/path/to/your/project/with the actual absolute path to this project's folder.
# The project directory must be an absolute path PROJECT_DIR="/path/to/your/project/video-to-gif-folder" # Loop through each file dropped onto the folder for f in "$@" do # Execute the conversion script, passing the file path as an argument "$PROJECT_DIR/convert_video_to_gif.sh" "$f" done
-
Save the Folder Action. Give it a descriptive name, like "Video to GIF Converter".
Your automated workflow is now active. To test it, simply drag and drop a video file into the input folder. Within a few moments, you should see:
- A new
.giffile appear in theoutputfolder. - The original video file disappear from the
inputfolder and appear in theprocessedfolder. - The
conversion.logfile will be updated with the details of the conversion.
Before setting up the Automator action, you can test the script directly from your terminal to make sure it's working correctly. Navigate to the project directory and run:
./convert_video_to_gif.sh /path/to/your/video.mp4This is a great way to troubleshoot any issues with ffmpeg or the script itself. Check the conversion.log for detailed output.
This project was built with the help of the Gemini CLI (https://github.com/google-gemini/gemini-cli). If you need to modify the script, fix bugs, or add new features, you can use it for assistance.
