File Coverage

blib/lib/Image/ExifTool/MOI.pm
Criterion Covered Total %
statement 20 20 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 4 4 100.0
pod 0 1 0.0
total 28 34 82.3


line stmt bran cond sub pod time code
1             #------------------------------------------------------------------------------
2             # File: MOI.pm
3             #
4             # Description: Read MOI meta information
5             #
6             # Revisions: 2014/12/15 - P. Harvey Created
7             #
8             # References: 1) https://en.wikipedia.org/wiki/MOI_(file_format)
9             #------------------------------------------------------------------------------
10              
11             package Image::ExifTool::MOI;
12              
13 1     1   4491 use strict;
  1         2  
  1         32  
14 1     1   7 use vars qw($VERSION);
  1         3  
  1         38  
15 1     1   5 use Image::ExifTool qw(:DataAccess :Utils);
  1         2  
  1         597  
16              
17             $VERSION = '1.02';
18              
19             # MOI tags (ref 1)
20             %Image::ExifTool::MOI::Main = (
21             GROUPS => { 2 => 'Video' },
22             PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
23             NOTES => q{
24             MOI files store information about associated MOD or TOD files, and are
25             written by some JVC, Canon and Panasonic camcorders.
26             },
27             0x00 => { Name => 'MOIVersion', Format => 'string[2]' },
28             # 0x02 => { Name => 'MOIFileSize', Format => 'int32u' },
29             0x06 => {
30             Name => 'DateTimeOriginal',
31             Description => 'Date/Time Original',
32             Format => 'undef[8]',
33             Groups => { 2 => 'Time' },
34             ValueConv => sub {
35             my $val = shift;
36             return undef unless length($val) >= 8;
37             my @v = unpack('nCCCCn', $val);
38             $v[5] /= 1000;
39             return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%06.3f', @v);
40             },
41             PrintConv => '$self->ConvertDateTime($val)',
42             },
43             0x0e => {
44             Name => 'Duration',
45             Format => 'int32u',
46             ValueConv => '$val / 1000',
47             PrintConv => 'ConvertDuration($val)',
48             },
49             0x80 => {
50             Name => 'AspectRatio',
51             Format => 'int8u',
52             PrintConv => q{
53             my $lo = ($val & 0x0f);
54             my $hi = ($val >> 4);
55             my $aspect;
56             if ($lo < 2) {
57             $aspect = '4:3';
58             } elsif ($lo == 4 or $lo == 5) {
59             $aspect = '16:9';
60             } else {
61             $aspect = 'Unknown';
62             }
63             if ($hi == 4) {
64             $aspect .= ' NTSC';
65             } elsif ($hi == 5) {
66             $aspect .= ' PAL';
67             }
68             return $aspect;
69             },
70             },
71             0x84 => {
72             Name => 'AudioCodec',
73             Format => 'int16u',
74             Groups => { 2 => 'Audio' },
75             PrintHex => 1,
76             PrintConv => {
77             0x00c1 => 'AC3',
78             0x4001 => 'MPEG',
79             },
80             },
81             0x86 => {
82             Name => 'AudioBitrate',
83             Format => 'int8u',
84             Groups => { 2 => 'Audio' },
85             ValueConv => '$val * 16000 + 48000',
86             PrintConv => 'ConvertBitrate($val)',
87             },
88             0xda => {
89             Name => 'VideoBitrate',
90             Format => 'int16u',
91             PrintHex => 1,
92             ValueConv => {
93             0x5896 => '8500000',
94             0x813d => '5500000',
95             },
96             PrintConv => 'ConvertBitrate($val)',
97             },
98             );
99              
100             #------------------------------------------------------------------------------
101             # Validate and extract metadata from MOI file
102             # Inputs: 0) ExifTool ref, 1) dirInfo ref
103             # Returns: 1 on success, 0 if this wasn't a valid MOI file
104             sub ProcessMOI($$)
105             {
106 1     1 0 4 my ($et, $dirInfo) = @_;
107 1         2 my $raf = $$dirInfo{RAF};
108 1         2 my $buff;
109             # read enough to allow skipping over run-in if it exists
110 1 50 33     5 $raf->Read($buff, 256) == 256 and $buff =~ /^V6/ or return 0;
111 1 50       4 if (defined $$et{VALUE}{FileSize}) {
112 1         6 my $size = unpack('x2N', $buff);
113 1 50       4 $size == $$et{VALUE}{FileSize} or return 0;
114             }
115 1         6 $et->SetFileType();
116 1         5 SetByteOrder('MM');
117 1         3 my $tagTablePtr = GetTagTable('Image::ExifTool::MOI::Main');
118 1         24 return $et->ProcessBinaryData({ DataPt => \$buff }, $tagTablePtr);
119             }
120              
121             1; # end
122              
123             __END__