MOI.pm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. package Image::ExifTool::MOI;
  11. use strict;
  12. use vars qw($VERSION);
  13. use Image::ExifTool qw(:DataAccess :Utils);
  14. $VERSION = '1.02';
  15. # MOI tags (ref 1)
  16. %Image::ExifTool::MOI::Main = (
  17. GROUPS => { 2 => 'Video' },
  18. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  19. NOTES => q{
  20. MOI files store information about associated MOD or TOD files, and are
  21. written by some JVC, Canon and Panasonic camcorders.
  22. },
  23. 0x00 => { Name => 'MOIVersion', Format => 'string[2]' },
  24. # 0x02 => { Name => 'MOIFileSize', Format => 'int32u' },
  25. 0x06 => {
  26. Name => 'DateTimeOriginal',
  27. Format => 'undef[8]',
  28. Groups => { 2 => 'Time' },
  29. ValueConv => sub {
  30. my $val = shift;
  31. return undef unless length($val) >= 8;
  32. my @v = unpack('nCCCCn', $val);
  33. $v[5] /= 1000;
  34. return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%06.3f', @v);
  35. },
  36. PrintConv => '$self->ConvertDateTime($val)',
  37. },
  38. 0x0e => {
  39. Name => 'Duration',
  40. Format => 'int32u',
  41. ValueConv => '$val / 1000',
  42. PrintConv => 'ConvertDuration($val)',
  43. },
  44. 0x80 => {
  45. Name => 'AspectRatio',
  46. Format => 'int8u',
  47. PrintConv => q{
  48. my $lo = ($val & 0x0f);
  49. my $hi = ($val >> 4);
  50. my $aspect;
  51. if ($lo < 2) {
  52. $aspect = '4:3';
  53. } elsif ($lo == 4 or $lo == 5) {
  54. $aspect = '16:9';
  55. } else {
  56. $aspect = 'Unknown';
  57. }
  58. if ($hi == 4) {
  59. $aspect .= ' NTSC';
  60. } elsif ($hi == 5) {
  61. $aspect .= ' PAL';
  62. }
  63. return $aspect;
  64. },
  65. },
  66. 0x84 => {
  67. Name => 'AudioCodec',
  68. Format => 'int16u',
  69. Groups => { 2 => 'Audio' },
  70. PrintHex => 1,
  71. PrintConv => {
  72. 0x00c1 => 'AC3',
  73. 0x4001 => 'MPEG',
  74. },
  75. },
  76. 0x86 => {
  77. Name => 'AudioBitrate',
  78. Format => 'int8u',
  79. Groups => { 2 => 'Audio' },
  80. ValueConv => '$val * 16000 + 48000',
  81. PrintConv => 'ConvertBitrate($val)',
  82. },
  83. 0xda => {
  84. Name => 'VideoBitrate',
  85. Format => 'int16u',
  86. PrintHex => 1,
  87. ValueConv => {
  88. 0x5896 => '8500000',
  89. 0x813d => '5500000',
  90. },
  91. PrintConv => 'ConvertBitrate($val)',
  92. },
  93. );
  94. #------------------------------------------------------------------------------
  95. # Validate and extract metadata from MOI file
  96. # Inputs: 0) ExifTool ref, 1) dirInfo ref
  97. # Returns: 1 on success, 0 if this wasn't a valid MOI file
  98. sub ProcessMOI($$)
  99. {
  100. my ($et, $dirInfo) = @_;
  101. my $raf = $$dirInfo{RAF};
  102. my $buff;
  103. # read enough to allow skipping over run-in if it exists
  104. $raf->Read($buff, 256) == 256 and $buff =~ /^V6/ or return 0;
  105. if (defined $$et{VALUE}{FileSize}) {
  106. my $size = unpack('x2N', $buff);
  107. $size == $$et{VALUE}{FileSize} or return 0;
  108. }
  109. $et->SetFileType();
  110. SetByteOrder('MM');
  111. my $tagTablePtr = GetTagTable('Image::ExifTool::MOI::Main');
  112. return $et->ProcessBinaryData({ DataPt => \$buff }, $tagTablePtr);
  113. }
  114. 1; # end
  115. __END__
  116. =head1 NAME
  117. Image::ExifTool::MOI - Read MOI meta information
  118. =head1 SYNOPSIS
  119. This module is used by Image::ExifTool
  120. =head1 DESCRIPTION
  121. This module contains definitions required by Image::ExifTool to read meta
  122. information from MOI files.
  123. =head1 AUTHOR
  124. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  125. This library is free software; you can redistribute it and/or modify it
  126. under the same terms as Perl itself.
  127. =head1 REFERENCES
  128. =over 4
  129. =item L<https://en.wikipedia.org/wiki/MOI_(file_format)>
  130. =back
  131. =head1 SEE ALSO
  132. L<Image::ExifTool::TagNames/MOI Tags>,
  133. L<Image::ExifTool(3pm)|Image::ExifTool>
  134. =cut