<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#------------------------------------------------------------------------------
# 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.01';

# MOI tags (ref 1)
%Image::ExifTool::MOI::Main = (
    GROUPS =&gt; { 2 =&gt; 'Video' },
    PROCESS_PROC =&gt; \&amp;Image::ExifTool::ProcessBinaryData,
    NOTES =&gt; q{
        MOI files store information about associated MOD or TOD files, and are
        written by some JVC, Canon and Panasonic camcorders.
    },
    0x00 =&gt; { Name =&gt; 'MOIVersion',  Format =&gt; 'string[2]' },
  # 0x02 =&gt; { Name =&gt; 'MOIFileSize', Format =&gt; 'int32u' },
    0x06 =&gt; {
        Name =&gt; 'DateTimeOriginal',
        Format =&gt; 'undef[8]',
        Groups =&gt; { 2 =&gt; 'Time' },
        ValueConv =&gt; sub {
            my $val = shift;
            return undef unless length($val) &gt;= 8;
            my @v = unpack('nCCCCn', $val);
            $v[5] /= 1000;
            return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%06.3f', @v);
        },
        PrintConv =&gt; '$self-&gt;ConvertDateTime($val)',
    },
    0x0e =&gt; {
        Name =&gt; 'Duration',
        Format =&gt; 'int32u',
        ValueConv =&gt; '$val / 1000',
        PrintConv =&gt; 'ConvertDuration($val)',
    },
    0x80 =&gt; {
        Name =&gt; 'AspectRatio',
        Format =&gt; 'int8u',
        PrintConv =&gt; q{
            my $lo = ($val &amp; 0x0f);
            my $hi = ($val &gt;&gt; 4);
            my $aspect;
            if ($lo &lt; 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 =&gt; {
        Name =&gt; 'AudioCodec',
        Format =&gt; 'int16u',
        Groups =&gt; { 2 =&gt; 'Audio' },
        PrintHex =&gt; 1,
        PrintConv =&gt; {
            0x00c1 =&gt; 'AC3',
            0x4001 =&gt; 'MPEG',
        },
    },
    0x86 =&gt; {
        Name =&gt; 'AudioBitrate',
        Format =&gt; 'int8u',
        Groups =&gt; { 2 =&gt; 'Audio' },
        ValueConv =&gt; '$val * 16000 + 48000',
        PrintConv =&gt; 'ConvertBitrate($val)',
    },
    0xda =&gt; {
        Name =&gt; 'VideoBitrate',
        Format =&gt; 'int16u',
        PrintHex =&gt; 1,
        ValueConv =&gt; {
            0x5896 =&gt; '8500000',
            0x813d =&gt; '5500000',
        },
        PrintConv =&gt; '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-&gt;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;
    }
    SetByteOrder('MM');
    my $tagTablePtr = GetTagTable('Image::ExifTool::MOI::Main');
    return $et-&gt;ProcessBinaryData({ DataPt =&gt; \$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-2015, 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&lt;https://en.wikipedia.org/wiki/MOI_(file_format)&gt;

=back

=head1 SEE ALSO

L&lt;Image::ExifTool::TagNames/MOI Tags&gt;,
L&lt;Image::ExifTool(3pm)|Image::ExifTool&gt;

=cut

</pre></body></html>