22

Is this possible with ffmpeg? Do you have any links that explain how to do this?

I have searched with Google but had not many results.

I just want to be able to convert a CD or DVD to MP3 audio files.

slhck
  • 235,242

5 Answers5

14

From DVDs, you can access the VOB files directly though, but you have to concatenate them:

cd /path/to/dvd/
cat VOB1.VOB VOB2.VOB VOB3.VOB | ffmpeg -i - -c:a libmp3lame -vn /path/to/output.mp3

For CD, if your ffmpeg was compiled with libcdio support, @M132 gives us a solution:

ffmpeg -f libcdio -ss 0 -i /dev/sr0 dump.flac

To get libcdio with ffmpeg under Windows, check out the Media Autobuild Suite. It can then read from a .cue file.

slhck
  • 235,242
9

For DVDs, the key part is installing the DVD decryption library (e.g. libdvdcss).

Reading the DVD directly with ffmpeg caused a lot of broken frames for me.

What worked like a charm, was dumping the movie to disk first

mpv dvd:// --dvd-device=/dev/cdrom --stream-dump=filename.vob
dvd://[title][/device] --dvd-device=PATH
          Play a DVD. DVD menus are not supported. If no title is given, the longest ti‐
          tle  is  auto-selected.  Without --dvd-device, it will probably try to open an
          actual optical drive, if available and implemented for the OS.

and convert it afterwards using ffmpeg:

ffmpeg -i filename.vob \
    -c:a libopus -b:a 90k -ar 48000 \  # OPUS, vbr 90 kbps, 48000 Hz
    -c:v libx264 -bf 16 -crf 22  \ # X.264, 16 B-frames (might be too high for action movies), target quality 22
    -trellis 2 -direct-pred auto \ # Some video quality tweaks
    -vf "unsharp=3:3:1.:5:5:0.0" \ # Unsharp masking for low DVD resolutions (720x576)
    -profile:v high444 -pix_fmt yuv444p -movflags +faststart \ # Some output settings
    outfile.mp4

You can list the available title numbers with lsdvd and subtract 1. So title number 3 as given by lsdvd corresponds to dvd://2.

You can also combine multiple titles as chapters into a single output file.


For audio CDs I recommend

  • asunder as a simple and light GUI-program that reliably "just-works" with some nice features, like automatic meta-data lookup, error correction, multi-output format conversion, etc.
  • abcde if you really want to dive into stuff and customize everything. Really nice console program but be prepared to spend some time reading the manual and figuring out the config first.
Suuuehgi
  • 267
2

Adding to @Suuuehgi's answer:
For me using mpv also worked, but mpv would add the DVD menu after the selected track itself, i.e. it concatenates the selected track and DVD menu. So I tried mplayer instead which also uses libdvdcss, but doesn't add the DVD menu after the selected track:

mplayer dvd://1 -dvd-device /dev/sr0 -dumpstream -dumpfile filename.vob
dump: 5386743808 bytes written (~99.9%)
dump: 5389791232 bytes written to 'filename.vob'.
Core dumped ;)

;)

1

If your ffmpeg doesn't have libcdio or you want to automatically store each track separately and you have cdparanoia installed, you can use that as the input and pipe each track to ffmpeg:

$ cdparanoia -Q 2>&1 | 
grep "^ *[1-9]" | 
sed -e 's/^ *\|\..*//g' | 
while read t; do 
  cdparanoia $t - | ffmpeg -i pipe: -b:a 128k -ar 44100 -ac 2 -y "rip $t.mp3"; 
done
  • cdparanoia -Q 2>&1 prints a track list and redirects it to standard out
  • grep "^ *[1-9]" finds the lines with a number at the start representing tracks
  • sed -e 's/^ *\|\..*//g' removes all substrings that are not the track number
  • while read t; do reads each track number into variable t
  • cdparanoia $t - runs cdparanoia again, this time to read the given track and writes output to standard out
  • ffmpeg -i pipe: -b:a 128k -ar 44100 -ac 2 -y "rip $t.mp3"; reads the input from standard in and does the conversion, here into mp3 (of course you can use any audio encoding you like)
  • done end of the while-loop

So you end up with a bunch of files named "rip <track number>.mp3" in your current directory.

sjngm
  • 2,143
-4

If a CD contains raw pcm data like 16 bit per channel at 44100 samples per second it should be possible to simply transfer the raw data to HDD then give it a standard wave header. making the data into a file all its own is up to you since finding programming tools to pre-open a null file is unknown to myself.