#!/bin/bash set -euo pipefail if [ "$#" -ne 2 ]; then echo "Usage: $0 " echo "Example: $0 input.mp4 output.webm" exit 1 fi INPUT="$1" OUTPUT="$2" if [ ! -f "$INPUT" ]; then echo "Error: input file not found: $INPUT" exit 1 fi if [ "$INPUT" = "$OUTPUT" ]; then echo "Error: input and output must be different files" exit 1 fi EXT=$(printf '%s' "${OUTPUT##*.}" | tr '[:upper:]' '[:lower:]') case "$EXT" in mp4) ffmpeg -i "$INPUT" \ -c:v libx265 -crf 24 -preset medium \ -c:a aac -b:a 128k \ -movflags +faststart \ "$OUTPUT" ;; webm) ffmpeg -i "$INPUT" \ -c:v libvpx-vp9 -crf 32 -b:v 0 -deadline good -cpu-used 2 \ -c:a libopus -b:a 128k \ "$OUTPUT" ;; *) echo "Error: unsupported output format '.$EXT'" echo "Use output extension: .mp4 or .webm" exit 1 ;; esac