Convert m4a to mp3.pl

From Colettapedia
Jump to navigation Jump to search
  • must have the command line tools faad2 and lame to work
    • use MacPorts to install: sudo port install faad2 lame
  • then put this code in a file called convert_m4a_to_mp3.pl, chmod +x it and run from the top level dir containing files
#!/usr/bin/perl

use warnings;
use strict;

my @files = `find . -name "*.m4a"`;
foreach (@files) {
	chomp;
	print $_ . "\n";
	my $newname = $_;
	my $orig = $_;
	$newname =~ s/m4a/mp3/;
	print $newname . "\n";
	my $cmd = "faad -o - \"$orig\" | lame - \"$newname\"";
	print $cmd . "\n";
	system( $cmd );
	unlink( $orig );
}
1;