#!/usr/bin/perl # realtomp3: convert realaudio .rm to .mp3 # This version works with realplayer version 10 # This program depends on the programs realplay, vsound, and lame or notlame # or some mp3 encoder. # Tested under linux. =head1 Usage: realtomp3 file1.rm file2.ra ... Converts each realaudio file given on command line to mp3. The file can be a network location, eg. realtomp3 pnm://streamer.loc.com/content.rm For each file on the command line, all characters after the final '/' are taken to be the name of the realaudio file. So if your location has additional characters (giving title, etc.) you must stript them off. The realaudio file is expected to have a file extention that consists of a string of letters beginning with 'r', for example .ra, .rm, .rmj. An intermediate .wav file is created and is deleted after being converted to mp3 The program works as follows for each real audio file. Realplay and vsound are launched to play the file. Output goes to the sound card and vsound also captures the audio (in the raw digital form) and streams it to a temporary file. realtomp3 monitors realplay to see when it is done playing the file, after which, realplay just waits for gui input. realtomp3 then kills the realplay process. vsound sees that the realplay process is killed and converts its temporary sound file to wav format. Finally the encoder encodes the wav file to mp3. The original real audio file is preserved, the other temporary files are removed. This program assumes no other realplay processes are being run. (eg by other users). The encoder used can the command line switches are set in the variable $Encoder below. =cut use Getopt::Long; $Encoder = "lame -S -h "; sub dosys; sub debug; sub mssg; $optret = &GetOptions ( 'keepwav' => \$keepwav, 'b:i' => \$bitrate); # each arg is name of rm file (fully qualified path) foreach $rmfile ( @ARGV ) { # .wav format file (needed for intermediate stage) $wavefile = $rmfile; # just copy $wavefile =~ m/([^\/]+)$/; # find just the file name if it is a network # location or fully qualified pathname. $wavefile = $1; $mp3file = $wavefile; $wavefile =~ s/\.r[a-z]+$/\.wav/; # change extension for wav file # .mp3 format file $mp3file =~ s/\.r[a-z]+$/\.mp3/; # change extension for mp3 file # run through realplay to get wavefile dosys "vsound -t -d -f $wavefile realplay -q $rmfile"; # vsound and realplay are done, so encode to mp3 $flags = ''; if ( defined $bitrate and $bitrate > 0) { $flags .= " -b $bitrate "; } if ( defined $keepwav and $keepwav == 1 ) { dosys "$Encoder $flags $wavefile $mp3file"; } else { dosys "$Encoder $flags $wavefile $mp3file && rm -f $wavefile"; } } sub mssg { my $s = shift; print STDERR "$s\n"; } sub dosys { my $c =shift; print $c,"\n"; system $c; } sub debug { my $s = shift; # print STDERR "$s\n"; }