Skip to content

Instantly share code, notes, and snippets.

@programminghoch10
Last active September 17, 2024 10:44
Show Gist options
  • Save programminghoch10/0749cd76eea9c1d6f62e4cd9d7b98746 to your computer and use it in GitHub Desktop.
Save programminghoch10/0749cd76eea9c1d6f62e4cd9d7b98746 to your computer and use it in GitHub Desktop.
Rip DVDs using FFmpeg
#!/bin/bash
set -e
#set -x
set -u
set -o pipefail
shopt -s inherit_errexit
# input can be device path /dev/sr0 or folder path
input="${1:-}"
[ -z "$input" ] && input=/dev/sr0
# disc title (output file name)
# will be detected automatically if possible
title="${2:-}"
for cmd in lsdvd ffmpeg sed grep wc seq basename; do
[ -z "$(command -v "$cmd")" ] && echo "$cmd missing" >&2 && exit 1
done
[ -z "$title" ] && title=$(lsdvd "$input" 2>/dev/null | grep '^Disc Title: ' | sed 's/^Disc Title: \(.*\)$/\1/')
[ "$title" = "unknown" ] && [ -d "$input" ] && title=$(basename "$input")
trackcount=$(lsdvd "$input" 2>/dev/null | grep '^Title: ' | wc -l)
processTrack() {
local dvdid="$1"
ffmpeg -nostdin -hide_banner \
-v warning -stats \
-f dvdvideo -title "$dvdid" -i "$input" \
-map 0 -c copy -disposition +0 \
-metadata:s:s VIEWPORT= \
-y \
"$title"_"$dvdid".mkv
}
for i in $(seq 1 $trackcount); do
processTrack "$i" &
[ -b "$input" ] && wait
done
wait

Rip DVDs using FFmpeg

This Gist provides an easy to use script for ripping DVDs using FFmpeg.

Install

Install ffmpeg, libdvdcss2 and lsdvd on your system.
Download ripdvd.sh from this gist and make it executable.

Usage

Directly rip DVD

./ripdvd.sh /dev/sr0

Rip DVD backups

Create a file mirror from a DVD using vobcopy:

vobcopy --mirror --large-file --output-dir .

or mount an ISO backup into a directory.

Then

./ripdvd.sh path/to/DVDfiledump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment