save as .sh and add to qbittorent settings to run after a torrent finishes.
It uses NVIDIA h264_nvenc codec, so you need a NVIDIA card for this to work.
#!/bin/bash
TARGET="$1"
OUTPUT_DIR="/path/to/converted_videos"
mkdir -p "$OUTPUT_DIR"
process_file() {
local input="$1"
local filename=$(basename "$input")
local filename_no_ext="${filename%.*}"
local output="$OUTPUT_DIR/${filename_no_ext}_480p.mp4"
if [ -f "$output" ]; then
echo "File already exists: $output"
return
fi
echo "Converting $input..."
ffmpeg -hwaccel auto -i "$input" \
-vf "scale=-2:480" \
-c:v h264_nvenc -pix_fmt yuv420p -preset medium -rc vbr -cq 23 \
-c:a aac -b:a 160k \
-movflags +faststart \
-y "$output"
}
if [ -d "$TARGET" ]; then
find "$TARGET" -type f \( -name "*.mkv" -o -name "*.avi" -o -name "*.mov" -o -name "*.mp4" -o -name "*.webm" \) | while read -r file; do
process_file "$file"
done
elif [ -f "$TARGET" ]; then
process_file "$TARGET"
fi