Real.pm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. #------------------------------------------------------------------------------
  2. # File: Real.pm
  3. #
  4. # Description: Read Real audio/video meta information
  5. #
  6. # Revisions: 05/16/2006 - P. Harvey Created
  7. #
  8. # References: 1) http://www.getid3.org/
  9. # 2) https://common.helixcommunity.org/nonav/2003/HCS_SDK_r5/htmfiles/rmff.htm
  10. #------------------------------------------------------------------------------
  11. package Image::ExifTool::Real;
  12. use strict;
  13. use vars qw($VERSION);
  14. use Image::ExifTool qw(:DataAccess :Utils);
  15. use Image::ExifTool::Canon;
  16. $VERSION = '1.06';
  17. sub ProcessRealMeta($$$);
  18. sub ProcessRealProperties($$$);
  19. # Real property types (ref PH)
  20. my %propertyType = (
  21. 0 => 'int32u',
  22. 2 => 'string',
  23. );
  24. # Real Metadata property types
  25. my %metadataFormat = (
  26. 1 => 'string', # text
  27. 2 => 'string', # text list
  28. 3 => 'flag', # 1 or 4 byte integer
  29. 4 => 'int32u', # 4-byte integer
  30. 5 => 'undef', # binary data
  31. 6 => 'string', # URL
  32. 7 => 'string', # date
  33. 8 => 'string', # file name
  34. 9 => undef, # grouping
  35. 10 => undef, # reference
  36. );
  37. # Real Metadata property flag bit descriptions
  38. my %metadataFlag = (
  39. 0 => 'Read Only',
  40. 1 => 'Private',
  41. 2 => 'Type Descriptor',
  42. );
  43. # tags used in RealMedia (RM, RV and RMVB) files
  44. %Image::ExifTool::Real::Media = (
  45. GROUPS => { 2 => 'Video' },
  46. NOTES => q{
  47. These B<Tag ID>'s are Chunk ID's used in RealMedia and RealVideo (RM, RV and
  48. RMVB) files.
  49. },
  50. CONT => { SubDirectory => { TagTable => 'Image::ExifTool::Real::ContentDescr' } },
  51. MDPR => { SubDirectory => { TagTable => 'Image::ExifTool::Real::MediaProps' } },
  52. PROP => { SubDirectory => { TagTable => 'Image::ExifTool::Real::Properties' } },
  53. RJMD => { SubDirectory => { TagTable => 'Image::ExifTool::Real::Metadata' } },
  54. );
  55. # pseudo-tags used in RealAudio (RA) files
  56. %Image::ExifTool::Real::Audio = (
  57. GROUPS => { 2 => 'Audio' },
  58. NOTES => q{
  59. Tags in the following table reference information extracted from various
  60. versions of RealAudio (RA) files.
  61. },
  62. '.ra3' => { Name => 'RA3', SubDirectory => { TagTable => 'Image::ExifTool::Real::AudioV3' } },
  63. '.ra4' => { Name => 'RA4', SubDirectory => { TagTable => 'Image::ExifTool::Real::AudioV4' } },
  64. '.ra5' => { Name => 'RA5', SubDirectory => { TagTable => 'Image::ExifTool::Real::AudioV5' } },
  65. );
  66. # pseudo-tags used in RealMedia Metafiles and RealMedia Plug-in Metafiles (RAM and RPM)
  67. %Image::ExifTool::Real::Metafile = (
  68. GROUPS => { 2 => 'Video' },
  69. NOTES => q{
  70. Tags representing information extracted from Real Audio Metafile and
  71. RealMedia Plug-in Metafile (RAM and RPM) files.
  72. },
  73. txt => 'Text',
  74. url => 'URL',
  75. );
  76. %Image::ExifTool::Real::Properties = (
  77. GROUPS => { 1 => 'Real-PROP', 2 => 'Video' },
  78. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  79. VARS => { ID_LABEL => 'Sequence' },
  80. FORMAT => 'int32u',
  81. 0 => { Name => 'MaxBitrate', PrintConv => 'ConvertBitrate($val)' },
  82. 1 => { Name => 'AvgBitrate', PrintConv => 'ConvertBitrate($val)' },
  83. 2 => 'MaxPacketSize',
  84. 3 => 'AvgPacketSize',
  85. 4 => 'NumPackets',
  86. 5 => { Name => 'Duration', ValueConv => '$val / 1000', PrintConv => 'ConvertDuration($val)' },
  87. 6 => { Name => 'Preroll', ValueConv => '$val / 1000', PrintConv => 'ConvertDuration($val)' },
  88. 7 => { Name => 'IndexOffset', Unknown => 1 },
  89. 8 => { Name => 'DataOffset', Unknown => 1 },
  90. 9 => { Name => 'NumStreams', Format => 'int16u' },
  91. 10 => {
  92. Name => 'Flags',
  93. Format => 'int16u',
  94. PrintConv => { BITMASK => {
  95. 0 => 'Allow Recording',
  96. 1 => 'Perfect Play',
  97. 2 => 'Live',
  98. 3 => 'Allow Download', #PH (from rmeditor dump)
  99. } },
  100. },
  101. );
  102. %Image::ExifTool::Real::MediaProps = (
  103. GROUPS => { 1 => 'Real-MDPR', 2 => 'Video' },
  104. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  105. VARS => { ID_LABEL => 'Sequence' },
  106. FORMAT => 'int32u',
  107. PRIORITY => 0, # first stream takes priority
  108. 0 => { Name => 'StreamNumber', Format => 'int16u' },
  109. 1 => { Name => 'StreamMaxBitrate', PrintConv => 'ConvertBitrate($val)' },
  110. 2 => { Name => 'StreamAvgBitrate', PrintConv => 'ConvertBitrate($val)' },
  111. 3 => { Name => 'StreamMaxPacketSize' },
  112. 4 => { Name => 'StreamAvgPacketSize' },
  113. 5 => { Name => 'StreamStartTime' },
  114. 6 => { Name => 'StreamPreroll', ValueConv => '$val / 1000', PrintConv => 'ConvertDuration($val)' },
  115. 7 => { Name => 'StreamDuration',ValueConv => '$val / 1000', PrintConv => 'ConvertDuration($val)' },
  116. 8 => { Name => 'StreamNameLen', Format => 'int8u', Unknown => 1 },
  117. 9 => { Name => 'StreamName', Format => 'string[$val{8}]' },
  118. 10 => { Name => 'StreamMimeLen', Format => 'int8u', Unknown => 1 },
  119. 11 => {
  120. Name => 'StreamMimeType',
  121. Format => 'string[$val{10}]',
  122. RawConv => '$self->{RealStreamMime} = $val',
  123. },
  124. 12 => { Name => 'FileInfoLen', Unknown => 1 },
  125. 13 => {
  126. Name => 'FileInfoLen2',
  127. # if this condition fails, subsequent tags will not be processed
  128. Condition => '$self->{RealStreamMime} eq "logical-fileinfo"',
  129. Unknown => 1,
  130. },
  131. 14 => {
  132. Name => 'FileInfoVersion',
  133. Format => 'int16u',
  134. },
  135. 15 => {
  136. Name => 'PhysicalStreams',
  137. Format => 'int16u',
  138. Unknown => 1,
  139. },
  140. 16 => {
  141. Name => 'PhysicalStreamNumbers',
  142. Format => 'int16u[$val{15}]',
  143. Unknown => 1,
  144. },
  145. 17 => {
  146. Name => 'DataOffsets',
  147. Format => 'int32u[$val{15}]',
  148. Unknown => 1,
  149. },
  150. 18 => {
  151. Name => 'NumRules',
  152. Format => 'int16u',
  153. Unknown => 1,
  154. },
  155. 19 => {
  156. Name => 'PhysicalStreamNumberMap',
  157. Format => 'int16u[$val{18}]',
  158. Unknown => 1,
  159. },
  160. 20 => {
  161. Name => 'NumProperties',
  162. Format => 'int16u',
  163. Unknown => 1,
  164. },
  165. 21 => {
  166. Name => 'FileInfoProperties',
  167. Format => 'undef[$val{13}-$val{15}*6-$val{18}*2-12]',
  168. SubDirectory => { TagTable => 'Image::ExifTool::Real::FileInfo' },
  169. },
  170. );
  171. # Observed FileInfo properties (ref PH)
  172. %Image::ExifTool::Real::FileInfo = (
  173. GROUPS => { 1 => 'Real-MDPR', 2 => 'Video' },
  174. PROCESS_PROC => \&ProcessRealProperties,
  175. NOTES => q{
  176. The following tags have been observed in the FileInfo properties, but any
  177. other existing information will also be extracted.
  178. },
  179. Indexable => { PrintConv => { 0 => 'False', 1 => 'True' } },
  180. Keywords => { },
  181. Description => { },
  182. 'File ID' => { Name => 'FileID' },
  183. 'Content Rating' => {
  184. Name => 'ContentRating',
  185. PrintConv => {
  186. 0 => 'No Rating',
  187. 1 => 'All Ages',
  188. 2 => 'Older Children',
  189. 3 => 'Younger Teens',
  190. 4 => 'Older Teens',
  191. 5 => 'Adult Supervision Recommended',
  192. 6 => 'Adults Only',
  193. },
  194. },
  195. Audiences => { },
  196. audioMode => { Name => 'AudioMode' },
  197. 'Creation Date' => {
  198. Name => 'CreateDate',
  199. Groups => { 2 => 'Time' },
  200. ValueConv => q{
  201. $val =~ m{(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)} ?
  202. sprintf("%.4d:%.2d:%.2d %.2d:%.2d:%.2d",$3,$2,$1,$4,$5,$6) : $val
  203. },
  204. PrintConv => '$self->ConvertDateTime($val)',
  205. },
  206. 'Generated By' => { Name => 'Software' },
  207. 'Modification Date' => {
  208. Name => 'ModifyDate',
  209. Groups => { 2 => 'Time' },
  210. ValueConv => q{
  211. $val =~ m{(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)} ?
  212. sprintf("%.4d:%.2d:%.2d %.2d:%.2d:%.2d",$3,$2,$1,$4,$5,$6) : $val
  213. },
  214. PrintConv => '$self->ConvertDateTime($val)',
  215. },
  216. 'Target Audiences' => { Name => 'TargetAudiences' },
  217. 'Audio Format' => { Name => 'AudioFormat' },
  218. 'Video Quality' => { Name => 'VideoQuality' },
  219. videoMode => { Name => 'VideoMode' },
  220. );
  221. %Image::ExifTool::Real::ContentDescr = (
  222. GROUPS => { 1 => 'Real-CONT', 2 => 'Video' },
  223. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  224. VARS => { ID_LABEL => 'Sequence' },
  225. FORMAT => 'int16u',
  226. 0 => { Name => 'TitleLen', Unknown => 1 },
  227. 1 => { Name => 'Title', Format => 'string[$val{0}]' },
  228. 2 => { Name => 'AuthorLen', Unknown => 1 },
  229. 3 => { Name => 'Author', Format => 'string[$val{2}]', Groups => { 2 => 'Author' } },
  230. 4 => { Name => 'CopyrightLen', Unknown => 1 },
  231. 5 => { Name => 'Copyright', Format => 'string[$val{4}]', Groups => { 2 => 'Author' } },
  232. 6 => { Name => 'CommentLen', Unknown => 1 },
  233. 7 => { Name => 'Comment', Format => 'string[$val{6}]' },
  234. );
  235. # Real RJMD meta information (ref PH)
  236. %Image::ExifTool::Real::Metadata = (
  237. GROUPS => { 1 => 'Real-RJMD', 2 => 'Video' },
  238. PROCESS_PROC => \&ProcessRealMeta,
  239. NOTES => q{
  240. The tags below represent information which has been observed in the Real
  241. Metadata format, but ExifTool will extract any information it finds in this
  242. format. (As far as I can tell from the referenced documentation, string
  243. values should be plain text, but this is not the case for the only sample
  244. file I have been able to obtain containing this information. These tags
  245. could also be split into separate sub-directories, but this will wait until
  246. I have better documentation or a more complete set of samples.)
  247. },
  248. 'Album/Name' => 'AlbumName',
  249. 'Track/Category' => 'TrackCategory',
  250. 'Track/Comments' => 'TrackComments',
  251. 'Track/Lyrics' => 'TrackLyrics',
  252. );
  253. %Image::ExifTool::Real::AudioV3 = (
  254. GROUPS => { 1 => 'Real-RA3', 2 => 'Audio' },
  255. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  256. VARS => { ID_LABEL => 'Sequence' },
  257. FORMAT => 'int8u',
  258. 0 => { Name => 'Channels', Format => 'int16u' },
  259. 1 => { Name => 'Unknown', Format => 'int16u[3]', Unknown => 1 },
  260. 2 => { Name => 'BytesPerMinute', Format => 'int16u' },
  261. 3 => { Name => 'AudioBytes', Format => 'int32u' },
  262. 4 => { Name => 'TitleLen', Unknown => 1 },
  263. 5 => { Name => 'Title', Format => 'string[$val{4}]' },
  264. 6 => { Name => 'ArtistLen', Unknown => 1 },
  265. 7 => { Name => 'Artist', Format => 'string[$val{6}]', Groups => { 2 => 'Author' } },
  266. 8 => { Name => 'CopyrightLen', Unknown => 1 },
  267. 9 => { Name => 'Copyright', Format => 'string[$val{8}]', Groups => { 2 => 'Author' } },
  268. 10 => { Name => 'CommentLen', Unknown => 1 },
  269. 11 => { Name => 'Comment', Format => 'string[$val{10}]' },
  270. );
  271. %Image::ExifTool::Real::AudioV4 = (
  272. GROUPS => { 1 => 'Real-RA4', 2 => 'Audio' },
  273. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  274. VARS => { ID_LABEL => 'Sequence' },
  275. FORMAT => 'int16u',
  276. 0 => { Name => 'FourCC1', Format => 'undef[4]', Unknown => 1 },
  277. 1 => { Name => 'AudioFileSize', Format => 'int32u', Unknown => 1 },
  278. 2 => { Name => 'Version2', Unknown => 1 },
  279. 3 => { Name => 'HeaderSize', Format => 'int32u', Unknown => 1 },
  280. 4 => { Name => 'CodecFlavorID', Unknown => 1 },
  281. 5 => { Name => 'CodedFrameSize', Format => 'int32u', Unknown => 1 },
  282. 6 => { Name => 'AudioBytes', Format => 'int32u' },
  283. 7 => { Name => 'BytesPerMinute', Format => 'int32u' },
  284. 8 => { Name => 'Unknown', Format => 'int32u', Unknown => 1 },
  285. 9 => { Name => 'SubPacketH', Unknown => 1 },
  286. 10 => 'AudioFrameSize',
  287. 11 => { Name => 'SubPacketSize', Unknown => 1 },
  288. 12 => { Name => 'Unknown', Unknown => 1 },
  289. 13 => 'SampleRate',
  290. 14 => { Name => 'Unknown', Unknown => 1 },
  291. 15 => 'BitsPerSample',
  292. 16 => 'Channels',
  293. 17 => { Name => 'FourCC2Len', Format => 'int8u', Unknown => 1 },
  294. 18 => { Name => 'FourCC2', Format => 'undef[4]', Unknown => 1 },
  295. 19 => { Name => 'FourCC3Len', Format => 'int8u', Unknown => 1 },
  296. 20 => { Name => 'FourCC3', Format => 'undef[4]', Unknown => 1 },
  297. 21 => { Name => 'Unknown', Format => 'int8u', Unknown => 1 },
  298. 22 => { Name => 'Unknown', Unknown => 1 },
  299. 23 => { Name => 'TitleLen', Format => 'int8u', Unknown => 1 },
  300. 24 => { Name => 'Title', Format => 'string[$val{23}]' },
  301. 25 => { Name => 'ArtistLen', Format => 'int8u', Unknown => 1 },
  302. 26 => { Name => 'Artist', Format => 'string[$val{25}]', Groups => { 2 => 'Author' } },
  303. 27 => { Name => 'CopyrightLen', Format => 'int8u', Unknown => 1 },
  304. 28 => { Name => 'Copyright', Format => 'string[$val{27}]', Groups => { 2 => 'Author' } },
  305. 29 => { Name => 'CommentLen', Format => 'int8u', Unknown => 1 },
  306. 30 => { Name => 'Comment', Format => 'string[$val{29}]' },
  307. );
  308. %Image::ExifTool::Real::AudioV5 = (
  309. GROUPS => { 1 => 'Real-RA5', 2 => 'Audio' },
  310. PROCESS_PROC => \&Image::ExifTool::Canon::ProcessSerialData,
  311. VARS => { ID_LABEL => 'Sequence' },
  312. FORMAT => 'int16u',
  313. 0 => { Name => 'FourCC1', Format => 'undef[4]', Unknown => 1 },
  314. 1 => { Name => 'AudioFileSize', Format => 'int32u', Unknown => 1 },
  315. 2 => { Name => 'Version2', Unknown => 1 },
  316. 3 => { Name => 'HeaderSize', Format => 'int32u', Unknown => 1 },
  317. 4 => { Name => 'CodecFlavorID', Unknown => 1 },
  318. 5 => { Name => 'CodedFrameSize', Format => 'int32u', Unknown => 1 },
  319. 6 => { Name => 'AudioBytes', Format => 'int32u' },
  320. 7 => { Name => 'BytesPerMinute', Format => 'int32u' },
  321. 8 => { Name => 'Unknown', Format => 'int32u', Unknown => 1 },
  322. 9 => { Name => 'SubPacketH', Unknown => 1 },
  323. 10 => { Name => 'FrameSize', Unknown => 1 },
  324. 11 => { Name => 'SubPacketSize', Unknown => 1 },
  325. 12 => 'SampleRate',
  326. 13 => { Name => 'SampleRate2', Unknown => 1 },
  327. 14 => { Name => 'BitsPerSample', Format => 'int32u' },
  328. 15 => 'Channels',
  329. 16 => { Name => 'Genr', Format => 'int32u', Unknown => 1 },
  330. 17 => { Name => 'FourCC3', Format => 'undef[4]', Unknown => 1 },
  331. );
  332. #------------------------------------------------------------------------------
  333. # Process Real NameValueProperties
  334. # Inputs: 0) ExifTool object reference, 1) dirInfo ref, 2) tag table ref
  335. # Returns: 1 on success
  336. sub ProcessRealProperties($$$)
  337. {
  338. my ($et, $dirInfo, $tagTablePtr) = @_;
  339. my $dataPt = $$dirInfo{DataPt};
  340. my $dirLen = $$dirInfo{DirLen};
  341. my $pos = $$dirInfo{DirStart};
  342. my $verbose = $et->Options('Verbose');
  343. $verbose and $et->VerboseDir('RealProperties', undef, $dirLen);
  344. while ($pos + 6 <= $dirLen) {
  345. # get property size and version
  346. my ($size, $vers) = unpack("x${pos}Nn", $$dataPt);
  347. last if $size < 6;
  348. unless ($vers == 0) {
  349. $pos += $size;
  350. next;
  351. }
  352. $pos += 6;
  353. my $tagLen = unpack("x${pos}C", $$dataPt);
  354. ++$pos;
  355. last if $pos + $tagLen > $dirLen;
  356. my $tag = substr($$dataPt, $pos, $tagLen);
  357. $pos += $tagLen;
  358. last if $pos + 6 > $dirLen;
  359. my ($type, $valLen) = unpack("x${pos}Nn", $$dataPt);
  360. $pos += 6;
  361. last if $pos + $valLen > $dirLen;
  362. my $format = $propertyType{$type} || 'undef';
  363. my $count = int($valLen / Image::ExifTool::FormatSize($format));
  364. my $val = ReadValue($dataPt, $pos, $format, $count, $dirLen-$pos);
  365. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
  366. unless ($tagInfo) {
  367. my $tagName;
  368. ($tagName = $tag) =~ s/\s+//g;
  369. next unless $tagName =~ /^\w+$/; # ignore crazy names
  370. $tagInfo = { Name => ucfirst($tagName) };
  371. AddTagToTable($tagTablePtr, $tag, $tagInfo);
  372. }
  373. if ($verbose) {
  374. $et->VerboseInfo($tag, $tagInfo,
  375. Table => $tagTablePtr,
  376. Value => $val,
  377. DataPt => $dataPt,
  378. Size => $valLen,
  379. Start => $pos,
  380. Addr => $pos + $$dirInfo{DataPos},
  381. Format => $format,
  382. Count => $count,
  383. );
  384. }
  385. $et->FoundTag($tagInfo, $val);
  386. $pos += $valLen;
  387. }
  388. return 1;
  389. }
  390. #------------------------------------------------------------------------------
  391. # Process Real metadata properties
  392. # Inputs: 0) ExifTool object reference, 1) dirInfo ref, 2) tag table ref
  393. # Returns: 1 on success
  394. sub ProcessRealMeta($$$)
  395. {
  396. my ($et, $dirInfo, $tagTablePtr) = @_;
  397. my $dataPt = $$dirInfo{DataPt};
  398. my $dataPos = $$dirInfo{DataPos};
  399. my $pos = $$dirInfo{DirStart};
  400. my $dirEnd = $pos + $$dirInfo{DirLen};
  401. my $verbose = $et->Options('Verbose');
  402. my $prefix = $$dirInfo{Prefix} || '';
  403. $prefix and $prefix .= '/';
  404. $verbose and $et->VerboseDir('RealMetadata', undef, $$dirInfo{DirLen});
  405. for (;;) {
  406. last if $pos + 28 > $dirEnd;
  407. # extract fixed-position metadata structure members
  408. my ($size, $type, $flags, $valuePos, $subPropPos, $numSubProps, $nameLen)
  409. = unpack("x${pos}N7", $$dataPt);
  410. # make pointers relative to data start
  411. $valuePos += $pos;
  412. $subPropPos += $pos;
  413. # validate what we have read so far
  414. last if $pos + $size > $dirEnd;
  415. last if $pos + 28 + $nameLen > $dirEnd;
  416. last if $valuePos < $pos + 28 + $nameLen;
  417. last if $valuePos + 4 > $dirEnd;
  418. my $tag = substr($$dataPt, $pos + 28, $nameLen);
  419. $tag =~ s/\0.*//s; # truncate at null
  420. $tag = $prefix . $tag;
  421. my $valueLen = unpack("x${valuePos}N", $$dataPt);
  422. $valuePos += 4; # point at value itself
  423. last if $valuePos + $valueLen > $dirEnd;
  424. my $format = $metadataFormat{$type};
  425. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
  426. unless ($tagInfo) {
  427. my $tagName = $tag;
  428. $tagName =~ tr/A-Za-z0-9//dc;
  429. $tagInfo = { Name => ucfirst($tagName) };
  430. AddTagToTable($tagTablePtr, $tag, $tagInfo);
  431. }
  432. if ($verbose) {
  433. $format = 'undef' unless defined $format;
  434. $flags = Image::ExifTool::DecodeBits($flags, \%metadataFlag);
  435. }
  436. if ($valueLen and $format) {
  437. # (a flag can be 1 or 4 bytes)
  438. if ($format eq 'flag') {
  439. $format = ($valueLen == 4) ? 'int32u' : 'int8u';
  440. } elsif ($type == 7 and $tagInfo) {
  441. # add PrintConv and ValueConv for "date" type
  442. $$tagInfo{ValueConv} or $$tagInfo{ValueConv} = q{
  443. $val =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ ?
  444. sprintf("%.4d:%.2d:%.2d %.2d:%.2d:%.2d",$1,$2,$3,$4,$5,$6) :
  445. $val;
  446. };
  447. $$tagInfo{PrintConv} or $$tagInfo{PrintConv} = '$self->ConvertDateTime($val)';
  448. }
  449. my $count = int($valueLen / Image::ExifTool::FormatSize($format));
  450. my $val = ReadValue($dataPt, $valuePos, $format, $count, $dirEnd-$valuePos);
  451. $et->HandleTag($tagTablePtr, $tag, $val,
  452. DataPt => $dataPt,
  453. DataPos => $dataPos,
  454. Start => $valuePos,
  455. Size => $valueLen,
  456. Format => "type=$type, flags=$flags",
  457. );
  458. }
  459. # extract sub-properties
  460. if ($numSubProps) {
  461. my $dirStart = $valuePos + $valueLen + $numSubProps * 8;
  462. my %dirInfo = (
  463. DataPt => $dataPt,
  464. DataPos => $dataPos,
  465. DirStart => $dirStart,
  466. DirLen => $pos + $size - $dirStart,
  467. Prefix => $tag,
  468. );
  469. $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
  470. }
  471. $pos += $size; # step to next Metadata structure
  472. }
  473. unless ($pos == $dirEnd) {
  474. $et->Warn('Format error in Real Metadata');
  475. return 0;
  476. }
  477. return 1;
  478. }
  479. #------------------------------------------------------------------------------
  480. # Read information frame a Real file
  481. # Inputs: 0) ExifTool object reference, 1) Directory information reference
  482. # Returns: 1 on success, 0 if this wasn't a valid Real file
  483. sub ProcessReal($$)
  484. {
  485. my ($et, $dirInfo) = @_;
  486. my $raf = $$dirInfo{RAF};
  487. my ($buff, $tag, $vers, $extra, @mimeTypes, %dirCount);
  488. $raf->Read($buff, 8) == 8 or return 0;
  489. $buff =~ m{^(\.RMF|\.ra\xfd|pnm://|rtsp://|http://)} or return 0;
  490. my $fast3 = $$et{OPTIONS}{FastScan} && $$et{OPTIONS}{FastScan} == 3;
  491. my ($type, $tagTablePtr);
  492. if ($1 eq '.RMF') {
  493. $tagTablePtr = GetTagTable('Image::ExifTool::Real::Media');
  494. $type = 'RM';
  495. } elsif ($1 eq ".ra\xfd") {
  496. $tagTablePtr = GetTagTable('Image::ExifTool::Real::Audio');
  497. $type = 'RA';
  498. } else {
  499. $tagTablePtr = GetTagTable('Image::ExifTool::Real::Metafile');
  500. my $ext = $$et{FILE_EXT};
  501. $type = ($ext and $ext eq 'RPM') ? 'RPM' : 'RAM';
  502. require Image::ExifTool::PostScript;
  503. local $/ = Image::ExifTool::PostScript::GetInputRecordSeparator($raf) || "\n";
  504. $raf->Seek(0,0);
  505. while ($raf->ReadLine($buff)) {
  506. last if length $buff > 256;
  507. next unless $buff ;
  508. chomp $buff;
  509. if ($type) {
  510. # must be a Real file type if protocol is http
  511. return 0 if $buff =~ /^http/ and $buff !~ /\.(ra|rm|rv|rmvb|smil)$/i;
  512. $et->SetFileType($type);
  513. return 1 if $fast3;
  514. undef $type;
  515. }
  516. # save URL or Text from RAM file
  517. my $tag = $buff =~ m{^[a-z]{3,4}://} ? 'url' : 'txt';
  518. $et->HandleTag($tagTablePtr, $tag, $buff);
  519. }
  520. return 1;
  521. }
  522. $et->SetFileType($type);
  523. return 1 if $fast3;
  524. SetByteOrder('MM');
  525. my $verbose = $et->Options('Verbose');
  526. #
  527. # Process RealAudio file
  528. #
  529. if ($type eq 'RA') {
  530. ($vers, $extra) = unpack('x4nn', $buff);
  531. $tag = ".ra$vers";
  532. my $fpos = $raf->Tell();
  533. unless ($raf->Read($buff, 512)) {
  534. $et->Warn('Error reading audio header');
  535. return 1;
  536. }
  537. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
  538. if ($verbose > 2) {
  539. $et->VerboseInfo($tag, $tagInfo, DataPt => \$buff, DataPos => $fpos);
  540. }
  541. if ($tagInfo) {
  542. my $subTablePtr = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
  543. my %dirInfo = (
  544. DataPt => \$buff,
  545. DataPos => $fpos,
  546. DirLen => length $buff,
  547. DirStart => 0,
  548. );
  549. $et->ProcessDirectory(\%dirInfo, $subTablePtr);
  550. } else {
  551. $et->Warn('Unsupported RealAudio version');
  552. }
  553. return 1;
  554. }
  555. #
  556. # Process RealMedia file
  557. #
  558. # skip the rest of the RM header
  559. my $size = unpack('x4N', $buff);
  560. unless ($raf->Seek($size - 8, 1)) {
  561. $et->Warn('Error seeking in file');
  562. return 0;
  563. }
  564. # Process RealMedia chunks
  565. for (;;) {
  566. $raf->Read($buff, 10) == 10 or last;
  567. ($tag, $size, $vers) = unpack('a4Nn', $buff);
  568. last if $tag eq "\0\0\0\0";
  569. if ($verbose) {
  570. $et->VPrint(0, "$tag chunk ($size bytes):\n");
  571. } else {
  572. last if $tag eq 'DATA'; # stop normal parsing at DATA tag
  573. }
  574. if ($size & 0x80000000) {
  575. $et->Warn('Bad chunk header');
  576. last;
  577. }
  578. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
  579. if ($tagInfo and $$tagInfo{SubDirectory}) {
  580. my $fpos = $raf->Tell();
  581. unless ($raf->Read($buff, $size-10) == $size-10) {
  582. $et->Warn("Error reading $tag chunk");
  583. last;
  584. }
  585. if ($verbose > 2) {
  586. $et->VerboseInfo($tag, $tagInfo, DataPt => \$buff, DataPos => $fpos);
  587. }
  588. my $subTablePtr = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
  589. my %dirInfo = (
  590. DataPt => \$buff,
  591. DataPos => $fpos,
  592. DirLen => length $buff,
  593. DirStart => 0,
  594. );
  595. if ($dirCount{$tag}) {
  596. $$et{SET_GROUP1} = '+' . ++$dirCount{$tag};
  597. } else {
  598. $dirCount{$tag} = 1;
  599. }
  600. $et->ProcessDirectory(\%dirInfo, $subTablePtr);
  601. delete $$et{SET_GROUP1};
  602. # keep track of stream MIME types
  603. my $mime = $$et{RealStreamMime};
  604. if ($mime) {
  605. delete $$et{RealStreamMime};
  606. $mime =~ s/\0.*//s;
  607. push @mimeTypes, $mime unless $mime =~ /^logical-/;
  608. }
  609. } else {
  610. unless ($raf->Seek($size-10, 1)) {
  611. $et->Warn('Error seeking in file');
  612. last;
  613. }
  614. }
  615. }
  616. # override MIMEType with stream MIME type if we only have one stream
  617. if (@mimeTypes == 1 and length $mimeTypes[0]) {
  618. $$et{VALUE}{MIMEType} = $mimeTypes[0];
  619. $et->VPrint(0, " MIMEType = $mimeTypes[0]\n");
  620. }
  621. #
  622. # Process footer containing Real metadata and ID3 information
  623. #
  624. if ($raf->Seek(-140, 2) and $raf->Read($buff, 12) == 12 and $buff =~ /^RMJE/) {
  625. my $metaSize = unpack('x8N', $buff);
  626. if ($raf->Seek(-$metaSize-12, 1) and
  627. $raf->Read($buff, $metaSize) == $metaSize and
  628. $buff =~ /^RJMD/)
  629. {
  630. my %dirInfo = (
  631. DataPt => \$buff,
  632. DataPos => $raf->Tell() - $metaSize,
  633. DirStart => 8,
  634. DirLen => length($buff) - 8,
  635. );
  636. my $tagTablePtr = GetTagTable('Image::ExifTool::Real::Metadata');
  637. $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
  638. } else {
  639. $et->Warn('Bad metadata footer');
  640. }
  641. if ($raf->Seek(-128, 2) and $raf->Read($buff, 128) == 128 and $buff =~ /^TAG/) {
  642. $et->VPrint(0, "ID3v1:\n");
  643. my %dirInfo = (
  644. DataPt => \$buff,
  645. DirStart => 0,
  646. DirLen => length($buff),
  647. );
  648. my $tagTablePtr = GetTagTable('Image::ExifTool::ID3::v1');
  649. $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
  650. }
  651. }
  652. return 1;
  653. }
  654. 1; # end
  655. __END__
  656. =head1 NAME
  657. Image::ExifTool::Real - Read Real audio/video meta information
  658. =head1 SYNOPSIS
  659. This module is used by Image::ExifTool
  660. =head1 DESCRIPTION
  661. This module contains the routines required by Image::ExifTool to read meta
  662. information in RealAudio (RA), RealMedia (RM, RV and RMVB) and RealMedia
  663. Metafile (RAM and RPM) files.
  664. =head1 NOTES
  665. There must be a bug in the software that wrote the Metadata used in the test
  666. file t/images/Real.rm because the TrackLyricsDataSize word is written
  667. little-endian, but the Real format is big-endian.
  668. =head1 AUTHOR
  669. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  670. This library is free software; you can redistribute it and/or modify it
  671. under the same terms as Perl itself.
  672. =head1 REFERENCES
  673. =over 4
  674. =item L<http://www.getid3.org/>
  675. =item L<https://common.helixcommunity.org/nonav/2003/HCS_SDK_r5/htmfiles/rmff.htm>
  676. =back
  677. =head1 SEE ALSO
  678. L<Image::ExifTool::TagNames/Real Tags>,
  679. L<Image::ExifTool(3pm)|Image::ExifTool>
  680. =cut