root/gs2-extensions/music-ir-src/trunk/bin/script/convert_mp3_to_wav.pl @ 29657

Revision 29657, 1.0 KB (checked in by jmt12, 6 years ago)

little script to convert a directory of MP3s into WAVs

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6print "\n===== Convert MP3s to WAVs =====\n";
7print "Converts a directory of MP3s into a directory of WAVs, replacing old\n";
8print "filenames with simple numbering.\n\n";
9
10if (!defined $ARGV[0] || !-d $ARGV[0])
11{
12  print "Error! Missing input directory or directory doesn't exist\n";
13  print "usage: convert_mp3_to_wav.pl <input directory> <output directory>\n\n";
14  exit();
15}
16if (!defined $ARGV[1] || !-d $ARGV[1])
17{
18  print "Error! Missing output directory or directory doesn't exist\n";
19  print "usage: convert_mp3_to_wav.pl <input directory> <output directory>\n\n";
20  exit();
21}
22
23opendir(DH, $ARGV[0]) or die "Failed to open directory for reading: ./import.mp3";
24my @files = readdir(DH);
25closedir(DH);
26
27my $counter = 0;
28foreach my $file (@files)
29{
30  if ($file =~ /\.mp3$/)
31  {
32    $counter++;
33    my $cmd = 'ffmpeg -i "' . $ARGV[0] . '/' . $file . '" "' . $ARGV[1] . '/' . sprintf("%04d", $counter) . '.wav"';
34    print $cmd . "\n";
35    `$cmd`;
36  }
37}
38
39print "Complete!\n\n";
40
41exit;
421;
Note: See TracBrowser for help on using the browser.