line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FLV::ToMP3; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52998
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
32
|
use 5.008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
514
|
use FLV::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
8
|
use FLV::Util; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
151
|
|
9
|
1
|
|
|
1
|
|
6
|
use FLV::AudioTag; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
5
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
521
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
494
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.24'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=for stopwords MP3 transcodes framerate |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
FLV::ToMP3 - Convert audio from a FLV file into an MP3 file |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 LICENSE |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
See L |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use FLV::ToMP3; |
28
|
|
|
|
|
|
|
my $converter = FLV::ToMP3->new(); |
29
|
|
|
|
|
|
|
$converter->parse_flv($flv_filename); |
30
|
|
|
|
|
|
|
$converter->save($mp3_filename); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
See also L. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Extracts audio data from an FLV file and constructs an MP3 file. See |
37
|
|
|
|
|
|
|
the L command-line program for a nice interface and a |
38
|
|
|
|
|
|
|
detailed list of caveats and limitations. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item $pkg->new() |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Instantiate a converter. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new |
51
|
|
|
|
|
|
|
{ |
52
|
3
|
|
|
3
|
1
|
2113
|
my $pkg = shift; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
32
|
my $self = bless { flv => FLV::File->new() }, $pkg; |
55
|
3
|
|
|
|
|
23
|
$self->{flv}->empty(); |
56
|
3
|
|
|
|
|
7
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item $self->parse_flv($flv_filename) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Open and parse the specified FLV file. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub parse_flv |
66
|
|
|
|
|
|
|
{ |
67
|
3
|
|
|
3
|
1
|
18
|
my $self = shift; |
68
|
3
|
|
|
|
|
5
|
my $infile = shift; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
17
|
$self->{flv}->parse($infile); |
71
|
2
|
|
|
|
|
13
|
$self->{flv}->populate_meta(); |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
15
|
$self->_validate(); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
7
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _validate |
79
|
|
|
|
|
|
|
{ |
80
|
7
|
|
|
7
|
|
12
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
7
|
|
|
|
|
39
|
my $acodec = $self->{flv}->get_meta('audiocodecid'); |
83
|
7
|
100
|
|
|
|
24
|
if (!defined $acodec) |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
|
|
|
|
7
|
die "No audio data found\n"; |
86
|
|
|
|
|
|
|
} |
87
|
6
|
100
|
|
|
|
17
|
if ($acodec != 2) |
88
|
|
|
|
|
|
|
{ |
89
|
1
|
|
|
|
|
12
|
die "Audio format $AUDIO_FORMATS{$acodec} not supported; " |
90
|
|
|
|
|
|
|
. "only MP3 audio allowed\n"; |
91
|
|
|
|
|
|
|
} |
92
|
5
|
|
|
|
|
14
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item $self->save($mp3_filename) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Write out an MP3 file. Note: this is usually called only after |
98
|
|
|
|
|
|
|
C. Throws an exception upon error. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub save |
103
|
|
|
|
|
|
|
{ |
104
|
5
|
|
|
5
|
1
|
19816
|
my $self = shift; |
105
|
5
|
|
|
|
|
10
|
my $outfile = shift; |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
21
|
$self->_validate(); |
108
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
34
|
my $outfh = FLV::Util->get_write_filehandle($outfile); |
110
|
3
|
100
|
|
|
|
8
|
if (!$outfh) |
111
|
|
|
|
|
|
|
{ |
112
|
1
|
|
|
|
|
15
|
die 'Failed to write MP3 file: ' . $OS_ERROR; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
2
|
|
|
|
|
16
|
for my $tag ($self->{flv}->{body}->get_tags()) |
116
|
|
|
|
|
|
|
{ |
117
|
870
|
100
|
|
|
|
2550
|
next if (!$tag->isa('FLV::AudioTag')); |
118
|
570
|
|
|
|
|
566
|
print {$outfh} $tag->{data}; |
|
570
|
|
|
|
|
2206
|
|
119
|
|
|
|
|
|
|
} |
120
|
2
|
50
|
|
|
|
129
|
close $outfh or die 'Failed to finish writing file'; |
121
|
2
|
|
|
|
|
17
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |