Created
November 24, 2025 19:50
-
-
Save velrino/727891cfb3c0c06d9e69bbb469e375b3 to your computer and use it in GitHub Desktop.
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 | |
| # Script to convert videos (mainly .mov) to .mp4 with efficient compression | |
| # Usage: ./video.sh /path/to/video.mov | |
| # ./video.sh "/Users/velrino/Documents/screenshots/Screen Recording 2025-11-24 at 15.58.38.mov" | |
| # This script will: | |
| # - Convert video to H.264/AAC MP4 format | |
| # - Compress the file efficiently while maintaining good quality | |
| # - Save the output to ~/Documents/videos-ffmpeg/ | |
| # | |
| # Requirements: ffmpeg (install with: brew install ffmpeg) | |
| # Check if a file was provided | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <video_path>" | |
| echo "Example: $0 ~/Desktop/video.mov" | |
| exit 1 | |
| fi | |
| # Input file | |
| INPUT_FILE="$1" | |
| # Check if file exists | |
| if [ ! -f "$INPUT_FILE" ]; then | |
| echo "Error: File '$INPUT_FILE' not found!" | |
| exit 1 | |
| fi | |
| # Create output directory if it doesn't exist | |
| OUTPUT_DIR="$HOME/Documents/videos-ffmpeg" | |
| mkdir -p "$OUTPUT_DIR" | |
| # Extract filename without extension | |
| FILENAME=$(basename "$INPUT_FILE") | |
| FILENAME_NO_EXT="${FILENAME%.*}" | |
| # Output file | |
| OUTPUT_FILE="$OUTPUT_DIR/${FILENAME_NO_EXT}.mp4" | |
| # Check if ffmpeg is installed, if not, install it automatically | |
| if ! command -v ffmpeg &> /dev/null; then | |
| echo "β οΈ ffmpeg is not installed!" | |
| echo "π¦ Installing ffmpeg via Homebrew..." | |
| echo "" | |
| # Check if Homebrew is installed | |
| if ! command -v brew &> /dev/null; then | |
| echo "β Error: Homebrew is not installed!" | |
| echo "Please install Homebrew first: https://brew.sh" | |
| exit 1 | |
| fi | |
| # Install ffmpeg | |
| brew install ffmpeg | |
| # Check if installation was successful | |
| if ! command -v ffmpeg &> /dev/null; then | |
| echo "β Error: Failed to install ffmpeg!" | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "β ffmpeg installed successfully!" | |
| echo "" | |
| fi | |
| echo "" | |
| echo "π¬ Converting video..." | |
| echo "" | |
| echo "π₯ Input: $INPUT_FILE" | |
| echo "π¦ Output: $OUTPUT_FILE" | |
| echo "" | |
| echo "" | |
| # Convert video with optimized settings | |
| # -c:v libx264: H.264 codec (compatible and efficient) | |
| # -crf 23: quality (18-28, where 23 is great balance quality/size) | |
| # -preset slow: slower encoding but better compression | |
| # -c:a aac: AAC audio codec | |
| # -b:a 128k: audio bitrate 128kbps | |
| # -movflags +faststart: optimize for web streaming | |
| ffmpeg -i "$INPUT_FILE" \ | |
| -c:v libx264 \ | |
| -crf 23 \ | |
| -preset slow \ | |
| -c:a aac \ | |
| -b:a 128k \ | |
| -movflags +faststart \ | |
| "$OUTPUT_FILE" | |
| # Check if conversion was successful | |
| if [ $? -eq 0 ]; then | |
| echo "" | |
| echo "" | |
| echo "β Conversion completed successfully!" | |
| echo "" | |
| # Show file sizes | |
| ORIGINAL_SIZE=$(du -h "$INPUT_FILE" | cut -f1) | |
| NEW_SIZE=$(du -h "$OUTPUT_FILE" | cut -f1) | |
| echo "π Original size: $ORIGINAL_SIZE" | |
| echo "π New size: $NEW_SIZE" | |
| echo "π Location: $OUTPUT_FILE" | |
| echo "" | |
| else | |
| echo "" | |
| echo "β Error during conversion!" | |
| exit 1 | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start