qbittorrent ffmpeg conversion

run this after a torrent finishes

bash

save as .sh

#!/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}_web.mp4"

    if [ -f "$output" ]; then
        echo "File already exists: $output"
        return
    fi

    echo "Converting $input using GPU at 30 FPS..."
    ffmpeg -hwaccel auto -i "$input" \
        -c:v h264_nvenc -pix_fmt yuv420p -preset medium -rc vbr -cq 23 \
        -r 30 \
        -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