#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: $0 <видео> [папка] [яркость] [контраст] [насыщенность] [гамма]" } if [[ $# -lt 1 || $# -gt 6 ]]; then usage >&2 exit 2 fi input="$1" out_dir="${2:-color}" brightness="${3:-0.03}" contrast="${4:-1.08}" saturation="${5:-1.1}" gamma="${6:-1.0}" command -v ffmpeg >/dev/null 2>&1 || { echo "Не найден ffmpeg" >&2; exit 1; } [[ -f "$input" ]] || { echo "Файл не найден: $input" >&2; exit 1; } is_number() { [[ "$1" =~ ^-?[0-9]+([.][0-9]+)?$ ]] } for value in "$brightness" "$contrast" "$saturation" "$gamma"; do if ! is_number "$value"; then echo "Неверное числовое значение: $value" >&2 exit 2 fi done mkdir -p "$out_dir" base="$(basename "${input%.*}")" output="$out_dir/${base}_color.mp4" if [[ -e "$output" ]]; then echo "Файл уже существует: $output" >&2 exit 1 fi echo "Коррекция: brightness=$brightness contrast=$contrast saturation=$saturation gamma=$gamma" ffmpeg -hide_banner -nostdin -i "$input" \ -vf "eq=brightness=${brightness}:contrast=${contrast}:saturation=${saturation}:gamma=${gamma}" \ -c:v libx264 -preset medium -crf 20 -pix_fmt yuv420p \ -c:a aac -b:a 192k -movflags +faststart -n "$output" echo "Готово: $output"