summaryrefslogtreecommitdiff
path: root/lib/Image/ExifTool/MOI.pm
blob: 9246060bf091a03e6a8067c704beca0ddf326777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#------------------------------------------------------------------------------
# File:         MOI.pm
#
# Description:  Read MOI meta information
#
# Revisions:    2014/12/15 - P. Harvey Created
#
# References:   1) https://en.wikipedia.org/wiki/MOI_(file_format)
#------------------------------------------------------------------------------

package Image::ExifTool::MOI;

use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);

$VERSION = '1.02';

# MOI tags (ref 1)
%Image::ExifTool::MOI::Main = (
    GROUPS => { 2 => 'Video' },
    PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
    NOTES => q{
        MOI files store information about associated MOD or TOD files, and are
        written by some JVC, Canon and Panasonic camcorders.
    },
    0x00 => { Name => 'MOIVersion',  Format => 'string[2]' },
  # 0x02 => { Name => 'MOIFileSize', Format => 'int32u' },
    0x06 => {
        Name => 'DateTimeOriginal',
        Format => 'undef[8]',
        Groups => { 2 => 'Time' },
        ValueConv => sub {
            my $val = shift;
            return undef unless length($val) >= 8;
            my @v = unpack('nCCCCn', $val);
            $v[5] /= 1000;
            return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%06.3f', @v);
        },
        PrintConv => '$self->ConvertDateTime($val)',
    },
    0x0e => {
        Name => 'Duration',
        Format => 'int32u',
        ValueConv => '$val / 1000',
        PrintConv => 'ConvertDuration($val)',
    },
    0x80 => {
        Name => 'AspectRatio',
        Format => 'int8u',
        PrintConv => q{
            my $lo = ($val & 0x0f);
            my $hi = ($val >> 4);
            my $aspect;
            if ($lo < 2) {
                $aspect = '4:3';
            } elsif ($lo == 4 or $lo == 5) {
                $aspect = '16:9';
            } else {
                $aspect = 'Unknown';
            }
            if ($hi == 4) {
                $aspect .= ' NTSC';
            } elsif ($hi == 5) {
                $aspect .= ' PAL';
            }
            return $aspect;
        },
    },
    0x84 => {
        Name => 'AudioCodec',
        Format => 'int16u',
        Groups => { 2 => 'Audio' },
        PrintHex => 1,
        PrintConv => {
            0x00c1 => 'AC3',
            0x4001 => 'MPEG',
        },
    },
    0x86 => {
        Name => 'AudioBitrate',
        Format => 'int8u',
        Groups => { 2 => 'Audio' },
        ValueConv => '$val * 16000 + 48000',
        PrintConv => 'ConvertBitrate($val)',
    },
    0xda => {
        Name => 'VideoBitrate',
        Format => 'int16u',
        PrintHex => 1,
        ValueConv => {
            0x5896 => '8500000',
            0x813d => '5500000',
        },
        PrintConv => 'ConvertBitrate($val)',
    },
);

#------------------------------------------------------------------------------
# Validate and extract metadata from MOI file
# Inputs: 0) ExifTool ref, 1) dirInfo ref
# Returns: 1 on success, 0 if this wasn't a valid MOI file
sub ProcessMOI($$)
{
    my ($et, $dirInfo) = @_;
    my $raf = $$dirInfo{RAF};
    my $buff;
    # read enough to allow skipping over run-in if it exists
    $raf->Read($buff, 256) == 256 and $buff =~ /^V6/ or return 0;
    if (defined $$et{VALUE}{FileSize}) {
        my $size = unpack('x2N', $buff);
        $size == $$et{VALUE}{FileSize} or return 0;
    }
    $et->SetFileType();
    SetByteOrder('MM');
    my $tagTablePtr = GetTagTable('Image::ExifTool::MOI::Main');
    return $et->ProcessBinaryData({ DataPt => \$buff }, $tagTablePtr);
}

1;  # end

__END__

=head1 NAME

Image::ExifTool::MOI - Read MOI meta information

=head1 SYNOPSIS

This module is used by Image::ExifTool

=head1 DESCRIPTION

This module contains definitions required by Image::ExifTool to read meta
information from MOI files.

=head1 AUTHOR

Copyright 2003-2018, Phil Harvey (phil at owl.phy.queensu.ca)

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 REFERENCES

=over 4

=item L<https://en.wikipedia.org/wiki/MOI_(file_format)>

=back

=head1 SEE ALSO

L<Image::ExifTool::TagNames/MOI Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>

=cut