Skip to content

Instantly share code, notes, and snippets.

@shalak
Created February 5, 2025 10:57
Show Gist options
  • Save shalak/9c5517583f54dfc830ee20e2859bd893 to your computer and use it in GitHub Desktop.
Save shalak/9c5517583f54dfc830ee20e2859bd893 to your computer and use it in GitHub Desktop.
MacOS script for converting MOV to MP4
#!/bin/bash
LOG_FILE="$HOME/Library/Logs/mov_to_mp4.log"
# Function to log messages and send macOS notifications
log_and_notify() {
local message="$1"
local emoji="$2"
echo "$(date +'%Y-%m-%d %H:%M:%S') $emoji $message" | tee -a "$LOG_FILE"
osascript -e "display notification \"$message\" with title \"MOV to MP4 Converter\""
}
# Check if ffmpeg is available
FFMPEG_PATH=$(command -v ffmpeg || echo "/opt/homebrew/bin/ffmpeg")
if [ ! -x "$FFMPEG_PATH" ]; then
log_and_notify "🚨 Error: ffmpeg not found. Install it with: brew install ffmpeg" "🚨"
exit 1
fi
log_and_notify "πŸŽ₯ Using ffmpeg at: $FFMPEG_PATH" "πŸŽ₯"
# Process each input file
for f in "$@"; do
if [[ "$f" == *.mov ]]; then
output="${f%.mov}.mp4"
# Check if output file already exists
if [[ -f "$output" ]]; then
log_and_notify "⚠️ Error: File $(basename "$output") already exists. Skipping." "⚠️"
continue
fi
log_and_notify "🎬 Starting conversion: $(basename "$f") β†’ $(basename "$output")" "🎬"
if "$FFMPEG_PATH" -i "$f" -vcodec h264 -acodec aac "$output" >>"$LOG_FILE" 2>&1; then
log_and_notify "βœ… Success: $(basename "$output") created." "βœ…"
else
log_and_notify "❌ Error: Failed to convert $(basename "$f"). Check logs at: $LOG_FILE" "❌"
rm -f "$output" # Ensure we remove any broken output file
fi
else
log_and_notify "⚠️ Skipping non-MOV file: $(basename "$f")" "⚠️"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment