I have a DVD with cartoons for kids and there are a couple of episodes on every one of them. How can I rip them such that every episode is in a separate file? I think every episode is written as a chapter within one title on the DVD.
2 Answers
To extract the .VOB for Title 2, Chapter 3
Note that '-chapter 3' and '-chapter 3-' will copy from chapter 3 to the end, and if the chapter number you specify is invalid, the option is ignored, and will therefore copy the full title.
# physical DVD
mplayer dvd://2 -chapter 3-3 -dumpstream -dumpfile ~/3.VOB
# DVD .iso image
mplayer dvd://2 -dvd-device "$dvd_iso" -chapter 3-3 -dumpstream -dumpfile ~/3.VOB
You can use lsdvd
to list title, chapter, cell, audio, video, etc for a physical DVD. However, it doesn't seem(?) to have a way to process a .iso
. You could mount a .iso, if need be.
# count Titles, and count Cells per title.
# eg. ${cell[1]} is the Count of Cells for the first title
# ${cell[titles]} is the Count of Cells for the last title
eval $(lsdvd | sed -n 's/Title: \([0-9]\+\), .* Chapters: \([0-9]\+\), Cells: .*/cells[$((10#\1))]=$((10#\2));/p')
titles=${#cells[@]}
title_num=2
from_cell=1
to_cell=${cell[title_num]}
dvdxchap
, on the other hand, can process a .iso
, but it doesn't list title info. You can, however, specify the title from which you want chapter info.
title_num=2
from_cell=1
# physical DVD
to_cell="$(dvdxchap -t $title_num /dev/dvd | sed -n 's/^CHAPTER\([0-9]\+\).*/\1/p' | sed -n '$p')"
# DVD .iso image
to_cell="$(dvdxchap -t $title_num "$dvd_iso"| sed -n 's/^CHAPTER\([0-9]\+\).*/\1/p' | sed -n '$p')"
When you know the title number you want, and know the number of cells, you can dump them in a loop:
# physical DVD
for ((c=$from_cell; c<$to_cell; c++)) ;do
mplayer dvd://$title_num -chapter $c-$c -dumpstream -dumpfile ~/$c.VOB
done
# DVD .iso image
for ((c=$from_cell; c<$to_cell; c++)) ;do
mplayer dvd://$title_num -dvd-device "$dvd_iso" -chapter $c-$c -dumpstream -dumpfile ~/$c.VOB
done
As a script that uses lsdvd
, Python, and ffmpeg
to extract the Chapters in a DVD to the current directory (extract-chapters.sh
):
#!/bin/sh
_genpy () {
if [ -n "$2" ]; then
lsdvd -x -Oy -t "$2" "$1"
else
lsdvd -x -Oy "$1"
fi
# Process in Python
cat <<EOF
for t in lsdvd['track']:
for c in t['chapter']:
print '{}\t{}\t{}\t{}'.format(t['vts'], t['ix'], c['ix'], c['length'])
EOF
}
_genpy "$@" 2> /dev/null | python | {
dvd_pos=0
while read line
do
dvd_file=$(printf '%02d' $(echo "$line" | cut -f1))
dvd_tr=$(echo "$line" | cut -f2)
dvd_cp=$(echo "$line" | cut -f3)
dvd_len=$(echo "$line" | cut -f4)
file_name="${dvd_tr}.${dvd_cp}.mkv"
cat "$1/VIDEO_TS/VTS_${dvd_file}"_*.VOB | ffmpeg -ss "$dvd_pos" -i - -t "$dvd_len" -c:v libvpx -c:a libvorbis -loglevel error "$file_name"
echo "Created $file_name"
dvd_pos=$(echo "$dvd_pos + $dvd_len" | bc)
done
}
Usage:
sh extract-chapters.sh PATH_TO_DVD_CONTENTS [TRACK]

- 5,167
-
For the non-POSIX tools, I chose
lsdvd
, Python, andffmpeg
because all of those came in the distribution's OSS repositories; other tools came from third-party repositories (e.g.dvdbackup
,makemkv
, etc.). – palswim Jan 16 '20 at 23:50
dvdxchap
is part of theogmtools
package. – Eborbob Oct 22 '17 at 14:41<=$to_cell
.to_cell
as calculated fromdvdxchap
will return the true total # of chapters (counted starting from 1), numbered the same asmplayer
understands via-chapter
flag, so we want to have a final loop where$c
=$to_cell
. – tobek Oct 17 '20 at 06:00lsdvd
sed
command earlier are the same and also need inclusive for-loop end. – tobek Oct 17 '20 at 06:07