#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: $0 <видео> [папка вывода]" } if [[ $# -lt 1 || $# -gt 2 ]]; then usage >&2 exit 2 fi input="$1" out_dir="${2:-stabilized}" command -v ffmpeg >/dev/null 2>&1 || { echo "Не найден ffmpeg" >&2; exit 1; } [[ -f "$input" ]] || { echo "Файл не найден: $input" >&2; exit 1; } if ! ffmpeg -hide_banner -filters 2>/dev/null | grep -q "vidstabdetect"; then echo "В этой сборке FFmpeg нет libvidstab. Установите полную сборку." >&2 exit 1 fi mkdir -p "$out_dir" base="$(basename "${input%.*}")" output="$out_dir/${base}_stabilized.mp4" if [[ -e "$output" ]]; then echo "Файл уже существует: $output" >&2 exit 1 fi tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT transforms="$tmp/transforms.trf" echo "Первый проход: анализ движения" ffmpeg -hide_banner -nostdin -i "$input" \ -vf "vidstabdetect=shakiness=5:accuracy=15:result=${transforms}" \ -f null - echo "Второй проход: стабилизация" ffmpeg -hide_banner -nostdin -i "$input" \ -vf "vidstabtransform=input=${transforms}:zoom=5:smoothing=30,unsharp=5:5:0.8:3:3:0.4" \ -c:v libx264 -preset medium -crf 20 -pix_fmt yuv420p \ -c:a aac -b:a 192k -movflags +faststart -n "$output" echo "Готово: $output"