/ Home  / Blog

backlinks: /index/TechBits

Convert ogg to mp3

There is so much crap out there when searching for codec conversions. Here is a simple Perl script that does the conversion. It assumes you have oggdec and lame in the path.

#!/usr/bin/perl -w

# Convert a directory of .ogg to .mp3

sub systemprint
    my $cmd = shift;

    print "$cmd\n";
    system( $cmd );

foreach my $oggPath ( glob("*.ogg") )
    my $mp3Path = $oggPath;
    $mp3Path =~ s/\.ogg$/.mp3/;
    my $wavPath = $oggPath;
    $wavPath =~ s/\.ogg$/.wav/;

    systemprint( "oggdec -o \"$wavPath\" \"$oggPath\"" );
    systemprint( "lame -b 256 \"$wavPath\" \"$mp3Path\"" );