Skip to content

Instantly share code, notes, and snippets.

@schuhiti
Last active December 14, 2015 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schuhiti/5023567 to your computer and use it in GitHub Desktop.
Save schuhiti/5023567 to your computer and use it in GitHub Desktop.
translate files to m4a by ffmpeg. using perl under Windows bat file.
@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!perl
#line 15
use strict;
use warnings;
use feature qw/say/;
use Encode qw/decode encode/;
use File::Basename qw/fileparse/;
use File::Path;
exit_with_help() unless scalar @ARGV;
my @files;
my @cmd = qw/ffmpeg -vn -acodec copy -i/;
foreach my $file (@ARGV) {
next unless -e -s -f $file;
$file = decode("CP932", $file);
my ($name, $dir, $ext) = fileparse($file, qr/\.[a-zA-Z0-9]+$/);
system (@cmd, encode("CP932", $file),
encode("CP932", File::Spec->catfile($dir, $name . ".m4a"))
);
}
sub exit_with_help {
my $mes = shift // "perl $0 file [file ...]";
say $mes;
exit;
}
__END__
:endofperl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment