Transcoding Notes
This page records some miscellaneous notes about manipulating video and audio.
Problems with Sound
I have experienced problems multiplexing ac3 streams which have been
ripped from legitimate sources. In general, all these audio problems
can be overcome with the technique described below:
First, use mplayer to rip the audio to a pcm wave file. It is important
to use the waveheader option, because the waveheader includes
synchronization information necessary to synchronize the audio and
video tracks when we multiplex them. The -ao fast -vc null and -vo null
speed up the rip process.
bash$ mplayer -ao pcm:fast:waveheader:file=audio.wav -vc null -vo null -chapter 4-4 dvd://2
Once the audio is in wav format, you could use the normal utilities to code as mp2, mp3, ogg, or ac3, for instance:
bash$ ffmpeg -i audio.wav -ab 256 -ar 48000 -ac 2 -acodec ac3 -y audio.ac3
As far as I can tell, subsequent encoding preserves the synchronization info.
Ripping DVD-Video using mplayer -dumpvideo
The easiest way I know to rip the video from a legitimate dvd-video is by using the mplayer -dumpvideo option, like this:
bash$ mplayer -dumpvideo -dumpfile video.m2v -chapter 5-5 dvd://2
The -chapter switch is very handy. This example rips the fifth chapter
of the second title. If the start and end positions do not fall on
chapter boudaries, then the -ss and -endpos switches may be
used to define a start position and a duration:
bash$ mplayer -ss 00:05:00 -endpos 00:00:20 -dvd-device /dev/disk5 dvd://3
Device Names in Mac OS X
In Mac OS X the drives are typically numbered, starting with /dev/disk0 then /dev/disk1, etc. In mplayer, the dvd device name may be specified using the -dvd-device switch:
bash$ mplayer -dvd-device /dev/disk4 dvd://1
It is important that the dvd not be mounted.
Mac OS X auto mounts and auto plays DVD-video discs, therefore it may
be necessary to use Disk Utility to unmount the dvd filesystem (or use
the umount command in a terminal window).
Device Names in Debian PPC
Under debian PPC the device names follow the usual /dev/hda, /dev/hdb for internal devices. But usb drives use the /dev/sr0 sequence of device names, like this:
bash# growisofs -dvd-compat -Z /dev/sr0=dvd_image.iso
Two Pass DIVX Encoding with mplayer
Mplayer can do two pass divx encoding, like this:
bash$ mencoder input.mpg -idx -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=750:aspect=1.33/1.0 -oac copy -o output.avi
bash$ mencoder input.mpg -idx -ovc lavc -lavcopts vcodec=mpeg4:vpass=2:vbitrate=750:aspect=1.33/1.0 -oac copy -o output.avi
In this case, I added the -idx switch because sometimes the resulting avi file lacks proper indexing.
Tovid Hints
I really like the tovid suite,
which converts just about any video clip to a dvd (or vcd or svcd)
compatible format. tovid uses mplayer, and I learned a lot about
mplayer by examining the tovid log file. For instance, here is how
tovid converts the audio:
mplayer -quiet -vc null -vo null -ao pcm:waveheader:file=audiodump.wav kangaroo.avi
ffmpeg -i audiodump.wav -ab 224 -ar 48000 -ac 2 -acodec ac3 -y kangaroo.ac3
Obviously, that is how I learned to use mplayer to generate wave format
audio dumps. Here is how tovid converts the video stream:
mplayer -benchmark -nosound -noframedrop -noautosub \
-vo yuv4mpeg -vf-add scale=720:480 kangaroo.AVI
cat stream.yuv | yuvfps -r 30000:1001 -v 0 | \
nice -n 0 mpeg2enc --sequence-length 4300 \
--nonvideo-bitrate 304 --aspect 2 -f 8 -b 7840 -g 4 \
-G 11 -D 10 -K hi-res --frame-rate 4 -v 0 \
--video-norm n --reduction-4x4 2 \
--reduction-2x2 1 -q 5 -o kangaroo.m2v
This is a hugely interesting command. The mplayer command generates a
yuv stream from the original video file kangaroo.avi. The yuv stream is
stored in the special FIFO file stream.yuv. The stream first gets
processed by the yuvfps utility, which sets the frame rate (in this
case to the NTSC standard) and then gets processed by mpeg2enc into a
mpeg2 encoded video file.