Created
February 5, 2025 10:57
-
-
Save shalak/9c5517583f54dfc830ee20e2859bd893 to your computer and use it in GitHub Desktop.
MacOS script for converting MOV to MP4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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