65 lines
1.7 KiB
Bash
Executable File
65 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
INPUT="$HOME/mount/Ripping/Lutz/noch zu rendern/Brücke nach Terabithia/A1_t00.mkv"
|
|
OUTPUT="${INPUT%.*}_deinterlaced.mp4"
|
|
LOGFILE=$(mktemp)
|
|
|
|
if [ ! -f "$INPUT" ]; then
|
|
echo "Input file not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Step 1: Try runtime detection with idet
|
|
ffmpeg -hide_banner -vstats -nostats \
|
|
-i "$INPUT" \
|
|
-filter:v "format=yuv420p,idet" \
|
|
-frames:v 500 \
|
|
-an -f rawvideo -y /dev/null \
|
|
2> "$LOGFILE"
|
|
|
|
TFF=$(grep -o 'TFF:[0-9]*' "$LOGFILE" | head -1 | cut -d: -f2)
|
|
BFF=$(grep -o 'BFF:[0-9]*' "$LOGFILE" | head -1 | cut -d: -f2)
|
|
PROG=$(grep -o 'Progressive:[0-9]*' "$LOGFILE" | head -1 | cut -d: -f2)
|
|
rm "$LOGFILE"
|
|
|
|
TFF=${TFF:-0}
|
|
BFF=${BFF:-0}
|
|
PROG=${PROG:-0}
|
|
|
|
echo "Detected via idet - Progressive: $PROG, TFF: $TFF, BFF: $BFF"
|
|
|
|
# Step 2: Fallback to metadata if no detection occurred
|
|
if [ "$((TFF + BFF + PROG))" -eq 0 ]; then
|
|
echo "idet returned 0 frames — falling back to metadata..."
|
|
FIELD_ORDER=$(ffprobe -v error -select_streams v:0 \
|
|
-show_entries stream=field_order \
|
|
-of default=noprint_wrappers=1:nokey=1 "$INPUT")
|
|
|
|
case "$FIELD_ORDER" in
|
|
tt|bb)
|
|
echo "Field order is interlaced ($FIELD_ORDER)."
|
|
INTERLACED=true
|
|
;;
|
|
progressive|unknown|"")
|
|
echo "Metadata says progressive or unknown."
|
|
INTERLACED=false
|
|
;;
|
|
esac
|
|
else
|
|
INTERLACED=$((TFF + BFF > PROG))
|
|
fi
|
|
|
|
# Step 3: Skip or apply deinterlacing
|
|
if [ "$INTERLACED" = false ]; then
|
|
echo "Video is progressive. No deinterlacing needed."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Video is interlaced. Proceeding with deinterlacing..."
|
|
|
|
# Step 4: Apply yadif
|
|
ffmpeg -i "$INPUT" \
|
|
-vf "yadif=mode=1:parity=auto" \
|
|
-c:v libx264 -preset slow -crf 18 -c:a copy \
|
|
"$OUTPUT"
|