Created
July 10, 2025 20:33
-
-
Save DeedleFake/26a515a0184963d568a9fee30993885e to your computer and use it in GitHub Desktop.
A script to convert an MP4 to an upscaled WebP file. Script was originally generated by Grok 4 and then tweaked slightly.
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 | |
| # Prerequisites: | |
| # - ffmpeg and ffprobe installed (for video processing). | |
| # - upscayl-ncsnn installed (for upscaling). | |
| # Ensure it's in your PATH or adjust the command below. | |
| # - Models optionally downloaded into a 'models' directory in the current working directory (or adjust -m option). | |
| # | |
| # Usage: ./script.sh input.mp4 output.webp [scale] [model] | |
| # - scale: Upscale factor (default: 4, can be 2, 3, or 4). | |
| # - model: Model name. | |
| # | |
| # Note: This script creates temporary directories 'frames' and 'upscaled'. They are cleaned up at the end. | |
| # Adjust the number of threads (-j) or GPU (-g) in the upscale command if needed for performance. | |
| set -e | |
| input="$1" | |
| output="$2" | |
| scale="${3:-4}" | |
| model="${4:-realesrgan-x4plus}" | |
| if [ -z "$input" ] || [ -z "$output" ]; then | |
| echo "Usage: $0 input.mp4 output.webp [scale] [model]" | |
| exit 1 | |
| fi | |
| # Get the framerate of the input video | |
| fps=$(ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 "$input") | |
| # Create temporary directories | |
| mkdir -p frames upscaled | |
| # Extract frames from the MP4 | |
| ffmpeg -i "$input" frames/frame_%06d.png | |
| # Upscale each frame | |
| for file in frames/*.png; do | |
| base=$(basename "$file") | |
| upscayl -i "$file" -o "upscaled/$base" -s "$scale" -n "$model" -m models | |
| done | |
| # Convert upscaled frames to animated WebP | |
| ffmpeg -framerate "$fps" -i upscaled/frame_%06d.png -loop 0 -c:v libwebp -lossless 0 -quality 100 "$output" | |
| # Clean up temporary directories | |
| rm -rf frames upscaled | |
| echo "Processing complete. Output saved to $output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment