Difference between revisions of "Rip Audio CDs"

From ArchWiki
Jump to: navigation, search
(update templates, see Help:Style)
(merge request)
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Optical (English)]]
+
[[Category:Optical]]
{{i18n|Rip Audio CDs}}
+
{{Merge|Optical Disc Drive|There's already [[Optical Disc Drive#DVD ripping]].}}
==Graphical tools==
+
CD rippers are designed to extract ("rip") the raw digital audio (in a format commonly called CDDA) from a compact disc to a file or other output. Most CD rippers also support burning audio to a CD and transcoding it on-the-fly.
There are several tools to create .mp3 or .ogg files from an audio CD (eg. k3b, KAudioCreator, Rhythmbox)
+
  
==Console tools==
+
== Introduction ==
abcde is a comprehensive audio ripping tool, including CDDB lookup.
+
  
==Shell script==
+
Music is usually stored on audio CDs in an uncompressed format (requires a lot of space, e.g. 700MB for only 80 minutes of audio). Extracting the audio from the CD usually involves compressing it so that it requires less space using:
If you want to rip an audio CD gapless and using CD-Text you can use the following shell script. You need to have the following packages installed on your system: ''mp3splt'', ''cdrtools'' and ''vorbis-tools''.
+
; Lossless compression: same quality, less space.
 +
; Lossy compression: lower quality, much less space.
  
You need cdrtools from AUR for this script to work: [https://aur.archlinux.org/packages.php?ID=323 cdrtools]
+
Most common formats to convert to are: APE and FLAC for lossless and MP3 and OGG for lossy.
  
{{hc|rip_gapless.sh|2=
+
== Ripping ==
#!/bin/sh
+
 
 +
=== Using a CD ripper ===
 +
 
 +
{{Box||For some examples of CD rippers see: [[List of Applications#CD Ripping]].|#E5E5FF|#FCFCFC}}
 +
 
 +
=== Using a simple shell script ===
 +
 
 +
If you want to rip an audio CD gapless and using CD-Text you can use the following shell script. You need to [[pacman|install]] the {{Pkg|mp3splt}}, {{Pkg|cdrtools}} and {{Pkg|vorbis-tools}} packages, all available in the [[official repositories]].
 +
 
 +
{{hc|rip_gapless.sh|<nowiki>
 +
#!/bin/bash
 
# This script needs mp3splt, cdrtools, vorbis-tools
 
# This script needs mp3splt, cdrtools, vorbis-tools
  
usage()  
+
CREATE_OGG="true";
 +
CREATE_FLAC="false";
 +
CREATE_MKA="false";
 +
 
 +
WORKING_DIRECTORY=$(pwd)
 +
 
 +
function usage()  
 
{  
 
{  
   echo "Usage: $0 &#91;filename&#93; device"
+
   echo "Usage: $0 [OUTPUT_DIRECTORY] device";
   echo "eg.: $0 /dev/sr0"
+
   echo "eg.: $0 my_audio_cd /dev/sr0";
   exit
+
   exit;
 
}
 
}
  
filename=cdimage
+
function no_cdtext()
 +
{
 +
  echo "CD doesn't contain cd-text information";
 +
  echo "Please specify output directory";
 +
  echo "$0 OUTPUT_DIRECTORY device";
 +
  exit;
 +
}
  
if &#91;&#91; "$#" = "1" &#93;&#93;; then
+
function remove_quotes() {
   cdrom=$1
+
  local OUTPUT_STRING
 +
  # remove quotes
 +
  OUTPUT_STRING=$(echo "$1" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
 +
  # remove selected special characters
 +
  echo "$OUTPUT_STRING" | sed "s/\(.*\)[\\]\(.*\)/\1\2/g"
 +
}
 +
 
 +
# store command line parameters
 +
if [[ "$#" = "2" ]] ; then
 +
  CDROM=$2;
 +
  OUTPUT_DIRECTORY=$1;
 +
elif [[ "$#" = "1" ]] ; then
 +
  CDROM=$1;
 +
else
 +
  usage;
 +
fi
 +
 
 +
# retrieve CD information
 +
echo "Retrieve CD information"
 +
CD_INFO=$(cdda2wav -J -g /dev/sr0 2>&1)
 +
 
 +
# test if CD-Text is available
 +
if [[ "detected" == $(echo "${CD_INFO}" | awk '/^CD-Text.*/ {print $2}') ]]; then
 +
  echo "CD-Text detected"
 +
  CD_TEXT_DETECTED=true
 +
  ALBUM_INFORMATION=$(echo "${CD_INFO}" | grep ^"Album title")
 +
  # remove characters from beginning of string
 +
  ALBUM_INFORMATION=$(echo "${ALBUM_INFORMATION#*Album title: }")
 +
  ALBUM_TITLE=$(echo "${ALBUM_INFORMATION% from *}")
 +
  ALBUM_TITLE=$(remove_quotes "${ALBUM_TITLE}")
 +
  ALBUM_ARTIST=$(echo "${ALBUM_INFORMATION#* from }")
 +
  ALBUM_ARTIST=$(remove_quotes "${ALBUM_ARTIST}")
 +
fi
 +
 
 +
# check if cd has cdtext
 +
if [[ true == ${CD_TEXT_DETECTED} ]]; then
 +
  if [[ "2" = "$#" ]]; then
 +
    echo "CD-text found"
 +
    echo "Overriding given output directory name"
 +
   fi
 +
  mkdir -p "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
 +
  cd "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
 +
  OUTPUT_DIRECTORY="${ALBUM_ARTIST}/${ALBUM_TITLE}"
 +
  OUTPUT_FILENAME="${ALBUM_TITLE}"
 
else
 
else
   usage
+
   if [[ "$#" != "2" ]]; then
 +
    no_cdtext
 +
  else
 +
    mkdir "${OUTPUT_DIRECTORY}"
 +
    cd "${OUTPUT_DIRECTORY}"
 +
    OUTPUT_FILENAME="${OUTPUT_DIRECTORY}"
 +
  fi
 
fi
 
fi
  
cdda2wav -cuefile -paranoia -t all dev=${cdrom} ${filename}.wav
+
cdda2wav -cuefile -paranoia -t all dev=${CDROM} "${OUTPUT_FILENAME}.wav" &> "${OUTPUT_FILENAME}.log"
oggenc -o ${filename}.ogg -q 6 ${filename}.wav
+
 
oggsplt -c ${filename}.cue -o "@N - @t" ${filename}.ogg
+
if [[ "true" = ${CREATE_OGG} ]]; then
rm ${filename}.{cddb,cdindex,cdtext,cue,wav,ogg}
+
  mkdir ogg
}}
+
  pushd ogg
 +
  oggenc -o "${OUTPUT_FILENAME}.ogg" -q 6 "../${OUTPUT_FILENAME}.wav"
 +
  oggsplt -c "../${OUTPUT_FILENAME}.cue" -o "@N - @t" "${OUTPUT_FILENAME}.ogg"
 +
  popd
 +
fi
 +
 
 +
if [[ "true" = ${CREATE_FLAC} ]]; then
 +
  mkdir flac
 +
  pushd flac
 +
  cd flac  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
 +
  flac --cuesheet="../${OUTPUT_FILENAME}.cue" --tag-from-file=CUESHEET="../${OUTPUT_FILENAME}.cue" --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
 +
  popd
 +
fi
 +
 
 +
if [[ "true" = ${CREATE_MKA} ]]; then
 +
  mkdir mka
 +
  pushd mka
 +
  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
 +
  flac --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
 +
  mkvmerge -q -o "${OUTPUT_FILENAME}.flac.mka" "${OUTPUT_FILENAME}.flac" --attachment-mime-type text/plain --attachment-description "cdda2wav Log" --attach-file "../${OUTPUT_FILENAME}.log" --attachment-mime-type text/plain --attachment-description "Original CUE Sheet" --attach-file "../${OUTPUT_FILENAME}.cue" --title "${ALBUM_TITLE}" --chapters "../${OUTPUT_FILENAME}.cue"
 +
  rm "./${OUTPUT_FILENAME}.flac"
 +
  popd
 +
fi
 +
 
 +
# rm "${WORKING_DIRECTORY}/${OUTPUT_DIRECTORY}/${OUTPUT_FILENAME}.{cddb,cdindex,cdtext,wav}"
 +
</nowiki>}}
 +
 
 +
== Post-processing ==
 +
 
 +
=== Tag editors ===
 +
 
 +
{{Box||For some examples of audio tag editors see: [[List of Applications#Audio tag editors]].|#E5E5FF|#FCFCFC}}
 +
 
 +
=== Converting to other formats ===
 +
 
 +
If the CD ripper you used does not support the format you wanted to convert to you can use other encoders/decoders such as [[FFmpeg]] or [[MEncoder]]. Some simple scripts to convert from [[Convert Flac to Mp3|flac]] or [[Convert Any To Mp3|other formats]] to MP3 can also be found on the wiki.
 +
 
 +
== See also ==
 +
 
 +
* RIAA and actual laws allow backup of physically obtained media under these conditions [https://www.riaa.com/physicalpiracy.php?content_selector=piracy_online_the_law RIAA - The Law].

Revision as of 03:39, 15 September 2013

Merge-arrows-2.pngThis article or section is a candidate for merging with Optical Disc Drive.Merge-arrows-2.png

Notes: There's already Optical Disc Drive#DVD ripping. (Discuss in Talk:Rip Audio CDs#)

CD rippers are designed to extract ("rip") the raw digital audio (in a format commonly called CDDA) from a compact disc to a file or other output. Most CD rippers also support burning audio to a CD and transcoding it on-the-fly.

Introduction

Music is usually stored on audio CDs in an uncompressed format (requires a lot of space, e.g. 700MB for only 80 minutes of audio). Extracting the audio from the CD usually involves compressing it so that it requires less space using:

Lossless compression
same quality, less space.
Lossy compression
lower quality, much less space.

Most common formats to convert to are: APE and FLAC for lossless and MP3 and OGG for lossy.

Ripping

Using a CD ripper

Template:Box

Using a simple shell script

If you want to rip an audio CD gapless and using CD-Text you can use the following shell script. You need to install the mp3splt, cdrtools and vorbis-tools packages, all available in the official repositories.

rip_gapless.sh
#!/bin/bash
# This script needs mp3splt, cdrtools, vorbis-tools

CREATE_OGG="true";
CREATE_FLAC="false";
CREATE_MKA="false";

WORKING_DIRECTORY=$(pwd)

function usage() 
{ 
  echo "Usage: $0 [OUTPUT_DIRECTORY] device";
  echo "eg.: $0 my_audio_cd /dev/sr0";
  exit;
}

function no_cdtext()
{
  echo "CD doesn't contain cd-text information";
  echo "Please specify output directory";
  echo "$0 OUTPUT_DIRECTORY device";
  exit;
}

function remove_quotes() {
  local OUTPUT_STRING
  # remove quotes
  OUTPUT_STRING=$(echo "$1" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
  # remove selected special characters
  echo "$OUTPUT_STRING" | sed "s/\(.*\)[\\]\(.*\)/\1\2/g"
}

# store command line parameters
if  [[ "$#" = "2" ]] ; then
  CDROM=$2;
  OUTPUT_DIRECTORY=$1;
elif [[ "$#" = "1" ]] ; then
  CDROM=$1;
else 
  usage;
fi

# retrieve CD information
echo "Retrieve CD information"
CD_INFO=$(cdda2wav -J -g /dev/sr0 2>&1)

# test if CD-Text is available
if [[ "detected" == $(echo "${CD_INFO}" | awk '/^CD-Text.*/ {print $2}') ]]; then
  echo "CD-Text detected"
  CD_TEXT_DETECTED=true
  ALBUM_INFORMATION=$(echo "${CD_INFO}" | grep ^"Album title")
  # remove characters from beginning of string
  ALBUM_INFORMATION=$(echo "${ALBUM_INFORMATION#*Album title: }")
  ALBUM_TITLE=$(echo "${ALBUM_INFORMATION% from *}")
  ALBUM_TITLE=$(remove_quotes "${ALBUM_TITLE}")
  ALBUM_ARTIST=$(echo "${ALBUM_INFORMATION#* from }")
  ALBUM_ARTIST=$(remove_quotes "${ALBUM_ARTIST}")
fi

# check if cd has cdtext
if [[ true == ${CD_TEXT_DETECTED} ]]; then
  if [[ "2" = "$#" ]]; then
    echo "CD-text found"
    echo "Overriding given output directory name"
  fi
  mkdir -p "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
  cd "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
  OUTPUT_DIRECTORY="${ALBUM_ARTIST}/${ALBUM_TITLE}"
  OUTPUT_FILENAME="${ALBUM_TITLE}"
else
  if [[ "$#" != "2" ]]; then
    no_cdtext
  else
    mkdir "${OUTPUT_DIRECTORY}"
    cd "${OUTPUT_DIRECTORY}"
    OUTPUT_FILENAME="${OUTPUT_DIRECTORY}"
  fi
fi

cdda2wav -cuefile -paranoia -t all dev=${CDROM} "${OUTPUT_FILENAME}.wav" &> "${OUTPUT_FILENAME}.log"

if [[ "true" = ${CREATE_OGG} ]]; then
  mkdir ogg
  pushd ogg
  oggenc -o "${OUTPUT_FILENAME}.ogg" -q 6 "../${OUTPUT_FILENAME}.wav"
  oggsplt -c "../${OUTPUT_FILENAME}.cue" -o "@N - @t" "${OUTPUT_FILENAME}.ogg"
  popd
fi

if [[ "true" = ${CREATE_FLAC} ]]; then
  mkdir flac
  pushd flac
  cd flac  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
  flac --cuesheet="../${OUTPUT_FILENAME}.cue" --tag-from-file=CUESHEET="../${OUTPUT_FILENAME}.cue" --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
  popd
fi

if [[ "true" = ${CREATE_MKA} ]]; then
  mkdir mka
  pushd mka
  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
  flac --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
  mkvmerge -q -o "${OUTPUT_FILENAME}.flac.mka" "${OUTPUT_FILENAME}.flac" --attachment-mime-type text/plain --attachment-description "cdda2wav Log" --attach-file "../${OUTPUT_FILENAME}.log" --attachment-mime-type text/plain --attachment-description "Original CUE Sheet" --attach-file "../${OUTPUT_FILENAME}.cue" --title "${ALBUM_TITLE}" --chapters "../${OUTPUT_FILENAME}.cue"
  rm "./${OUTPUT_FILENAME}.flac"
  popd
fi

# rm "${WORKING_DIRECTORY}/${OUTPUT_DIRECTORY}/${OUTPUT_FILENAME}.{cddb,cdindex,cdtext,wav}"

Post-processing

Tag editors

Template:Box

Converting to other formats

If the CD ripper you used does not support the format you wanted to convert to you can use other encoders/decoders such as FFmpeg or MEncoder. Some simple scripts to convert from flac or other formats to MP3 can also be found on the wiki.

See also

  • RIAA and actual laws allow backup of physically obtained media under these conditions RIAA - The Law.