[Flac-dev] FLAC to mp3 batch converter?

Jason L. Cook jason at siliconashes.net
Tue Apr 2 12:33:46 PST 2002


Here's an extremely quick-and-dirty Perl script I wrote to do just that. 
This script depends on having the MP3::Info Perl module for ID3 tag 
information, and assumes that you have lame set up. It will take a flac 
file (or a wildcard) as an argument, decompress that file, and encode it 
as a fairly high-bitrate VBR MP3.

I want to stress that this is just something I wrote for my needs, so it 
outputs filenames the way I like them, and assumes a great deal about 
the environment in which it's run.

Hope this helps...

Cheers,
  -Jason


Christian Lambert wrote:

>I'm just wondering if someone wrote a perl script to convert
>a directory with flac files into mp3 and preserving the id3 tag
>from flac to mp3? 
>
>I have two harddrives where I keep my favorite CDs in flac and others in mp3 but 
>when I get tired of them, I move them into mp3 and rather than popping the
>original CD in, it might be easier to just convert from flac to mp3 directly.
>
>Please cc me on your reply.  clambert at sgi.com
>
>Let me know
>
>
>_______________________________________________
>Flac-dev mailing list
>Flac-dev at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/flac-dev
>


-------------- next part --------------
#!/usr/bin/perl

use MP3::Info;

foreach $file (@ARGV) {
  if (!($file =~ /\.flac$/)) {
    print "Skipping $file\n";
    next;
  }
  if ($tag = get_mp3tag($file)) {
    $artist = $tag->{ARTIST};
    $title = $tag->{TITLE};
    $album = $tag->{ALBUM};
    $track = $tag->{TRACKNUM};
    chomp($artist);
    chomp($title);
    chomp($album);
    chomp($track);
    $track = sprintf("%2.2d", $track);
  } else {
    print "Couldn't get MP3 tag for $file.\n";
  } 
  `flac -d "$file"`;
  $file =~ s/\.flac$/.wav/;
  if (($artist) && ($title) && ($track)) {
    $outfile = "$artist - ($track)$title.mp3";
  } else {
    $outfile = $file;
    $outfile =~ s/\.wav$/.mp3/;
  }
  `lame -V -b128 -B256 --tt "$title" --ta "$artist" --tl "$album" --tn $track "$file" "$outfile"`;
  `rm "$file"`;
  print "-------------------------------------------\n";
}




More information about the Flac-dev mailing list