-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathconv
More file actions
executable file
·107 lines (89 loc) · 3.01 KB
/
conv
File metadata and controls
executable file
·107 lines (89 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl
die "usage: $0 <from file> <to file> | <to format> <files ...>\nconverts any file format to another\n" unless @ARGV;
my $FFMPEG = "/opt/local/bin/ffmpeg";
my ($a, $b, $type1, $type2);
my $default = "mp3";
my %default = (
"wav" => "mp3",
"aif" => "mp3",
"aiff" => "mp3",
"flac" => "mp3",
"mov" => "mp3",
"flv" => "mp3",
"mpg" => "mp3",
"mkv" => "mp3",
"avi" => "mp3",
"png" => "jpg",
"webp" => "jpg",
);
# to format, files
if (@ARGV == 1)
{
$b = $a;
$b =~ s/(\w+)$/$default{$1} || $default/e;
$type2 = $default{$1} || $default;
}
elsif (@ARGV > 2 || (@ARGV == 2 && !-e $ARGV[0]))
{
$type2 = shift @ARGV;
foreach $a (@ARGV)
{
($b = $a) =~ s/(\w+)$/$type2/;
$type1 = $1;
conv($a, $b, $type1, $type2);
}
exit;
}
else
{
($a, $b) = @ARGV;
}
$type1 = lc($1) if $a =~ /(\w+)$/;
$type2 = lc($1) if $b =~ /(\w+)$/;
conv($a, $b, $type1, $type2);
sub conv
{
my ($a, $b, $type1, $type2) = @_;
my %types = (
"webm-aiff" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"mov-aiff" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"mov-aif" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"mp4-aiff" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"mp4-aif" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"flv-aiff" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"flv-aif" => [$FFMPEG, "-i", $a, "-f", "aiff", "-ab", "320000", "-vn", $b],
"webm-wav" => [$FFMPEG, "-i", $a, "-f", "wav", "-ab", "320000", "-vn", $b],
"mp4-wav" => [$FFMPEG, "-i", $a, "-f", "wav", "-ab", "320000", "-vn", $b],
"mov-wav" => [$FFMPEG, "-i", $a, "-f", "wav", "-ab", "320000", "-vn", $b],
"flv-wav" => [$FFMPEG, "-i", $a, "-f", "wav", "-ab", "320000", "-vn", $b],
"webm-mp3" => [$FFMPEG, "-i", $a, "-f", "mp3", "-ab", "320000", "-vn", $b],
"mp4-mp3" => [$FFMPEG, "-i", $a, "-f", "mp3", "-ab", "320000", "-vn", $b],
"mov-mp3" => [$FFMPEG, "-i", $a, "-f", "mp3", "-ab", "320000", "-vn", $b],
"flv-mp3" => [$FFMPEG, "-i", $a, "-f", "mp3", "-ab", "320000", "-vn", $b],
"aif-mp3" => ["sox", "-V3", $a, "-C", "320", $b],
"aiff-mp3" => ["sox", "-V3", $a, "-C", "320", $b],
"flac-mp3" => ["sox", "-V3", $a, "-C", "320", $b],
#"m4a" => ["faad -o - 04\ Kiss\ Kiss\ Bang\ Bang.m4a | lame - "
#"mp4-mov" => [$FFMPEG, "-i", $a, $b],
"webm" => [$FFMPEG, "-i", $a, $b],
"mov" => [$FFMPEG, "-i", $a, $b],
"mp4" => [$FFMPEG, "-i", $a, $b],
"mp3" => ["sox", "-V3", $a, "-C", "320", $b],
"wav" => ["sox", "-V3", $a, "-C", "320", $b],
"jpg" => ["convert", "-verbose", $a, $b],
"png" => ["convert", "-verbose", $a, $b],
"gif" => ["convert", "-verbose", $a, $b],
"bmp" => ["convert", "-verbose", $a, $b],
);
my $out = $types{"$type1-$type2"} || $types{$type2};
if ($type1 eq $type2)
{
die "Can't convert to the same type ($type1)\n";
}
if (!$out)
{
die "Don't understand type $type1 or $type2\n";
}
print "> " . join(" ", @{$out}) . "\n";
system(@{$out});
}