I am a man with an mplayer. Luckily, it’s less of a hammer and more of an absurd swiss army knife: there’s nothing it can’t do! The documentation is excellent but overly complicated for a beginner, hence this quick guide to some recipes I’ve found useful. I don’t want to have to work them out from scratch again.
A few days ago I used this to extract the audio from Neil Gaiman’s Authors@Google talk. It ignores the video and dumps the audio straight to a file.
mplayer <input_file> -dumpaudio -dumpfile <output_file>
The downside is that it’s only useful if the audio is playable on its own (in this case it was already an mp3). If not, mencoder can be used to convert arbitrary video files:
mencoder <input_file> -ovc frameno -oac mp3lame -lameopts cbr:br=128 -of rawaudio -o <output_file.mp3>
The -oac option determines the output audio codec; here it’s the LAME mp3 encoder, set by -lameopts to encode as 128kbps CBR.
The method I’ve seen recommended elsewhere is to convert the file into raw PCM audio, typically a .wav file.
mplayer <input_file> -novideo -ao pcm:file=<output_file.wav>
(This also works to extract the audio from a video file, incidentally.)
The downside is that .wav files are huge and useless, so we have to have plenty of spare disk space — 10MB per minute of audio! — and use a separate encoder, like LAME, for compression:
lame --preset medium <input.wav> <output.mp3>
mencoder only works on video files, but there is a dodgy method for forcing it to process audio. The trick is that it’s possible to specify an external audio file — the file we want to convert — to use in place of the video’s real audio stream. We just need a dummy video to pacify it:
mencoder -ovc frameno -oac mp3lame -lameopts cbr:br=128 -of rawaudio -o <output_file.mp3> -audiofile <input_file> <dummy_video_file>
It’s a hack, but it does seem to work. If mplayer can play it, you can convert it, and mplayer can handle just about anything: RealMedia, FLV, AAC…
mencoder <input_file> -o <output_file> -oac copy -ovc copy -ss <start> -endpos <time_since_start>
Setting -oac and -ovc to “copy” — that is, to copy from the streams without encoding them — is fastest, but won’t always work. Try -ovc lavc and -oac mp3lame for decent defaults, or consult the “Encoding with MEncoder” guide for the (extraordinarily complicated) details.
The time format is [[hh:]mm:]ss[.ms]. “15″ is fifteen seconds; “10:05″ is ten minutes and five seconds; “09:10:05″ is nine hours, ten minutes and five seconds.
mplayer <input_file> -noaudio -vo jpeg
-vo gif89a supposedly generates animated GIFs, but I can’t get it to work. Images can be resized or filtered like any other video stream, so that, for example, it’s possible to generate 100×100 thumbnails:
mplayer <input_file> -noaudio -vo jpeg -vf-add scale=100:100
mplayer can play streaming audio and video, so it can rip streaming audio and video. The input file in any of the above examples can be replaced by a URL.