line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Timecode; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
21631
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
138
|
|
4
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
238
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
5
|
|
|
|
|
27
|
'+' => '_add', |
7
|
|
|
|
|
|
|
'-' => '_subtract', |
8
|
|
|
|
|
|
|
'*' => '_multiply', |
9
|
|
|
|
|
|
|
'/' => '_divide', |
10
|
|
|
|
|
|
|
'cmp' => '_compare', |
11
|
|
|
|
|
|
|
'<=>' => '_compare', |
12
|
5
|
|
|
5
|
|
6110
|
'""' => 'to_string'; |
|
5
|
|
|
|
|
4747
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
2898
|
use POSIX (); |
|
5
|
|
|
|
|
28152
|
|
|
5
|
|
|
|
|
112
|
|
15
|
5
|
|
|
5
|
|
26
|
use Carp (); |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
570
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $DEFAULT_FPS = 29.97; |
20
|
|
|
|
|
|
|
our $DEFAULT_DROPFRAME = 0; |
21
|
|
|
|
|
|
|
our $DEFAULT_DELIMITER = ':'; |
22
|
|
|
|
|
|
|
our $DEFAULT_FRAME_DELIMITER = $DEFAULT_DELIMITER; |
23
|
|
|
|
|
|
|
our $DEFAULT_TO_STRING_FORMAT = ''; # If not set $TO_STRING_FORMAT is used |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $SECONDS_PER_MINUTE = 60; |
26
|
|
|
|
|
|
|
my $SECONDS_PER_HOUR = $SECONDS_PER_MINUTE * 60; |
27
|
|
|
|
|
|
|
my $TO_STRING_FORMAT = '%02s%s%02s%s%02s%s%02s'; #HH:MM:SS:FF |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $TIME_PART = qr|[0-5]\d|; |
30
|
|
|
|
|
|
|
my $DROP_FRAME_DELIMITERS = '.;'; #, too? |
31
|
|
|
|
|
|
|
my $FRAME_PART_DELIMITERS = "${DEFAULT_DELIMITER}${DROP_FRAME_DELIMITERS}"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
34
|
5
|
|
|
5
|
|
20
|
no strict 'refs'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
9872
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my @methods = qw|hours minutes seconds frames fps is_dropframe total_frames|; |
37
|
|
|
|
|
|
|
my %method_aliases = ( |
38
|
|
|
|
|
|
|
hours => ['hh', 'hrs'], |
39
|
|
|
|
|
|
|
minutes => ['mm', 'mins'], |
40
|
|
|
|
|
|
|
seconds => ['ss', 'secs'], |
41
|
|
|
|
|
|
|
frames => ['ff'] |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
for my $accessor (@methods) { |
45
|
1124
|
|
|
1124
|
|
3229
|
*$accessor = sub { (shift)->{$accessor} }; |
46
|
|
|
|
|
|
|
*$_ = \&$accessor for @{$method_aliases{$accessor}}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new |
51
|
|
|
|
|
|
|
{ |
52
|
79
|
50
|
33
|
79
|
1
|
1525
|
Carp::croak 'usage: Time::Timecode->new( TIMECODE [, OPTIONS ] )' if @_ < 2 || !defined($_[1]); |
53
|
|
|
|
|
|
|
|
54
|
79
|
|
|
|
|
74
|
my $class = shift; |
55
|
79
|
100
|
|
|
|
194
|
my $options = ref($_[-1]) eq 'HASH' ? pop : {}; |
56
|
|
|
|
|
|
|
my $self = bless { is_dropframe => $options->{dropframe}, |
57
|
|
|
|
|
|
|
frame_delimiter => $options->{frame_delimiter}, |
58
|
|
|
|
|
|
|
delimiter => $options->{delimiter} || $DEFAULT_DELIMITER, |
59
|
79
|
|
66
|
|
|
376
|
fps => $options->{fps} || $DEFAULT_FPS }, $class; |
|
|
|
66
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
79
|
100
|
|
|
|
879
|
Carp::croak "Invalid fps '$self->{fps}': fps must be >= 0" unless $self->{fps} =~ /\A\d+(?:\.\d+)?\z/; |
62
|
|
|
|
|
|
|
|
63
|
78
|
100
|
100
|
|
|
310
|
if(@_ == 1 && $_[0] !~ /^\d+$/) { |
64
|
12
|
|
|
|
|
27
|
$self->_timecode_from_string( shift ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
|
|
|
|
|
|
# For string timecodes these can be derrived by their format |
68
|
66
|
100
|
|
|
|
103
|
$self->{is_dropframe} = $DEFAULT_DROPFRAME unless defined $self->{is_dropframe}; |
69
|
66
|
|
66
|
|
|
158
|
$self->{frame_delimiter} ||= $DEFAULT_FRAME_DELIMITER; |
70
|
|
|
|
|
|
|
|
71
|
66
|
100
|
|
|
|
75
|
if(@_ == 1) { |
72
|
52
|
|
|
|
|
79
|
$self->_timecode_from_total_frames( shift ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
|
|
|
|
|
|
# Add frames if necessary |
76
|
14
|
100
|
|
|
|
30
|
push @_, 0 unless @_ == 4; |
77
|
14
|
|
|
|
|
27
|
$self->_set_and_validate_time(@_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
75
|
50
|
|
|
|
104
|
if ($self->_is_deprecated_dropframe_rate) { |
82
|
0
|
|
|
|
|
0
|
warn<
|
83
|
|
|
|
|
|
|
Time::Timecode warning: versions > 0.3X will not treat drop frame 30 and 60 like 29.97 and 59.94. Use an fps of 29.97 or 59.94 instead. |
84
|
|
|
|
|
|
|
DEPRECATION |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
75
|
|
|
|
|
178
|
$self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub to_string |
91
|
|
|
|
|
|
|
{ |
92
|
26
|
|
|
26
|
1
|
59
|
my $self = shift; |
93
|
26
|
|
66
|
|
|
50
|
my $format = shift || $DEFAULT_TO_STRING_FORMAT; |
94
|
|
|
|
|
|
|
my $tc = sprintf $TO_STRING_FORMAT, $self->hours, |
95
|
|
|
|
|
|
|
$self->{delimiter}, |
96
|
|
|
|
|
|
|
$self->minutes, |
97
|
|
|
|
|
|
|
$self->{delimiter}, |
98
|
|
|
|
|
|
|
$self->seconds, |
99
|
|
|
|
|
|
|
$self->{frame_delimiter}, |
100
|
26
|
|
|
|
|
39
|
$self->frames; |
101
|
|
|
|
|
|
|
|
102
|
26
|
100
|
|
|
|
46
|
if($format) { |
103
|
15
|
|
|
|
|
10
|
my @args; |
104
|
|
|
|
|
|
|
# TODO: Add %X too? |
105
|
15
|
|
|
|
|
18
|
my %formats = (H => $self->hours, |
106
|
|
|
|
|
|
|
M => $self->minutes, |
107
|
|
|
|
|
|
|
S => $self->seconds, |
108
|
|
|
|
|
|
|
f => $self->frames, |
109
|
|
|
|
|
|
|
r => $self->fps, |
110
|
|
|
|
|
|
|
i => $self->total_frames, |
111
|
|
|
|
|
|
|
s => sprintf("%02d", $self->frames/$self->fps*100), |
112
|
|
|
|
|
|
|
T => $tc, |
113
|
|
|
|
|
|
|
'%'=> '%'); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Match printf style formats with optional width and alignment. |
116
|
15
|
|
|
|
|
60
|
($tc = $format) =~ s/(%-?\d*)([HMSfrisT%])/sprintf "${1}s", $formats{$2}/ge |
|
20
|
|
|
|
|
76
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
26
|
|
|
|
|
242
|
$tc; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub convert |
123
|
|
|
|
|
|
|
{ |
124
|
3
|
|
|
3
|
1
|
6
|
my ($self, $fps, $options) = @_; |
125
|
|
|
|
|
|
|
|
126
|
3
|
|
100
|
|
|
10
|
$options ||= {}; |
127
|
3
|
|
|
|
|
6
|
$options->{fps} = $fps; |
128
|
3
|
|
100
|
|
|
9
|
$options->{dropframe} ||= 0; |
129
|
3
|
|
33
|
|
|
11
|
$options->{delimiter} ||= $self->{delimiter}; |
130
|
3
|
|
66
|
|
|
8
|
$options->{frame_delimiter} ||= $self->{frame_delimiter}; |
131
|
|
|
|
|
|
|
|
132
|
3
|
|
|
|
|
5
|
Time::Timecode->new($self->to_non_dropframe->total_frames, $options); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub to_dropframe |
136
|
|
|
|
|
|
|
{ |
137
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
138
|
1
|
50
|
|
|
|
2
|
return $self if $self->is_dropframe; |
139
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
2
|
my $options = $self->_dup_options; |
141
|
1
|
|
|
|
|
2
|
$options->{dropframe} = 1; |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
1
|
Time::Timecode->new($self->total_frames, $options); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub to_non_dropframe |
147
|
|
|
|
|
|
|
{ |
148
|
4
|
|
|
4
|
1
|
4
|
my $self = shift; |
149
|
4
|
100
|
|
|
|
5
|
return $self unless $self->is_dropframe; |
150
|
|
|
|
|
|
|
|
151
|
2
|
|
|
|
|
5
|
my $options = $self->_dup_options; |
152
|
2
|
|
|
|
|
3
|
$options->{dropframe} = 0; |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
3
|
Time::Timecode->new($self->total_frames, $options); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _add |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
_handle_binary_overload(@_, sub { |
160
|
5
|
|
|
5
|
|
11
|
$_[0] + $_[1]; |
161
|
5
|
|
|
5
|
|
24
|
}); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _subtract |
165
|
|
|
|
|
|
|
{ |
166
|
|
|
|
|
|
|
_handle_binary_overload(@_, sub { |
167
|
4
|
|
|
4
|
|
8
|
$_[0] - $_[1]; |
168
|
4
|
|
|
4
|
|
17
|
}); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _multiply |
172
|
|
|
|
|
|
|
{ |
173
|
|
|
|
|
|
|
_handle_binary_overload(@_, sub { |
174
|
1
|
|
|
1
|
|
2
|
$_[0] * $_[1]; |
175
|
2
|
|
|
2
|
|
8
|
}); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _divide |
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
_handle_binary_overload(@_, sub { |
181
|
2
|
|
|
2
|
|
5
|
int($_[0] / $_[1]); |
182
|
2
|
|
|
2
|
|
8
|
}); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _compare |
186
|
|
|
|
|
|
|
{ |
187
|
9
|
|
|
9
|
|
15
|
my ($lhs, $rhs) = _overload_order(@_); |
188
|
9
|
|
|
|
|
15
|
$lhs->total_frames <=> $rhs->total_frames; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _overload_order |
192
|
|
|
|
|
|
|
{ |
193
|
22
|
|
|
22
|
|
21
|
my ($lhs, $rhs, $reversed) = @_; |
194
|
22
|
100
|
66
|
|
|
78
|
$rhs = Time::Timecode->new($rhs) if !ref($rhs) or !$rhs->isa('Time::Timecode'); |
195
|
21
|
100
|
|
|
|
27
|
($lhs, $rhs) = ($rhs, $lhs) if $reversed; |
196
|
21
|
|
|
|
|
24
|
($lhs, $rhs); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub _handle_binary_overload |
200
|
|
|
|
|
|
|
{ |
201
|
13
|
|
|
13
|
|
13
|
my $fx = pop @_; |
202
|
13
|
|
|
|
|
17
|
my ($lhs, $rhs) = _overload_order(@_); |
203
|
12
|
|
|
|
|
16
|
Time::Timecode->new($fx->($lhs->total_frames, $rhs->total_frames), $lhs->_dup_options); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub _dup_options |
207
|
|
|
|
|
|
|
{ |
208
|
15
|
|
|
15
|
|
9
|
my $self = shift; |
209
|
|
|
|
|
|
|
{ fps => $self->fps, |
210
|
|
|
|
|
|
|
dropframe => $self->is_dropframe, |
211
|
|
|
|
|
|
|
delimiter => $self->{delimiter}, |
212
|
15
|
|
|
|
|
17
|
frame_delimiter => $self->{frame_delimiter} }; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub _frames_per_hour |
216
|
|
|
|
|
|
|
{ |
217
|
129
|
|
|
129
|
|
121
|
shift->_rounded_fps * $SECONDS_PER_HOUR; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub _frames_per_minute |
221
|
|
|
|
|
|
|
{ |
222
|
181
|
|
|
181
|
|
176
|
shift->_rounded_fps * $SECONDS_PER_MINUTE; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub _frames |
226
|
|
|
|
|
|
|
{ |
227
|
52
|
|
|
52
|
|
40
|
my ($self, $frames) = @_; |
228
|
52
|
|
|
|
|
57
|
$frames % $self->_rounded_fps; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub _rounded_fps |
232
|
|
|
|
|
|
|
{ |
233
|
439
|
|
|
439
|
|
279
|
my $self = shift; |
234
|
439
|
|
66
|
|
|
986
|
$self->{rounded_fps} ||= POSIX::ceil($self->fps); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub _hours_from_frames |
238
|
|
|
|
|
|
|
{ |
239
|
52
|
|
|
52
|
|
41
|
my ($self, $frames) = @_; |
240
|
52
|
|
|
|
|
51
|
int($frames / $self->_frames_per_hour); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub _minutes_from_frames |
244
|
|
|
|
|
|
|
{ |
245
|
52
|
|
|
52
|
|
44
|
my ($self, $frames) = @_; |
246
|
52
|
|
|
|
|
59
|
int($frames % $self->_frames_per_hour / $self->_frames_per_minute); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub _seconds_from_frames |
250
|
|
|
|
|
|
|
{ |
251
|
52
|
|
|
52
|
|
47
|
my ($self, $frames) = @_; |
252
|
52
|
|
|
|
|
54
|
int($frames % $self->_frames_per_minute / $self->_rounded_fps); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub _valid_frames |
256
|
|
|
|
|
|
|
{ |
257
|
77
|
|
|
77
|
|
64
|
my ($part, $frames, $max) = @_; |
258
|
77
|
50
|
33
|
|
|
510
|
Carp::croak "Invalid frames '$frames': frames must be between 0 and ${ \int($max) }" unless $frames =~ /^\d+$/ && $frames >= 0 && $frames <= $max; |
|
0
|
|
33
|
|
|
0
|
|
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub _valid_time_part |
262
|
|
|
|
|
|
|
{ |
263
|
231
|
|
|
231
|
|
179
|
my ($part, $value) = @_; |
264
|
231
|
100
|
33
|
|
|
1027
|
Carp::croak "Invalid $part '$value': $part must be between 0 and 59" if !defined($value) || $value < 0 || $value > 59; |
|
|
|
66
|
|
|
|
|
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub _set_and_validate_time_part |
268
|
|
|
|
|
|
|
{ |
269
|
308
|
|
|
308
|
|
306
|
my ($self, $part, $value, $validator) = @_; |
270
|
308
|
|
|
|
|
311
|
$validator->($part, $value, $self->fps); |
271
|
307
|
|
|
|
|
446
|
$self->{$part} = int($value); # Can be a string with a 0 prefix: 01, 02, etc... |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub _frames_to_drop { |
275
|
77
|
|
|
77
|
|
81
|
my $self = shift; |
276
|
|
|
|
|
|
|
|
277
|
77
|
50
|
|
|
|
117
|
if (!defined $self->{frames_to_drop}) { |
278
|
77
|
100
|
|
|
|
82
|
$self->{frames_to_drop} = $self->is_dropframe ? POSIX::ceil($self->{fps}*0.066666) : 0; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
77
|
|
|
|
|
95
|
$self->{frames_to_drop}; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub _set_and_validate_time |
285
|
|
|
|
|
|
|
{ |
286
|
25
|
|
|
25
|
|
48
|
my ($self, $hh, $mm, $ss, $ff) = @_; |
287
|
25
|
|
|
|
|
45
|
$self->_set_and_validate_time_part('frames', $ff, \&_valid_frames); |
288
|
25
|
|
|
|
|
42
|
$self->_set_and_validate_time_part('seconds', $ss, \&_valid_time_part); |
289
|
25
|
|
|
|
|
35
|
$self->_set_and_validate_time_part('minutes', $mm, \&_valid_time_part); |
290
|
25
|
|
|
|
|
43
|
$self->_set_and_validate_time_part('hours', $hh, \&_valid_time_part); |
291
|
|
|
|
|
|
|
|
292
|
25
|
|
|
|
|
34
|
my $total = $self->frames; |
293
|
25
|
|
|
|
|
35
|
$total += $self->_rounded_fps * $ss; |
294
|
25
|
|
|
|
|
39
|
$total += $self->_frames_per_minute * $mm; |
295
|
25
|
|
|
|
|
38
|
$total += $self->_frames_per_hour * $hh; |
296
|
|
|
|
|
|
|
|
297
|
25
|
|
|
|
|
30
|
my $total_minutes = $SECONDS_PER_MINUTE * $hh + $mm; |
298
|
25
|
|
|
|
|
37
|
$total -= $self->_frames_to_drop * ( $total_minutes - int($total_minutes / 10) ); |
299
|
|
|
|
|
|
|
|
300
|
25
|
100
|
|
|
|
40
|
Carp::croak "Invalid dropframe timecode: '$self'" unless $self->_valid_dropframe_timecode; |
301
|
24
|
|
|
|
|
45
|
$self->{total_frames} = $total; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
sub _valid_dropframe_timecode |
305
|
|
|
|
|
|
|
{ |
306
|
25
|
|
|
25
|
|
22
|
my $self = shift; |
307
|
25
|
|
66
|
|
|
29
|
!($self->is_dropframe |
308
|
|
|
|
|
|
|
&& $self->seconds == 0 |
309
|
|
|
|
|
|
|
&& ($self->frames == 0 || $self->frames == 1) |
310
|
|
|
|
|
|
|
&& ($self->minutes % 10 != 0)); |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub _set_timecode_from_frames |
314
|
|
|
|
|
|
|
{ |
315
|
52
|
|
|
52
|
|
40
|
my ($self, $frames) = @_; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# We need the true frame rate here, not the rounded |
318
|
52
|
|
|
|
|
56
|
my $fps = $self->{fps}; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
# Support drop frame calculations for known frame rates that don't support them :( |
321
|
|
|
|
|
|
|
# This is in place temporarily for backwards compatibility with $VERSION < 0.30 and will be removed in 0.40 |
322
|
52
|
50
|
|
|
|
58
|
if ($self->_is_deprecated_dropframe_rate) { |
323
|
0
|
0
|
|
|
|
0
|
$fps = $self->{fps} == 30 ? 29.97 : 59.94; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
##### |
327
|
|
|
|
|
|
|
# Algorithm from: http://www.davidheidelberger.com/blog/?p=29 |
328
|
52
|
|
|
|
|
111
|
my $drop = $self->_frames_to_drop; |
329
|
|
|
|
|
|
|
|
330
|
52
|
|
|
|
|
63
|
my $frames_per_ten_minutes = $fps * $SECONDS_PER_MINUTE * 10; |
331
|
52
|
|
|
|
|
59
|
my $frames_per_minute = $self->_frames_per_minute - $drop; |
332
|
|
|
|
|
|
|
|
333
|
52
|
|
|
|
|
72
|
my $d = int($frames / $frames_per_ten_minutes); |
334
|
52
|
|
|
|
|
41
|
my $m = $frames % $frames_per_ten_minutes; |
335
|
|
|
|
|
|
|
|
336
|
52
|
100
|
|
|
|
60
|
if($m > $drop) { |
337
|
49
|
|
|
|
|
81
|
$frames += ($drop * 9 * $d) + $drop * int(($m - $drop) / $frames_per_minute); |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
else { |
340
|
3
|
|
|
|
|
5
|
$frames += $drop * 9 * $d; |
341
|
|
|
|
|
|
|
} |
342
|
|
|
|
|
|
|
##### |
343
|
|
|
|
|
|
|
|
344
|
52
|
|
|
|
|
65
|
$self->_set_and_validate_time_part('frames', $self->_frames($frames), \&_valid_frames); |
345
|
52
|
|
|
|
|
75
|
$self->_set_and_validate_time_part('seconds', $self->_seconds_from_frames($frames), \&_valid_time_part); |
346
|
52
|
|
|
|
|
70
|
$self->_set_and_validate_time_part('minutes', $self->_minutes_from_frames($frames), \&_valid_time_part); |
347
|
52
|
|
|
|
|
78
|
$self->_set_and_validate_time_part('hours', $self->_hours_from_frames($frames), \&_valid_time_part); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub _is_deprecated_dropframe_rate |
351
|
|
|
|
|
|
|
{ |
352
|
127
|
|
|
127
|
|
93
|
my $self = shift; |
353
|
127
|
100
|
33
|
|
|
131
|
$self->is_dropframe && ($self->{fps} == 30 || $self->{fps} == 60); |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
sub _timecode_from_total_frames |
357
|
|
|
|
|
|
|
{ |
358
|
52
|
|
|
52
|
|
53
|
my ($self, $frames) = @_; |
359
|
52
|
|
|
|
|
89
|
$self->{total_frames} = $frames; |
360
|
52
|
|
|
|
|
74
|
$self->_set_timecode_from_frames($frames); |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
# Close your eyes, it's about to get ugly... |
364
|
|
|
|
|
|
|
sub _timecode_from_string |
365
|
|
|
|
|
|
|
{ |
366
|
12
|
|
|
12
|
|
16
|
my ($self, $timecode) = @_; |
367
|
|
|
|
|
|
|
#[\Q$self->{delimiter}$DEFAULT_DELIMITER\E] |
368
|
12
|
|
|
|
|
30
|
my $delim = '[' . quotemeta("$self->{delimiter}$DEFAULT_DELIMITER") . ']'; |
369
|
12
|
|
|
|
|
11
|
my $frame_delim = $FRAME_PART_DELIMITERS; |
370
|
|
|
|
|
|
|
|
371
|
12
|
100
|
|
|
|
22
|
$frame_delim .= $self->{frame_delimiter} if defined $self->{frame_delimiter}; |
372
|
12
|
|
|
|
|
19
|
$frame_delim = '[' . quotemeta("$frame_delim") . ']'; |
373
|
|
|
|
|
|
|
|
374
|
12
|
100
|
|
|
|
413
|
if($timecode =~ /^\s*($TIME_PART)$delim($TIME_PART)$delim($TIME_PART)($frame_delim)([0-5]\d)\s*([NDPF])?\s*$/) { |
375
|
|
|
|
|
|
|
#TODO: Use suffix after frames to determine drop/non-drop -and possibly other things |
376
|
11
|
100
|
|
|
|
25
|
if(!defined $self->{is_dropframe}) { |
377
|
10
|
100
|
|
|
|
45
|
$self->{is_dropframe} = index($DROP_FRAME_DELIMITERS, $4) != -1 ? 1 : $DEFAULT_DROPFRAME; |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
|
380
|
11
|
100
|
|
|
|
28
|
$self->{frame_delimiter} = $4 unless defined $self->{frame_delimiter}; |
381
|
11
|
|
|
|
|
27
|
$self->_set_and_validate_time($1, $2, $3, $5); |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
else { |
384
|
1
|
|
|
|
|
150
|
Carp::croak "Can't create timecode from '$timecode'"; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
1; |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
__END__ |