26
34
FlashVersion => { },
27
Compressed => { PrintConv => { 0 => 'False', 1 => 'True' } },
35
Compressed => { PrintConv => { 0 => 'False', 1 => 'True' } },
33
41
Notes => 'calculated from FrameRate and FrameCount',
34
42
PrintConv => 'sprintf("%.2f sec",$val)',
46
# packets in Flash Video files
47
%Image::ExifTool::Flash::FLV = (
49
Information is extracted from the following packets in FLV (Flash Video)
55
SubDirectory => { TagTable => 'Image::ExifTool::Flash::Audio' },
60
SubDirectory => { TagTable => 'Image::ExifTool::Flash::Video' },
64
SubDirectory => { TagTable => 'Image::ExifTool::Flash::Meta' },
68
# tags in Flash Video packet header
69
%Image::ExifTool::Flash::Audio = (
70
PROCESS_PROC => \&Image::ExifTool::FLAC::ProcessBitStream,
71
GROUPS => { 2 => 'Audio' },
72
NOTES => 'Information extracted from the Flash Audio header.',
74
Name => 'AudioEncoding',
79
5 => 'Nellymoser 8kHz mono',
84
Name => 'AudioSampleRate',
93
Name => 'AudioSampleBits',
94
ValueConv => '8 * ($val + 1)',
97
Name => 'AudioChannels',
98
ValueConv => '$val + 1',
106
# tags in Flash Video packet header
107
%Image::ExifTool::Flash::Video = (
108
PROCESS_PROC => \&Image::ExifTool::FLAC::ProcessBitStream,
109
GROUPS => { 2 => 'Video' },
110
NOTES => 'Information extracted from the Flash Video header.',
112
Name => 'VideoEncoding',
114
2 => 'Sorensen H.263',
121
# tags in Flash META packet (in ActionScript Message Format)
122
%Image::ExifTool::Flash::Meta = (
123
PROCESS_PROC => \&ProcessMeta,
124
GROUPS => { 2 => 'Video' },
126
Below are a few observed FLV Meta tags, but ExifTool will attempt to extract
127
information from any tag found.
129
'audiocodecid' => { Name => 'AudioCodecID', Groups => { 2 => 'Audio' } },
131
Name => 'AudioBitrate',
132
Groups => { 2 => 'Audio' },
133
ValueConv => '$val * 1000',
134
PrintConv => 'int($val + 0.5)',
136
'audiodelay' => { Name => 'AudioDelay', Groups => { 2 => 'Audio' } },
137
'audiosamplerate'=>{ Name => 'AudioSampleRate', Groups => { 2 => 'Audio' } },
138
'audiosamplesize'=>{ Name => 'AudioSampleSize', Groups => { 2 => 'Audio' } },
139
'audiosize' => { Name => 'AudioSize', Groups => { 2 => 'Audio' } },
140
'canSeekToEnd' => 'CanSeekToEnd',
142
# (not an AMF date type in my sample)
143
Name => 'CreateDate',
144
Groups => { 2 => 'Time' },
145
ValueConv => '$val=~s/\s+$//; $val', # trim trailing whitespace
149
SubDirectory => { TagTable => 'Image::ExifTool::Flash::CuePoint' },
151
'datasize' => 'DataSize',
154
PrintConv => 'sprintf("%.3fs",$val)',
156
'filesize' => 'FileSizeBytes',
159
PrintConv => 'int($val * 1000 + 0.5) / 1000',
161
'hasAudio' => { Name => 'HasAudio', Groups => { 2 => 'Audio' } },
162
'hasCuePoints' => 'HasCuePoints',
163
'hasKeyframes' => 'HasKeyFrames',
164
'hasMetadata' => 'HasMetadata',
165
'hasVideo' => 'HasVideo',
166
'height' => 'ImageHeight',
167
'keyframesTimes'=> 'KeyFramesTimes',
168
'keyframesFilepositions' => 'KeyFramePositions',
169
'lasttimestamp' => 'LastTimeStamp',
170
'lastkeyframetimestamp' => 'LastKeyFrameTime',
171
'metadatacreator'=>'MetadataCreator',
173
Name => 'MetadataDate',
174
Groups => { 2 => 'Time' },
175
PrintConv => '$self->ConvertDateTime($val)',
177
'stereo' => { Name => 'Stereo', Groups => { 2 => 'Audio' } },
178
'videocodecid' => 'VideoCodecID',
180
Name => 'VideoBitrate',
181
ValueConv => '$val * 1000',
182
PrintConv => 'int($val + 0.5)',
184
'videosize' => 'VideoSize',
185
'width' => 'ImageWidth',
188
# tags in Flash META CuePoint structure
189
%Image::ExifTool::Flash::CuePoint = (
190
PROCESS_PROC => \&ProcessMeta,
191
GROUPS => { 2 => 'Video' },
193
These tag names are added to the CuePoint name to generate complete tag
194
names like "CuePoint0Name".
201
SubDirectory => { TagTable => 'Image::ExifTool::Flash::Parameter' },
205
# tags in Flash META CuePoint Parameter structure
206
%Image::ExifTool::Flash::Parameter = (
207
PROCESS_PROC => \&ProcessMeta,
208
GROUPS => { 2 => 'Video' },
210
There are no pre-defined parameter tags, but ExifTool will extract any
211
existing parameters, with tag names like "CuePoint0ParameterXxx".
215
# name lookup for known AMF data types
216
my @amfType = qw(double boolean string object movieClip null undefined reference
217
mixedArray objectEnd array date longString unsupported recordSet
218
XML typedObject AMF3data);
220
# test for AMF structure types (object, mixed array or typed object)
221
my %isStruct = ( 0x03 => 1, 0x08 => 1, 0x10 => 1 );
223
#------------------------------------------------------------------------------
224
# Process Flash Video AMF Meta packet (ref 3)
225
# Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
226
# 3) Set to extract single type/value only
227
# Returns: 1 on success, (or type/value if extracting single value)
228
# Notes: Updates DataPos in dirInfo if extracting single value
229
sub ProcessMeta($$$;$)
231
my ($exifTool, $dirInfo, $tagTablePtr, $single) = @_;
232
my $dataPt = $$dirInfo{DataPt};
233
my $dataPos = $$dirInfo{DataPos};
234
my $dirLen = $$dirInfo{DirLen} || length($$dataPt);
235
my $pos = $$dirInfo{Pos} || 0;
236
my $verbose = $exifTool->Options('Verbose');
237
my ($type, $val, $rec);
239
$exifTool->VerboseDir('Meta') unless $single;
241
Record: for ($rec=0; ; ++$rec) {
242
last if $pos >= $dirLen;
243
$type = ord(substr($$dataPt, $pos));
245
if ($type == 0x00 or $type == 0x0b) { # double or date
246
last if $pos + 8 > $dirLen;
247
$val = GetDouble($dataPt, $pos);
249
if ($type == 0x0b) { # date
250
$val /= 1000; # convert to seconds
251
my $frac = $val - int($val); # fractional seconds
253
last if $pos + 2 > $dirLen;
254
my $tz = Get16s($dataPt, $pos);
256
# construct date/time string
257
$val = Image::ExifTool::ConvertUnixTime(int($val));
259
$frac = sprintf('%.6f', $frac);
260
$frac =~ s/(^0|0+$)//g;
270
$val .= sprintf('%.2d:%.2d', int($tz/60), $tz%60);
272
} elsif ($type == 0x01) { # boolean
273
last if $pos + 1 > $dirLen;
274
$val = Get8u($dataPt, $pos);
275
$val = { 0 => 'No', 1 => 'Yes' }->{$val} if $val < 2;
277
} elsif ($type == 0x02) { # string
278
last if $pos + 2 > $dirLen;
279
my $len = Get16u($dataPt, $pos);
280
last if $pos + 2 + $len > $dirLen;
281
$val = substr($$dataPt, $pos + 2, $len);
283
} elsif ($isStruct{$type}) { # object, mixed array or typed object
284
$exifTool->VPrint(1, " + [$amfType[$type]]\n");
286
$val = ''; # dummy value
287
if ($type == 0x08) { # mixed array
288
# skip last array index for mixed array
289
last if $pos + 4 > $dirLen;
291
} elsif ($type == 0x10) { # typed object
295
# get tag ID (or typed object name)
296
last Record if $pos + 2 > $dirLen;
297
my $len = Get16u($dataPt, $pos);
298
if ($pos + 2 + $len > $dirLen) {
299
$exifTool->Warn("Truncated $amfType[$type] record");
302
my $tag = substr($$dataPt, $pos + 2, $len);
304
# first string of a typed object is the object name
306
$exifTool->VPrint(1," | (object name '$tag')\n");
308
next; # (ignore name for now)
310
my $subTablePtr = $tagTablePtr;
311
my $tagInfo = $$subTablePtr{$tag};
312
# switch to subdirectory table if necessary
313
if ($tagInfo and $$tagInfo{SubDirectory}) {
314
$tag = $$tagInfo{Name}; # use our name for the tag
315
$subTablePtr = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
318
my $valPos = $pos + 1;
319
$$dirInfo{Pos} = $pos;
320
my $structName = $$dirInfo{StructName};
321
# add structure name to start of tag name
322
$tag = $structName . ucfirst($tag) if defined $structName;
323
$$dirInfo{StructName} = $tag; # set new structure name
324
my ($t, $v) = ProcessMeta($exifTool, $dirInfo, $subTablePtr, 1);
325
$$dirInfo{StructName} = $structName;# restore original structure name
326
$pos = $$dirInfo{Pos}; # update to new position in packet
327
# all done if this value contained tags
328
last Record unless defined $t and defined $v;
329
next if $isStruct{$t}; # already handled tags in sub-structures
330
next if ref($v) eq 'ARRAY' and not @$v; # ignore empty arrays
331
last if $t == 0x09; # (end of object)
332
if (not $$subTablePtr{$tag} and $tag =~ /^\w+$/) {
333
Image::ExifTool::AddTagToTable($subTablePtr, $tag, { Name => ucfirst($tag) });
334
$verbose > 1 and $exifTool->VPrint(1, " | (adding $tag)\n");
336
$exifTool->HandleTag($subTablePtr, $tag, $v,
340
Size => $pos - $valPos,
341
Format => $amfType[$t] || sprintf('0x%x',$t),
344
# } elsif ($type == 0x04) { # movie clip (not supported)
345
} elsif ($type == 0x05 or $type == 0x06 or $type == 0x09 or $type == 0x0d) {
346
# null, undefined, dirLen of object, or unsupported
348
} elsif ($type == 0x07) { # reference
349
last if $pos + 2 > $dirLen;
350
$val = Get16u($dataPt, $pos);
352
} elsif ($type == 0x0a) { # array
353
last if $pos + 4 > $dirLen;
354
my $num = Get32u($dataPt, $pos);
355
$$dirInfo{Pos} = $pos + 4;
357
# add array index to compount tag name
358
my $structName = $$dirInfo{StructName};
359
for ($i=0; $i<$num; ++$i) {
360
$$dirInfo{StructName} = $structName . $i if defined $structName;
361
my ($t, $v) = ProcessMeta($exifTool, $dirInfo, $tagTablePtr, 1);
362
last Record unless defined $v;
363
# save value unless contained in a sub-structure
364
push @vals, $v unless $isStruct{$t};
366
$$dirInfo{StructName} = $structName;
367
$pos = $$dirInfo{Pos};
369
} elsif ($type == 0x0c or $type == 0x0f) { # long string or XML
370
last if $pos + 4 > $dirLen;
371
my $len = Get32u($dataPt, $pos);
372
last if $pos + 4 + $len > $dirLen;
373
$val = substr($$dataPt, $pos + 4, $len);
375
# } elsif ($type == 0x0e) { # record set (not supported)
376
# } elsif ($type == 0x11) { # AMF3 data (can't add support for this without a test sample)
378
my $t = $amfType[$type] || sprintf('type 0x%x',$type);
379
$exifTool->Warn("AMF $t record not yet supported");
380
undef $type; # (so we don't print another warning)
381
last; # can't continue
383
last if $single; # all done if extracting single value
384
unless ($isStruct{$type}) {
385
# only process "onMetaData" Meta packets
386
if ($type == 0x02 and not $rec) {
387
my $verb = ($val eq 'onMetaData') ? 'processing' : 'ignoring';
388
$exifTool->VPrint(0, " | ($verb $val information)\n");
389
last unless $val eq 'onMetaData';
391
# give verbose indication if we ignore a lone value
392
my $t = $amfType[$type] || sprintf('type 0x%x',$type);
393
$exifTool->VPrint(1, " | (ignored lone $t value '$val')\n");
397
if (not defined $val and defined $type) {
398
$exifTool->Warn(sprintf("Truncated AMF record 0x%x",$type));
400
return 1 unless $single; # all done
401
$$dirInfo{Pos} = $pos; # update position
402
return($type,$val); # return single type/value pair
405
#------------------------------------------------------------------------------
406
# Read information frame a Flash Video file
407
# Inputs: 0) ExifTool object reference, 1) Directory information reference
408
# Returns: 1 on success, 0 if this wasn't a valid Flash Video file
411
my ($exifTool, $dirInfo) = @_;
412
my $verbose = $exifTool->Options('Verbose');
413
my $raf = $$dirInfo{RAF};
416
$raf->Read($buff, 9) == 9 or return 0;
417
$buff =~ /^FLV\x01/ or return 0;
419
$exifTool->SetFileType();
420
my ($flags, $offset) = unpack('x4CN', $buff);
421
$raf->Seek($offset-9, 1) or return 1 if $offset > 9;
422
$flags &= 0x05; # only look for audio/video
424
my $tagTablePtr = GetTagTable('Image::ExifTool::Flash::FLV');
426
$raf->Read($buff, 15) == 15 or last;
427
my $len = unpack('x4N', $buff);
428
my $type = $len >> 24;
430
my $tagInfo = $exifTool->GetTagInfo($tagTablePtr, $type);
432
my $name = $tagInfo ? $$tagInfo{Name} : "type $type";
433
$exifTool->VPrint(1, "FLV $name packet, len $len\n");
436
if ($tagInfo and $$tagInfo{SubDirectory}) {
437
my $mask = $$tagInfo{BitMask};
439
# handle audio or video packet
440
unless ($found & $mask) {
443
if ($len>=1 and $raf->Read($buff, 1) == 1) {
446
$exifTool->Warn("Bad $$tagInfo{Name} packet");
450
} elsif ($raf->Read($buff, $len) == $len) {
453
$exifTool->Warn('Truncated Meta packet');
458
$exifTool->HandleTag($tagTablePtr, $type, undef,
460
DataPos => $raf->Tell() - length($buff),
464
$raf->Seek($len, 1) or last if $len;
38
469
#------------------------------------------------------------------------------
39
470
# Found a Flash tag
40
471
# Inputs: 0) ExifTool object ref, 1) tag name, 2) tag value