From 26154d746e7d4e37063fc77ce7f97bf085527d9a Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 13 Jan 2026 08:11:52 +0100 Subject: [PATCH] convert_dvd: Add --- convert_dvd.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 convert_dvd.sh diff --git a/convert_dvd.sh b/convert_dvd.sh new file mode 100755 index 0000000..24c5512 --- /dev/null +++ b/convert_dvd.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# this is great, but only sees first title: +# HandBrakeCLI -i /dev/sr0 -t 1 -O -o BBT-S08E09.mp4 -e x264 -q 20 -a 1,3 -E av_aac,av_aac -B 128,128 -s 1,3 --subtitle-burned=none -m + +# Check for required argument +if [ $# -lt 1 ] || [ $# -gt 2 ]; then + echo "Usage: $0 SEASON [TITLE_NUMBER]" + echo "Example: $0 S08 # Extract all titles" + echo "Example: $0 S08 3 # Extract only title 3" + exit 1 +fi + +# Configuration +DVD_DEVICE="/dev/sr0" +SEASON="$1" +SPECIFIC_TITLE="$2" +MIN_DURATION=300 # 5 minutes in seconds + +# Episode counter (starts at 1 + EPISODE_OFFSET, or at specific title if provided) +if [ -n "$SPECIFIC_TITLE" ]; then + episode_counter=$SPECIFIC_TITLE +else + episode_counter=$((1 + ${EPISODE_OFFSET:-0})) +fi + +# Parse lsdvd output and process titles +if [ -n "$SPECIFIC_TITLE" ]; then + echo "Extracting title $SPECIFIC_TITLE..." + echo "Title: $SPECIFIC_TITLE, Length: 99:99:99.999" +else + echo "Scanning DVD..." + lsdvd "$DVD_DEVICE" +fi | grep "^Title:" | while read -r line; do + # Extract title number and duration + title_num=$(echo "$line" | sed 's/Title: \([0-9]*\),.*/\1/') + duration=$(echo "$line" | sed 's/.*Length: \([0-9:\.]*\).*/\1/') + + # Convert duration to seconds (HH:MM:SS.mmm format) + IFS=':.' read -r hours minutes seconds milliseconds <<< "$duration" + total_seconds=$((10#$hours * 3600 + 10#$minutes * 60 + 10#$seconds)) + + echo "Title $title_num: $duration ($total_seconds seconds)" + + # Skip titles shorter than MIN_DURATION + if [ "$total_seconds" -lt "$MIN_DURATION" ]; then + echo " -> Skipping (too short)" + continue + fi + + # Format episode number with leading zero + episode_num=$(printf "E%02d" "$episode_counter") + output_file="BBT-${SEASON}${episode_num}.mp4" + + # Check if file already exists + if [ -f "$output_file" ]; then + echo " -> Skipping (already exists): $output_file" + episode_counter=$((episode_counter + 1)) + continue + fi + + echo " -> Converting to: $output_file" + + # Convert the title + mplayer dvd://$title_num -dvd-device "$DVD_DEVICE" -dumpstream -dumpfile /dev/stdout | \ + ffmpeg -i pipe:0 \ + -map 0:v:0 -map 0:a:0 -map 0:a:2 -map 0:#0x20 -map 0:#0x22 \ + -c:v libx264 -preset medium -crf 23 \ + -c:a aac -ac 2 -b:a 128k \ + -c:s dvdsub \ + -metadata:s:a:0 language=eng -metadata:s:a:1 language=deu \ + -metadata:s:s:0 language=eng -metadata:s:s:1 language=deu \ + "$output_file" + + if [ $? -eq 0 ]; then + echo " -> Done: $output_file" + else + echo " -> ERROR converting title $title_num" + fi + + episode_counter=$((episode_counter + 1)) + echo +done + +echo "All conversions complete!" -- 2.47.3