How to rip an audio CD using FFMPEG CLI?

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
747
Reaction score
608
Credits
4,639
I'm using this script to convert mka (the audio track of a mkv) to wav. But I'm wondering - what do I have to add/remove to/from this script in order to make it rip an audio CD and make the output files WAVs with the already predetermined specs?

Code:
#!/usr/bin/env bash

for name in *.mka;
do
    newname=$(echo "$name" | rev | cut -f 2- -d '.' | rev)
    ffmpeg -i "$name" -vn -ar 44100 -ac 2 -ab 1411k -f wav "$newname".wav;
done

This script will convert any mka to a 16-bit, 44 kHz, 2 channel, 1411 audio bitrate WAV. I'm guessing there isn't much to add to (or remove from) this FFMPEG line in order to make it read the audio CD in the optical device and rip each track to a wav? Or am I wrong? The output track name doesn't matter much for as long as they're different names (Track 1, Track 2 and so on), I can change them myself after ripping is complete.

I wanna do it with CLI bc I'm honestly sick of the non-thinking KDE developers and CLI will save me a lot of nerves.
 


JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,820
Reaction score
2,656
Credits
15,608
Personally, I've always used asunder to rip CD's to .wav, .flac, .mp3, .ogg etc.
I'm not sure offhand how you'd go about using ffmpeg to do it.
I'll have a play and see if I can come up with anything!
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,820
Reaction score
2,656
Credits
15,608
This looks like it might get you on the right track:

I've just tried the first thing in the OP's post there:
e.g.
Bash:
ffmpeg -f libcdio -ss 0 -i /dev/sr0 dump.flac
And that works flawlessly - but it does rip an entire album as a single song. After ripping the CD this way - I suppose you could use something like Audacity to split out the individual songs and to set the metadata for each song.

Failing that, you could write a script to read the metadata from the CD, in order to work out the number of songs and to get the start/end positions of each song on the disc.
Then you'd have to use the start/end values to work out the length of each track, allowing you to invoke ffmpeg to rip a song at a time specify the start position of each track and the length of the track as per the answer on the post at the above URL.....

Or you could just get a pencil and work it out........ Which reminds me of a joke about constipated mathematicians.

Q. How do mathematicians cure constipation?
A. They get a pencil and work it out. Ha ha ha!
 
Last edited:
OP
rado84

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
747
Reaction score
608
Credits
4,639
Failing that, you could write a script to read the metadata from the CD, in order to work out the number of songs and to get the start/end positions of each song on the disc.
Then you'd have to use the start/end values to work out the length of each track, allowing you to invoke ffmpeg to rip a song at a time specify the start position of each track and the length of the track as per the answer on the post at the above URL.....
If I can rip it as an image (flac, wavpack) with a cue file containing all the metadata, separating it to different tracks is easy and I have a few ways for that. The problem is IDK how to do the image creation. K3B supposedly can do this but the last time I tried creating an image from an audio CD, clicking those functions did nothing which suggests that K3B either can't do it, or it's bugged and that doesn't work.

I didn't know about that asunder, I'm gonna try it out. At first look at least it's GTK2 which is good! If it works the way I hope, I won't have to learn CLI ripping, altough this knowledge could come in handy some day.
 


Top