I’m receiving an error in Automator “The action “Run Shell Script” encountered an error:”
My script works perfectly fine when running it in terminal and gives the exact outputs I need – the script selects the video in the folder: “yourvideo.mp4” and then extracts an image every 60 seconds (Theres also a variable script where I can specify the seconds if needed)
But when I run it through automator: “The action “Run Shell Script” encountered an error”
#!/bin/bash
# Input and output directories
INPUT_DIR="/Users/river/Content/FFMPEG/FFMPEG IN"
OUTPUT_DIR="/Users/river/Content/FFMPEG/FFMPEG Out"
# Default interval (seconds per image)
DEFAULT_INTERVAL=60
# Function to display usage information
usage() {
echo "Usage: $0 -v video_name [-i interval]"
echo " -v video_name Name of the video file in the input directory to process"
echo " -i interval Interval in seconds between each thumbnail (default is $DEFAULT_INTERVAL seconds)"
exit 1
}
# Parse command-line arguments
while getopts ":v:i:" opt; do
case $opt in
v) VIDEO_NAME="$OPTARG"
;;
i) INTERVAL="$OPTARG"
;;
*) usage
;;
esac
done
# Ensure the video name is provided
if [ -z "$VIDEO_NAME" ]; then
usage
fi
# Set interval to default if not specified
if [ -z "$INTERVAL" ]; then
INTERVAL=$DEFAULT_INTERVAL
fi
# Check if the specified video exists in the input directory
VIDEO_PATH="$INPUT_DIR/$VIDEO_NAME"
if [ ! -f "$VIDEO_PATH" ]; then
echo "Error: Video file '$VIDEO_NAME' not found in the input directory."
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Get the base name of the video file (without extension)
BASE_NAME=$(basename "$VIDEO_PATH" | sed 's/.[^.]*$//')
# Create a subdirectory in the output directory with the video file's name
VIDEO_OUTPUT_DIR="$OUTPUT_DIR/$BASE_NAME"
mkdir -p "$VIDEO_OUTPUT_DIR"
# Generate thumbnails at the specified interval and save them as .png
ffmpeg -i "$VIDEO_PATH" -vf "fps=1/$INTERVAL,scale=iw:ih" "$VIDEO_OUTPUT_DIR/thumb%04d.png"
echo "Thumbnails for '$VIDEO_NAME' have been saved to '$VIDEO_OUTPUT_DIR'"
echo "Thumbnail generation complete."
I have checked the directories & file names are correct. I am very new to using Automator, so I dont know if I’m missing something completely…
Automator has full file access too.
Any help would be appreciated.
River Side is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.