Skip to content

Instantly share code, notes, and snippets.

@ronggur
Last active May 27, 2025 14:10
Show Gist options
  • Select an option

  • Save ronggur/0cc418ea51714458f7011c94d8729b75 to your computer and use it in GitHub Desktop.

Select an option

Save ronggur/0cc418ea51714458f7011c94d8729b75 to your computer and use it in GitHub Desktop.
Video Upscaler and Enhancer Script
#!/bin/bash
# =========================================================
# Video Upscaler and Enhancer Script
# =========================================================
#
# Description:
# This script enhances and upscales video files using FFmpeg.
# It provides an interactive interface to customize various
# video processing parameters while maintaining quality.
#
# Usage:
# upscalevideo [input_video_file]
#
# Features:
# - Multiple resolution options (HD to 4K)
# - Quality control via CRF (Constant Rate Factor)
# - Various encoding speed presets
# - FPS control (original, 30fps, or 60fps)
# - Video enhancement filters:
# * Sharpening
# * Contrast enhancement
# * Denoising
# * Brightness and saturation adjustment
#
# Output:
# Creates an enhanced video with filename format:
# [original]_enhanced_[resolution]_[fps]_crf[value]_[preset].[ext]
#
# Requirements:
# - FFmpeg with libx264 support
# - Bash shell
# =========================================================
# Check input
if [ -z "$1" ]; then
echo "Usage: upscale-enhance [filename.mp4]"
exit 1
fi
INPUT="$1"
BASENAME=$(basename "$INPUT" | cut -d. -f1)
EXT="${INPUT##*.}"
# === SELECT RESOLUTION ===
echo "Select output resolution (aspect ratio will be maintained):"
echo "1) 1080x1920 (Full HD)"
echo "2) 720x1280 (HD)"
echo "3) 1440x2560 (2K)"
echo "4) 3840x2160 (4K)"
read -p "Choice [1-4]: " RES
case $RES in
1) OUT_W=1080; OUT_H=1920 ;;
2) OUT_W=720; OUT_H=1280 ;;
3) OUT_W=1440; OUT_H=2560 ;;
4) OUT_W=3840; OUT_H=2160 ;;
*) echo "Invalid choice."; exit 1 ;;
esac
# === SELECT QUALITY (CRF) ===
echo ""
echo "Select video quality (CRF - lower = better quality):"
echo "1) CRF 18 (High quality)"
echo "2) CRF 23 (Standard)"
echo "3) CRF 28 (Small size)"
read -p "Choice [1-3]: " Q
case $Q in
1) CRF=18 ;;
2) CRF=23 ;;
3) CRF=28 ;;
*) echo "Invalid choice."; exit 1 ;;
esac
# === SELECT ENCODING PRESET ===
echo ""
echo "Select encoding speed:"
echo "1) veryslow"
echo "2) slow"
echo "3) medium"
echo "4) fast"
echo "5) ultrafast"
read -p "Choice [1-5]: " P
case $P in
1) PRESET="veryslow" ;;
2) PRESET="slow" ;;
3) PRESET="medium" ;;
4) PRESET="fast" ;;
5) PRESET="ultrafast" ;;
*) echo "Invalid choice."; exit 1 ;;
esac
# === SELECT FPS ===
echo ""
echo "Select target FPS:"
echo "1) Keep original"
echo "2) Force to 30 FPS"
echo "3) Force to 60 FPS"
read -p "Choice [1-3]: " F
case $F in
1) FPS_FILTER="" ; FPS_LABEL="originalfps" ;;
2) FPS_FILTER="fps=30," ; FPS_LABEL="fps30" ;;
3) FPS_FILTER="fps=60," ; FPS_LABEL="fps60" ;;
*) echo "Invalid choice."; exit 1 ;;
esac
# === OUTPUT FILE NAME ===
OUTPUT="${BASENAME}_enhanced_${OUT_W}x${OUT_H}_${FPS_LABEL}_crf${CRF}_${PRESET}.$EXT"
# === RUN FFmpeg ===
echo ""
echo "Processing: $INPUT"
echo "Resolution: ${OUT_W}x${OUT_H}"
echo "CRF : $CRF"
echo "Preset : $PRESET"
echo "FPS : $FPS_LABEL"
echo "Output : $OUTPUT"
echo ""
ffmpeg -i "$INPUT" \
-vf "${FPS_FILTER}scale=${OUT_W}:${OUT_H}:force_original_aspect_ratio=increase,crop=${OUT_W}:${OUT_H},unsharp=5:5:1.0:5:5:0.0,eq=contrast=1.2:brightness=0.05:saturation=1.2,hqdn3d" \
-c:v libx264 -preset "$PRESET" -crf "$CRF" \
-c:a aac -b:a 192k \
"$OUTPUT"
echo ""
echo "✅ Done! File saved as:"
echo "$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment