#!/usr/bin/env perl use strict; use warnings; die "Usage: $0 file1.wav file2.wav ...\n" if @ARGV == 0; chomp(my $ffmpeg = `which ffmpeg`); if ($ffmpeg =~ /^\s*$/) { die "ffmpeg is not installed. Please install it and try again.\n"; } foreach my $wavfile (@ARGV) { if ($wavfile =~ /\.wav$/i) { # Remove the .wav extension to create the .m4a file name my $m4afile = $wavfile; $m4afile =~ s/\.wav$/.m4a/i; # Execute ffmpeg command to convert the file my $command = "ffmpeg -i \"$wavfile\" -c:a aac -b:a 192k \"$m4afile\""; print "Converting $wavfile to $m4afile...\n"; system($command) == 0 or warn "Failed to convert $wavfile: $!\n"; } else { warn "Skipping $wavfile: not a .wav file.\n"; } }