Created
September 12, 2025 16:01
-
-
Save senmu/597e15e3d216e95063c526fee655692b to your computer and use it in GitHub Desktop.
ffscale
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
| # A shell script that uses ffmpeg to shrink a video | |
| # Usage: ffscale filename.mp4 | |
| function ffscale() { | |
| if [ "$1" != "" ] | |
| then | |
| # Extract the file extension | |
| extension="${1##*.}" | |
| # Create a temporary file with the same extension (macOS/Linux compatible) | |
| temp_file=$(mktemp "/tmp/ffscale_XXXXXX.$extension") | |
| # Process the video to the temporary file | |
| ffmpeg -i "$1" -vf "scale=trunc(iw/3)*2:trunc(ih/3)*2" "$temp_file" | |
| # Check if ffmpeg succeeded | |
| if [ $? -eq 0 ]; then | |
| # Replace the original file with the processed one | |
| mv "$temp_file" "$1" | |
| echo "Successfully scaled and replaced: $1" | |
| else | |
| # Clean up temporary file if ffmpeg failed | |
| rm -f "$temp_file" | |
| echo "Error: Failed to process $1" | |
| return 1 | |
| fi | |
| else | |
| echo "Usage: ffscale filename.mp4" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment