From 22c4c5ec3122c6ed8da804a7f016b0fce06269b0 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 17 May 2025 15:16:32 +0200 Subject: [PATCH] add camera compress --- ffmpeg/compress-camera.sh | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 ffmpeg/compress-camera.sh diff --git a/ffmpeg/compress-camera.sh b/ffmpeg/compress-camera.sh new file mode 100755 index 0000000..9b58255 --- /dev/null +++ b/ffmpeg/compress-camera.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +verify_commands() { + commands=("ffmpeg" "ffprobe") + for command in "${commands[@]}"; do + which $command &> /dev/null + if [ $? -ne 0 ]; then + echo "command '$command' not found" + exit 1 + fi + done +} + +main() { + verify_commands + + for arg in "$@"; do + for file in $(ls "$arg"); do + filename="${file%.*}" + extension="${file##*.}" + if [ "$extension" != "mp4" ]; then + echo "Invalid filetype: $file (expected mp4)" + continue + fi + + width=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=noprint_wrappers=1:nokey=1 "$file") + height=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=noprint_wrappers=1:nokey=1 "$file") + rotation=$(ffprobe -v error -select_streams v:0 -show_entries stream_side_data=rotation -of default=noprint_wrappers=1:nokey=1 "$file") + if [ "$rotation" -eq "90" ] || [ "$rotation" -eq "-90" ]; then + new_width=$height + new_height=$width + width=$new_width + height=$new_height + fi + + if [ "$width" -gt "$height" ]; then + width=1920 + height=-1 + else + width=-1 + height=1920 + fi + ffmpeg -i "$file" -vf scale="$width:$height" -c:v libsvtav1 -preset 4 -crf 23 -pix_fmt yuv420p10le -svtav1-params tune=0:film-grain=8 -c:a copy "${filename}_compressed.${extension}" + done + done +} + +main $@