Convert .opus and .m4a files to .mp3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.28; | |
use warnings; | |
use Path::Tiny; | |
use String::ShellQuote; | |
my $dir = path(shift // '..'); | |
# Convert the .opus files by piping to opusdec first. | |
# This creates a WAV, which sox will convert to MP3. | |
# | |
for my $path ($dir->children(qr/\.opus\z/)) { | |
say $path; | |
my $infile = shell_quote $path; | |
# say $infile; | |
my $outfile = $path->basename =~ s/\.opus$/.mp3/r; | |
# say $outfile; | |
my @cmd = ('sox', "|opusdec --force-wav $infile -", $outfile); | |
system(@cmd) == 0 or die "system '@cmd' failed: $?"; | |
} | |
# Convert the .m4a files with ffmpeg and LAME. | |
# | |
for my $path ($dir->children(qr/\.m4a\z/)) { | |
say $path; | |
my $infile = shell_quote $path; | |
# say $infile; | |
my $outfile = shell_quote($path->basename =~ s/\.m4a$/.mp3/r); | |
# say $outfile; | |
my $cmd = "ffmpeg -v 5 -y -i $infile -acodec libmp3lame -ac 2 -ab 192k $outfile"; | |
system($cmd) == 0 | |
or die "system '$cmd' failed: $?"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment