Skip to content

Instantly share code, notes, and snippets.

@fand

fand/README.md Secret

Created October 17, 2025 08:29
Show Gist options
  • Select an option

  • Save fand/9339e85bdb9acdb40330edf9a442a289 to your computer and use it in GitHub Desktop.

Select an option

Save fand/9339e85bdb9acdb40330edf9a442a289 to your computer and use it in GitHub Desktop.
"Convert to mp4" from macOS context menu

"Convert to mp4" from macOS context menu

Screenshot 2025-10-17 at 1 26 21 AM

Setup

image
  1. Launch "Automator", then "New" > "Quick Action"
  2. "Workflow receives current files or folders in Finder"
  3. "Pass input: as arguments"
  4. Paste the content of convert_to_mp4.sh into the shell vie
  5. Save the workflow
#!/bin/bash
# Commands
FFMPEG="/opt/homebrew/bin/ffmpeg"
NOTIFY="/opt/homebrew/bin/terminal-notifier"
# Make sure PATH includes Homebrew
export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
# Ask user for scale
SCALE_INPUT=$(osascript -e 'display dialog "Enter scale (e.g. 1280:-1)\nLeave blank for original size:" default answer ""' -e 'text returned of result')
# Trim spaces (just in case)
SCALE_INPUT=$(echo "$SCALE_INPUT" | tr -d '[:space:]')
# Automatically fix odd-dimension issue: replace ":-1" with ":-2"
SAFE_SCALE=$(echo "$SCALE_INPUT" | sed 's/:-1$/:-2/')
last_out=""
# Process each selected file
for f in "$@"
do
dir=$(dirname "$f")
base=$(basename "$f")
name="${base%.*}"
if [ -z "$SAFE_SCALE" ]; then
# Original size
out="${dir}/${name}.mp4"
"$FFMPEG" -i "$f" \
-vcodec libx264 -pix_fmt yuv420p -crf 23 -preset medium \
-acodec aac -movflags +faststart \
"$out" 2> ~/Desktop/ffmpeg_error.log
else
# Custom scale
out="${dir}/${name}_$(echo "$SAFE_SCALE" | tr -d ":").mp4"
"$FFMPEG" -i "$f" \
-vf "scale=${SAFE_SCALE}" \
-vcodec libx264 -pix_fmt yuv420p -crf 23 -preset medium \
-acodec aac -movflags +faststart \
"$out" 2> ~/Desktop/ffmpeg_error.log
fi
last_out="$out"
done
# Notify user when finished
"$NOTIFY" \
-title "ffmpeg" \
-message "Conversion completed." \
-actions "Show" \
-execute "open -R \"$last_out\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment