Sunday, January 31, 2010

Here is the perl script to convert .rm files to .mp3 format on linux. Needed this script since my DVD player cannot play .rm files. Script needs the following software to work
  1. Perl
  2. mplayer
  3. lame
  4. wget
The script can download rm or ram files and then process the download .rm files to produce the .mp3 file.
#!/usr/bin/perl -w
use strict;


&usage if @ARGV!=1;
my $fileName=shift;
&usage if ($fileName !~ m#\.(ram|rm)$#);
&process_ram($fileName) if ($fileName =~ m|\.ram$|);
&process_rm($fileName) if ($fileName =~ m|\.rm$|);

sub usage(){
print STDERR "usage: $0 filename.rm/ram\n";
exit 1;

sub process_ram(){
my $fileName=shift;
open RAM_FILE, $fileName || die "Failed To Process File: $!";
chop if ~ m/\r$/;
$_ = &processUrl($_);
close RAM_FILE;

sub process_rm(){
my $fileName=shift;

sub convertToMp3(){
my $fileName=shift;
chop($fileName) if $fileName =~ m/\r$/;
print "Processing File...$fileName";
my ($dirName,$baseName)=&dirname($fileName);
$baseName =~ s/\.rm/.mp3/;
die "Invalid File: ${fileName}" unless(-e $fileName);
`mplayer $fileName -ao pcm 2>/dev/null`;
`lame -h -b 128 audiodump.wav $dirName/$baseName`;
`rm audiodump.wav`;

sub dirname(){
return (".",$_[0]) unless $_[0] =~ m|^/|;
return $_[0]=~ m|(.*/)(.*)$|;
sub processUrl(){
my $fileName=shift;
return $fileName =~ m|.*/(.*)$|,$1;
return $fileName;

sub isUrl(){
$_[0] =~ m/^http.*/;

sub download(){
print "Downloading File...$_[0]";
system("wget -c $_[0]")==0 || die "Failed to download file: $_[0]";


Prashant Bhate said...

Thats really cool !!

But will the quality degrage during this conversion, .rm being highly compressed format?

Sriki said...

It doesn't as far i have experienced