Multi
track CD and DVD to Xvid ripping
Ripping CD
How to rip multiple tracks into one mp3/ogg vorbis file on FreeBSD;
Sometimes
longer songs are divided into seperate parts on a cd, which is not bad,
but when ripping them to compressed file for the portable player or the
car it's likely there's a pause or quick break playing them, so here's
a way to create one big raw PCM file from the cd tracks and rip it to
mp3/ogg vorbis.
Trouble with using wavmerge (from wavbreaker) is
that it caused a tick at the mergepoint of two wav files, and mp3wrap
cause the mp3 to go clock crazy in XMMS, so I looked for a way to merge
the raw data, then rip it into one track.
Start off by inserting the cd, then do lf /dev/acd*
in a shell, this will show the list of tracks on the cd (acd0 in this
case);
/dev/acd0*
/dev/acd0t03
/dev/acd0t06
/dev/acd0t09 /dev/acd0t12
/dev/acd0t01
/dev/acd0t04
/dev/acd0t07
/dev/acd0t10 /dev/acd0t13
/dev/acd0t02
/dev/acd0t05
/dev/acd0t08
/dev/acd0t11 /dev/acd1*
(I used lf instead of ls to
mark the cd drives with a *)
I want track 6 and 7 as one, and start copying both tracks with dd;
dd if=/dev/acd0t06 of=t06.pcm bs=2352
dd if=/dev/acd0t07 of=t07.pcm bs=2352
Then, merge the two by doing cat t07.pcm >>
t06.pcm.
Or, to preserve the files, cp t06.pcm tmp.pcm, cat
t07.pcm >> tmp.pcm.
Ripping them to high quality mp3 (I prefer ogg vorbis, but my
car audio only understands mp3) means telling lame
we use raw PCM data for source;
lame -m s -q 0 -V 0 --noreplaygain -r -s 44.1 --bitwidth 16 -x
t06.pcm Parabolas.mp3
(in
this case I merged Parabol and Parabola from Tool, hence Parabolas, The
rip from the first three tracks from Metallica's S&M is called
The
ecstasy of master Ktulu :-) )
In case the rip sounds like static, remove the -x
in the command line. I had to add it because of that problem.
Tag the mp3 file and it's done.
For the mediaserver at home I use oggenc -q 10
--advanced-encode-option impulse_noisetune=-15 -o filename.ogg -r
filename.pcm.
To refresh /dev after inserting another cd, use cdcontrol -f
/dev/acd0 info. (quick and dirty way)
Got myself a Cowon
iAudio 7 to hook up to the car stereo now, so ripping is done
with one command for both media server and portable player/car;
dd if=/dev/acd0t01
bs=2352 | oggenc -q 10 --advanced-encode-option impulse_noisetune=-15
-o 01-track_name.ogg -r -
To add the ripping into one script (named rip_cd.sh);
cdcontrol -f /dev/acd0 info
for track in /dev/acd0t*
do
ogg_name=`echo $track | sed -e "s%/dev/acd0t%%"`
echo ripping $track...
dd if=$track bs=2352 | oggenc -q 10 --advanced-encode-option impulse_noisetune=-15 -o $ogg_name.ogg -r -
done
Start it like sh rip_cd.sh.
Ripping DVD
Latest method
These encoding options result in an Xvid movie 45 to 70% of the size of a single .vob rip by tccat, depending on the amount of noise in the source (Silent Hill is a good example of lots of noise on the dvd) and the actual resolution of the movie.
Notes in relation to this method; although it doesn't save that much diskspace every bit helps (but 50% is still good), it saves more on CPU/GPU power needed to decode the stream. The player also needs to have all postprocessing turned off, otherwise that'll introduce artifacts (no use trying to enhance what already is set to maximum quality).
Mkvtoolnix and libxine don't mix in the current versions of FreeBSD and Ubuntu, mkv doctype 2 is written but libxine 1.1.16 doesn't understand it so either keep the .avi container or use mplayer. Mplayer on the other hand doesn't downmix 5.1 surround to stereo decently (lower volume and no surround mixed in left and right).
#encode generic single pass maximum quality
mencoder -dvd-device . dvd://1 -sws 2 -vf eq2=0.95,hqdn3d=0:0:4:3,crop=720:568,scale=720:400:0:0:0.00:0.66,harddup -ovc xvid -xvidencopts aspect=1.8:nointerlacing:vhq=4:quant_type=mpeg:min_iquant=1:min_pquant=1:min_bquant=1:bitrate=5000:chroma_opt:nolumi_mask:notrellis:qpel:threads=1 -oac copy -aid 128 -o rip.avi
#merge to mkv file
mkvmerge -o ../Title.mkv --title "Title" -d 0 -a 1 -S rip.avi
Previous methods:
After a long time messing with encoding
options, filters, etc. it turned out cropping the black bars but not
scaling the movie gives the best results. Black areas stay black
without showing horizontal lines. What's there in noise or flickering
is what's been in the source anyway.
It also made denoise and blur
filters are much less effective, too much reduces file size but brings
down quality. Keeping the quality good means the filters are set low
enough to just leave it out of the processing.
The same thing goes
for Quarterpel and Trellis quantizer, these can stay disabled as there
seems no improvement using these options.
So, currently ripping is done with dvd::rip
to xvid with quality set to 0.25. Xvid is set to mpeg quant type, ultra
high motion (6), wide search vhq (4) and all minimum quantizers to 1.
With
a resolution of 720x432 after crop for a standard letterbox movie it
takes about 500MB per half hour including the original 6 channel
ac3 soundtrack. At these sizes, why bother converting to mp3/vorbis?
If the movie needs deinterlacing, use zoom to full frame.
It's slower, but it gave the best results as tested with Independence
day. Strangely enough, with this movie, automatic clip & zoom
didn't change the resolution or size so I had to set it manually to
720x432. Had to set quality to 0.35 as well because keeping it at 0.25
made the bitrate too low. I think the calculation didn't work correctly
because I had to set clip & zoom manually.
And why mpeg? Because
then it can still be decoded by low power systems like the VIA Eden
mini ITX systems. I'd rather trade in filesize for less computing power
needed to watch a movie.
Matroska
As I noticed problems with some avi files in Xine and VLC I'm using mencoder and mkvtoolnix to rip the dvd to a .mkv container;
#check dvd title
mplayer dvd://1 -msglevel identify=6 -frames 0
#copy dvd title to disk
dvdcpy -o /usr/data/local/tmp/dvd -m -t 1 /dev/sr0
#detect crop size for bitstream calculation
mplayer -dvd-device /usr/data/local/tmp/dvd dvd://1 -chapter 2-2 -vf cropdetect (add -vo null -nosound to disable video/audio output)
#subtitle if needed
mencoder -dvd-device /usr/data/local/tmp/dvd dvd://1 -nocache -ovc copy -nosound -vobsuboutindex 0 -sid 0 -vobsubout /usr/data/local/tmp/vobsub -o /dev/null
#encode pass 1
mencoder -dvd-device /usr/data/local/tmp/dvd dvd://1
-nocache -vf harddup,eq2=0.97 -ovc xvid -passlogfile /usr/data/local/tmp/passlog
-xvidencopts
autoaspect:par=vga11:vhq=4:quant_type=mpeg:pass=1:chroma_opt:lumi_mask:notrellis:threads=1
-nosound -of rawvideo -o /dev/null
#encode pass 2
mencoder -dvd-device /usr/data/local/tmp/dvd dvd://1
-nocache -vf harddup,eq2=0.97 -ovc xvid -passlogfile /usr/data/local/tmp/passlog
-xvidencopts autoaspect:par=vga11:vhq=4:quant_type=mpeg:bitrate=5000000:chroma_opt:lumi_mask:notrellis:pass=2:threads=1 -oac copy -aid 128 -o /usr/data/local/tmp/rip.avi
#merge to mkv file
mkvmerge -o title.mkv --title "Title" --fourcc 0:XVID -d 0 -A -S /usr/data/local/tmp/rip.avi --language 0:chi --language 1:chi -a 1 -D -S /usr/data/local/tmp/rip.avi (add for subtitle: --language 0:nld --sub-charset 0:UTF-8 -s 0 -D -A /usr/data/local/tmp/vobsub.idx)
* modify as needed in bold
Bitrate
is cropped width*cropped height*framerate*bpp. At 0.25 bpp 720*416=1872
kbps, 720*432=1944 kbps, 720*544=2448 kbps, 720*576=2592 kbps.
Also, during the first pass the average bitrate is shown in the output which can also be used as the bitrate for second pass.
For
maximum quality (depending on the minimum quant quality ofcourse)
bitrate can be set to 3000000 or even higher but xvid will only use
what is necessary to encode (going from default quant min 2 to min 1
seems to double the filesize).
As
can be seen I don't crop as the overhead for encoding the black borders
is very low. I just need to test how much it will affect cpu power
needed though.
As
I use the noscale 720x576 output of the VIA Chrome TV output (it uses
less gpu power) downscaling video while playing uses extra cpu power.
For the use on this setup I use the extra options -sws 1 and add scale=720:404 to -vf.
One can also upscale to 1024*576 to not waste cpu while playing at 1024*768 output.
The command for 1 pass encoding which so far is just as good in quality as long as the bitrate maximum is high enough:
mencoder
-dvd-device . dvd://1 -sws 1 -vf eq2=0.97,scale=720:-2,harddup -ovc
xvid -xvidencopts
autoaspect:par=vga11:vhq=4:quant_type=mpeg:bitrate=5000000:chroma_opt:lumi_mask:notrellis:threads=0
-oac copy -aid 128 -o rip.avi
Previous method
Install transcode,
this will also install the needed port of ffmpeg.
To create one single .vob containing the main movie with
the soundtracks:
Check the amount of titles with tcprobe
-i /cdrom -H 10 and the DVD title line in
the beginning of the output.
To see what the length of each title is and determine which title is
the one you want, use tcprobe
-i /cdrom -H 10 -T title number.
Now run the command tccat
-i /cdrom -t dvd -T titlenumber,-1,1 -d 2 > filename.vob
to create the single .vob file.
It
is possible to reduce the size of the file by demuxing and muxing
the video and main audio stream if there are more than one audio
streams in the .vob file. The movie Alien resurrection for instance
went from a 4.7 to a 4.0 Gib file. To do this there needs to be enough
free disk space for at least one more copy.
Run the command ffmpeg
-i ripped.vob -vcodec copy -an -f vob video.vob and ffmpeg -i ripped.vob -vn -acodec
copy -f ac3 audio.ac3.
If the right soundtrack isn't the first, as can be seen in the output
when ffmpeg runs, add -map
0.x:0.0 to the command where x is the number for
the default track (usually the one marked as 0x80).
Mux the two files again with ffmpeg
-i video.vob -vcodec copy -i audio.ac3 -acodec copy -f vob filename.vob.
To test if all's well, add -t
600 to only mux the first 600 seconds.
This has all been done with the AC3 soundtrack, unless the DTS
soundtrack is encoded at full banwidth and not at +/- 768Kib it doesn't
make a difference in quality according to most opinions. I haven't
tested it myself yet.
It's possible for the time to be messed up where a media player will
report a movie length much shorter than reality.
This
seems to be a known issue with single .vob files and can be fixed by
using special editors (to me no known open source version).
The
other option is to rip the dvd or file to an MPEG-4 version anyway, but
for me I'd lose the MPEG-2 hardware acceleration on my VIA Eden media
server.
Example of ripping Aliens to a Matroska
container with mpeg4 (H.264 is too CPU intensive) and original
AC3 streams via 2 pass encoding;
ffmpeg
-i ripped.vob -vcodec mpeg4 -mpeg_quant 1 -qscale 1 -b 6000k -croptop
16 -cropbottom 16
-s 720x382 -sws_flags sinc -aspect 1.88 -qcomp 1 -cmp 2 -subcmp 2 -mbcmp
2 -precmp 2 -skipcmp 2 -trellis 1 -last_pred 2 -vsync 1 -an -pass 1
-passlogfile mpeg4 -f
matroska -y /dev/null && ffmpeg -i ripped.vob
-vcodec
mpeg4 -map 0.0:0.0
-mpeg_quant 1 -qscale 1 -b 6000k -croptop 16 -cropbottom 16 -s 720x382 -sws_flags sinc -aspect 1.88
-qcomp 1
-cmp 2 -subcmp 2 -mbcmp 2 -precmp 2 -skipcmp 2 -trellis 1 -last_pred 2
-vsync 1 -acodec
copy -map 0.2:0.1 -pass 2
-passlogfile mpeg4 -f matroska -y 02-Aliens.mkv
Cropping
the top and bottom bars by 16 pixels to remove the
black bars from the video stream, mapping the english sound stream
(0.2) to the default (0.1) otherwise it'll end up in french, and using -vsync to get rid of
the slowly getting out of sync sound towards the second half of the
movie.
Other options are -s
720x382, -sws_flags sinc and -aspect
1.88 so the player won't have to scale it afterwards and
the -...cmp 2
options
which makes movements much smoother. One thing to note though is that
anything not smooth in the original will be slightly more visible when
encoded to another format.
These
are (as far as I can tell) the best options to get reasonably fast encoding while
still getting a high (best?) quality output. The ffmpeg FAQ gave
options which seemed to be out of date with this development version
but out of those -flags
4mv -cmp 2 -subcmp 2 -g 300 made the file about 10%
smaller, yet the quality got worse.
Creating ISO
image and burning to cd
To create an ISO image in the lower directory; mkisofs -V Compilation_01 -J -U
-r -o ../compilation_01.iso .
Check the image by mounting it with mdconfig;
mdconfig -a -t vnode -f
compilation_01.iso -u 1
mount -t cd9660 /dev/md1
/mnt
Now the contents can be checked in /mnt.
To remove the image;
umount /mnt
mdconfig -d -u 1
Burn the cd with burncd;
burncd -f /dev/[cd/dvd
burner device name] data compilation_01.iso fixate
PS For some very enlightening reading on why you don't need to spend
huge amounts of money on high end audio equipment, read The
audio critic and its back issues.
Siegfried Linkwitz (yes, The SL) also provides a
lot of info on loudspeaker design
and gives you the Orion,
an affordable high end loudspeaker using an active crossover. (one I
will build and use in the near future)
References:
FreeBSD handbook, creating
CD's