#!/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:-presentation}" command -v ffmpeg >/dev/null 2>&1 || { echo "Не найден ffmpeg" >&2; exit 1; } command -v ffprobe >/dev/null 2>&1 || { echo "Не найден ffprobe" >&2; exit 1; } [[ -f "$input" ]] || { echo "Файл не найден: $input" >&2; exit 1; } width="$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$input" | head -n 1)" height="$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "$input" | head -n 1)" [[ "$width" =~ ^[0-9]+$ && "$height" =~ ^[0-9]+$ ]] || { echo "Не удалось определить размер кадра" >&2 exit 1 } mkdir -p "$out_dir" base="$(basename "${input%.*}")" output="$out_dir/${base}_slides.mp4" if [[ -e "$output" ]]; then echo "Файл уже существует: $output" >&2 exit 1 fi filters=() if (( width >= height )); then if (( width > 1920 )); then filters=(-vf "scale=1920:-2") fi else if (( height > 1920 )); then filters=(-vf "scale=-2:1920") fi fi echo "Версия для презентации: ${width}x${height}" ffmpeg -hide_banner -nostdin -i "$input" "${filters[@]}" \ -c:v libx264 -preset medium -crf 20 -profile:v high -level 4.2 \ -pix_fmt yuv420p -c:a aac -b:a 160k \ -movflags +faststart -n "$output" echo "Готово: $output"