| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
2
|
|
|
|
|
|
|
## Package: Info.pm |
|
3
|
|
|
|
|
|
|
## Author: Benjamin R. Ginter, Allen Day |
|
4
|
|
|
|
|
|
|
## Notice: Copyright (c) 2002 Benjamin R. Ginter, Allen Day |
|
5
|
|
|
|
|
|
|
## Purpose: Retrieve Video Properties |
|
6
|
|
|
|
|
|
|
## Comments: None |
|
7
|
|
|
|
|
|
|
## CVS: $Id |
|
8
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Video::Info; |
|
11
|
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
29080
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
160
|
|
|
13
|
4
|
|
|
4
|
|
2995
|
use Video::Info::Magic; |
|
|
4
|
|
|
|
|
16
|
|
|
|
4
|
|
|
|
|
1159
|
|
|
14
|
4
|
|
|
4
|
|
6380
|
use IO::File; |
|
|
4
|
|
|
|
|
81205
|
|
|
|
4
|
|
|
|
|
1095
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.993'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Class::MakeMethods::Emulator::MethodMaker |
|
19
|
4
|
|
|
|
|
67
|
get_set => [ |
|
20
|
|
|
|
|
|
|
'type', #ASF,MPEG,RIFF... |
|
21
|
|
|
|
|
|
|
'title', #ASF media title |
|
22
|
|
|
|
|
|
|
'author', #ASF author |
|
23
|
|
|
|
|
|
|
'date', #ASF date (units???) |
|
24
|
|
|
|
|
|
|
'copyright', #ASF copyright |
|
25
|
|
|
|
|
|
|
'description', #ASF description (freetext) |
|
26
|
|
|
|
|
|
|
'rating', #ASF MPAA rating |
|
27
|
|
|
|
|
|
|
'packets', #ASF ??? |
|
28
|
|
|
|
|
|
|
'comments', #MPEG |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
'astreams', #no. of audio streams. can this clash with achans? |
|
31
|
|
|
|
|
|
|
#this has special behavior, method is below |
|
32
|
|
|
|
|
|
|
# 'acodec', #audio codec |
|
33
|
|
|
|
|
|
|
'acodecraw', #audio codec (numeric) |
|
34
|
|
|
|
|
|
|
'arate', #audio bitrate |
|
35
|
|
|
|
|
|
|
'afrequency', #audio sampling frequency, in Hz |
|
36
|
|
|
|
|
|
|
'achans', #no. of audio channels. can this clash with astreams? |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
'vstreams', #no. of video streams |
|
39
|
|
|
|
|
|
|
'vcodec', #video codec |
|
40
|
|
|
|
|
|
|
'vrate', #video bitrate |
|
41
|
|
|
|
|
|
|
'vframes', #no. of video frames |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
'fps', #video frames/second |
|
44
|
|
|
|
|
|
|
'scale', #quoeth transcode: if(scale!=0) AVI->fps = (double)rate/(double)scale; |
|
45
|
|
|
|
|
|
|
'duration', #duration of video, in seconds |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
'width', #frame width |
|
48
|
|
|
|
|
|
|
'height', #frame height |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
'aspect_raw', #how to handle this? 16:9 scalar, or 16/9 float? |
|
51
|
|
|
|
|
|
|
'aspect', #not sure what this is. from MPEG |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
'filename', #the sourcefile name |
|
54
|
|
|
|
|
|
|
'filesize', #the size of the source file |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
'_handle', #filehandle to bitstream |
|
57
|
|
|
|
|
|
|
], |
|
58
|
4
|
|
|
4
|
|
9965
|
; |
|
|
4
|
|
|
|
|
54255
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
|
61
|
12
|
|
|
12
|
0
|
15355
|
my $proto = shift; |
|
62
|
12
|
|
33
|
|
|
98
|
my $class = ref($proto) || $proto; |
|
63
|
12
|
|
|
|
|
48
|
my $self = bless {}, $class; |
|
64
|
|
|
|
|
|
|
|
|
65
|
12
|
|
|
|
|
66
|
$self = $self->init(@_); |
|
66
|
|
|
|
|
|
|
|
|
67
|
12
|
|
|
|
|
78
|
return $self; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub init { |
|
71
|
6
|
|
|
6
|
0
|
27
|
my($self,%raw) = @_; |
|
72
|
|
|
|
|
|
|
# my($proto,%raw) = @_; |
|
73
|
|
|
|
|
|
|
# my $class = ref($proto) || $proto; |
|
74
|
|
|
|
|
|
|
# my $self = bless {}, $class; |
|
75
|
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
12
|
my %param; |
|
77
|
6
|
|
|
|
|
61
|
foreach(keys %raw){/^-?(.+)/;$param{$1} = $raw{$_}}; |
|
|
6
|
|
|
|
|
33
|
|
|
|
6
|
|
|
|
|
39
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
6
|
50
|
|
|
|
27
|
if($param{file}){ |
|
80
|
6
|
|
|
|
|
10
|
my($filetype,$handler) = @{ divine($param{file}) }; |
|
|
6
|
|
|
|
|
32
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
6
|
50
|
|
|
|
24
|
if($handler){ |
|
83
|
6
|
|
|
|
|
18
|
my $class = __PACKAGE__ . '::' . $handler; |
|
84
|
|
|
|
|
|
|
|
|
85
|
6
|
100
|
|
|
|
21
|
$class = 'MP3::Info' if $handler eq 'MP3'; |
|
86
|
|
|
|
|
|
|
|
|
87
|
6
|
|
|
|
|
2616
|
my $has_class = eval "require $class"; |
|
88
|
6
|
|
|
|
|
98744
|
$param{subtype} = $filetype; |
|
89
|
|
|
|
|
|
|
|
|
90
|
6
|
50
|
|
|
|
29
|
if($has_class){ |
|
91
|
6
|
100
|
|
|
|
25
|
if($handler eq 'MP3'){ |
|
92
|
2
|
|
|
|
|
27
|
$self = $class->new( $param{file} ); |
|
93
|
2
|
|
|
|
|
4402
|
return $self; |
|
94
|
|
|
|
|
|
|
} else { |
|
95
|
4
|
|
|
|
|
131
|
$self = $class->new(%param); |
|
96
|
4
|
|
|
|
|
107
|
$self->probe( $param{file}, [ $filetype, $handler ] ); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
6018
|
$self->{$_} = $param{$_} foreach(keys %param); |
|
103
|
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
29
|
$self->init_attributes(%param) ; |
|
105
|
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
63
|
$self->probe( $param{file} ); |
|
107
|
|
|
|
|
|
|
|
|
108
|
4
|
|
|
|
|
37
|
return $self; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub init_attributes { |
|
112
|
8
|
|
|
8
|
0
|
23
|
my $self = shift; |
|
113
|
8
|
|
|
|
|
32
|
my %raw = @_; |
|
114
|
8
|
|
|
|
|
17
|
my %param; |
|
115
|
8
|
|
|
|
|
33
|
foreach(keys %raw){/^-?(.+)/;$param{$1} = $raw{$_}}; |
|
|
13
|
|
|
|
|
69
|
|
|
|
13
|
|
|
|
|
72
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
8
|
|
|
|
|
32
|
foreach my $attr (qw( |
|
118
|
|
|
|
|
|
|
astreams arate achans vstreams vrate vframes fps |
|
119
|
|
|
|
|
|
|
scale duration width height aspect aspect_raw |
|
120
|
|
|
|
|
|
|
) |
|
121
|
|
|
|
|
|
|
) { |
|
122
|
104
|
|
|
|
|
4753
|
$self->$attr(0); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
8
|
|
|
|
|
306
|
$self->filename($param{file}); |
|
126
|
8
|
|
|
|
|
606
|
$self->filesize(-s $param{file}); |
|
127
|
8
|
50
|
|
|
|
138
|
$self->handle($param{file}) if $param{file}; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
131
|
|
|
|
|
|
|
## Extra methods |
|
132
|
|
|
|
|
|
|
## |
|
133
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
134
|
|
|
|
|
|
|
sub acodec { |
|
135
|
10
|
|
|
10
|
1
|
6888
|
my($self,$arg) = @_; |
|
136
|
10
|
100
|
|
|
|
54
|
if($arg){ |
|
|
|
100
|
|
|
|
|
|
|
137
|
4
|
|
|
|
|
35
|
$self->{acodec} = acodec2str($arg); |
|
138
|
|
|
|
|
|
|
} elsif(!$self->{acodec}){ |
|
139
|
1
|
|
|
|
|
32
|
$self->{acodec} = acodec2str($self->acodecraw); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
10
|
|
|
|
|
49
|
return $self->{acodec}; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub minutes { |
|
145
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
146
|
0
|
|
|
|
|
0
|
my $seconds = int($self->duration) % 60; |
|
147
|
0
|
|
|
|
|
0
|
my $minutes = (int($self->duration) - $seconds) / 60; |
|
148
|
0
|
|
|
|
|
0
|
return $minutes; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub MMSS { |
|
152
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
153
|
0
|
|
|
|
|
0
|
my $mm = $self->minutes; |
|
154
|
0
|
|
|
|
|
0
|
my $ss = int($self->duration) - ($self->minutes * 60); |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
0
|
my $return = sprintf( "%02d:%02d",$mm,$ss ); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
160
|
|
|
|
|
|
|
## handle() |
|
161
|
|
|
|
|
|
|
## |
|
162
|
|
|
|
|
|
|
## Open a file handle or return an existing one |
|
163
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
164
|
|
|
|
|
|
|
sub handle { |
|
165
|
16
|
|
|
16
|
0
|
35
|
my($self,$file) = @_; |
|
166
|
|
|
|
|
|
|
|
|
167
|
16
|
100
|
|
|
|
56
|
if(defined $file){ |
|
168
|
8
|
|
|
|
|
80
|
my $fh = new IO::File; |
|
169
|
8
|
|
|
|
|
399
|
$fh->open($file); |
|
170
|
8
|
|
|
|
|
9790
|
$self->_handle($fh); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
16
|
|
|
|
|
662
|
return $self->_handle; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
176
|
|
|
|
|
|
|
## probe() |
|
177
|
|
|
|
|
|
|
## |
|
178
|
|
|
|
|
|
|
## Open a video file and gather the stats |
|
179
|
|
|
|
|
|
|
##------------------------------------------------------------------------ |
|
180
|
|
|
|
|
|
|
sub probe { |
|
181
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
182
|
0
|
|
0
|
|
|
|
my $file = shift || die "probe(): A filename argument is required.\n"; |
|
183
|
0
|
|
0
|
|
|
|
my $type = shift || divine($file) || die "probe(): Couldn't divine $file"; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $warn; |
|
186
|
0
|
0
|
|
|
|
|
if ( $type->[1] ) { |
|
187
|
0
|
|
|
|
|
|
$warn .= "s of type $type->[1]\n"; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
else { |
|
190
|
0
|
|
|
|
|
|
$warn .= " type $type->[0]\n"; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
0
|
|
|
|
|
|
warn( ref( $self ), |
|
193
|
|
|
|
|
|
|
'::probe() abstract method -- Create a child class for file', |
|
194
|
|
|
|
|
|
|
$warn ); |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
__END__ |