Last active
August 5, 2026 05:29
-
-
Save zoxon/121f6e58a4869127d7fe071ea85bb1ae to your computer and use it in GitHub Desktop.
Convert video for web
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 | |
| # Check if ffmpeg is installed | |
| if ! command -v ffmpeg &> /dev/null; then | |
| echo "Error: ffmpeg is not installed. Please install it using 'brew install ffmpeg'." | |
| exit 1 | |
| fi | |
| # Directories | |
| INPUT_DIR="." | |
| OUTPUT_DIR="./output" | |
| # Step 0: Create output folder | |
| mkdir -p "$OUTPUT_DIR" | |
| # Step 1: Loop through all video files (mp4, mov, mkv, avi) | |
| for file in "$INPUT_DIR"/*.{mp4,mov,mkv,avi}; do | |
| [ -e "$file" ] || continue # skip if no files | |
| filename=$(basename "$file") | |
| name="${filename%.*}" | |
| echo "Processing $filename ..." | |
| # Step 2: Convert to MP4 (H.264 + AAC) | |
| ffmpeg -i "$file" -c:v libx264 -preset slow -crf 26 -pix_fmt yuv420p \ | |
| -vf "scale='min(1920,iw)':-2" -movflags +faststart \ | |
| -c:a aac -b:a 96k "$OUTPUT_DIR/${name}.mp4" | |
| # Step 3: Convert to WebM (VP9 + Opus) | |
| ffmpeg -i "$file" -c:v libvpx-vp9 -b:v 0 -crf 32 -row-mt 1 -threads 8 -pix_fmt yuv420p \ | |
| -vf "scale='min(1920,iw)':-2" \ | |
| -c:a libopus -b:a 96k "$OUTPUT_DIR/${name}.webm" | |
| done | |
| echo "All videos processed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment