Commit 8bce0bc
authored
* [TIKA-4801] Extract cover art from ID3v2 APIC frames
Pictures embedded in ID3v2 tags (APIC in v2.3/v2.4, PIC in v2.2) are
handed to the standard EmbeddedDocumentExtractor as inline embedded
documents. The declared mime type becomes the embedded Content-Type,
the picture description becomes dc:title and the APIC picture type is
mapped to dc:description via the spec's label list. No new metadata
properties are recorded on the audio document itself: consumers that
only want to know whether cover art exists can use the embedded
document count.
Malformed picture frames (missing encoding, unterminated mime type or
description, empty picture data) are skipped silently, matching the
existing handling of malformed COMM frames. Linked v2.2 pictures
(image format "-->") are skipped as they carry a URL, not image data.
The fixture is a copy of testMP3id3v24.mp3 with a self-crafted APIC
frame (minimal 1x1 PNG) inserted before the existing frames and the
synchsafe tag size rewritten accordingly.
* [TIKA-4801] Extract cover art from the MP4 covr atom
The covr ilst entry, previously skipped explicitly, is handed to the
standard EmbeddedDocumentExtractor as an inline embedded document, one
per data atom (the atom may repeat for multiple images). The data
atom's well-known value type declares the image format (13 = jpeg,
14 = png, 27 = bmp); any other type is left for auto-detection. As in
the ID3v2 commit, no new metadata properties are recorded on the audio
document itself.
The ParseContext needed for the embedded document extractor is plumbed
from MP4Parser through TikaMp4BoxHandler into TikaUserDataBox.
The fixture is a copy of testMP4.m4a with a self-crafted covr entry
(minimal 1x1 PNG, type 14) appended to the ilst box and the ancestor
box sizes patched.
* [TIKA-4801] Extract cover art from Vorbis metadata block pictures
METADATA_BLOCK_PICTURE comments, base64 encoded FLAC picture blocks as
used by Vorbis and Opus (and shared by all Ogg family parsers through
OggAudioParser.extractComments), are handed to the standard
EmbeddedDocumentExtractor as inline embedded documents. The declared
mime type becomes the embedded Content-Type, the description becomes
dc:title and the picture type is mapped to dc:description through the
ID3v2 APIC label list, which the FLAC picture spec reuses. The raw
comment is excluded from the generic vorbis:* passthrough: a giant
base64 metadata value helps nobody once the picture is an embedded
document. Malformed or truncated blocks and linked pictures (mime
"-->") are skipped silently.
Native FLAC PICTURE blocks remain out of scope: vorbis-java 0.8 keeps
them in FlacFile.otherMetadata without a public accessor.
The fixture is a copy of testVORBIS.ogg with a self-crafted
metadata_block_picture comment (minimal 1x1 PNG) inserted into the
comment header packet, with the Ogg page lacing values and CRC
rewritten.
* [TIKA-4801] Extract cover art from native FLAC PICTURE blocks
vorbis-java 0.8 parses the native FLAC metadata blocks but offers no
accessor for them (FlacFile.getOtherMetadata() exists on their master,
unreleased since 0.8 in 2016), so FlacParser walks the metadata region
itself through a second stream over the spooled file: fLaC magic, then
per block 1 header byte (last-block flag plus type) and a 24 bit BE
length, stopping at the last-block flag, at end of stream or at a
block that declares more data than is left. The PICTURE block payload
(type 6) is byte-identical to the metadata_block_picture comment, so
the parsing and inline embedded-document emission are shared with
OggAudioParser through the extracted extractPictureBlock helper,
keeping the semantics of the previous commit unchanged.
Scope is native FLAC only: FLAC-in-Ogg carries its pictures in
metadata_block_picture comments, which the previous commit already
handles, and its PICTURE packets stay out of scope.
The fixture is a copy of testFLAC.flac from the standard integration
tests with a self-crafted PICTURE block (minimal 1x1 PNG) appended
after the previous last metadata block, whose last-block flag is
cleared.
* [TIKA-4801] Emit all embedded pictures, not just the first
An ID3v2.4 tag with several APIC frames only yielded the first
picture. ID3v2.4 encodes frame sizes as synchsafe integers, but
RawTag read them as plain integers, so any frame above 127 bytes,
which every real cover picture is, made the frame walk overshoot
into the middle of the following frames: with two covers the walk
consumed the second APIC as trailing bytes of the first and stopped
in the padding. The pictures were also emitted with that trailing
garbage attached.
RawTag now reads v2.4 frame sizes as synchsafe. Because widespread
taggers (e.g. older iTunes) wrote plain integers into v2.4 tags, the
two readings are disambiguated when they disagree: a size byte with
the high bit set forces plain, otherwise the reading wins that lands
the walk on a plausible next frame (frame id of capitals and digits,
padding, or the tag end). Sizes below 128 bytes, like all frames in
the existing v2.4 fixtures, are identical in both encodings.
The ID3v2.3 (plain sizes) path, the MP4 covr repeats, the FLAC
PICTURE walk and the Vorbis metadata_block_picture loop were checked
against the same loss pattern and were already correct; multi-cover
fixtures and tests for all of them are added as regression coverage.
The MP3 fixtures were generated with ffmpeg -id3v2_version 4 / 3
(front 64x40 png, back 30x30 png, both above 127 bytes); the MP4,
FLAC and Ogg fixtures extend the single-cover fixtures with a second
image (MP4: one covr record with a png and a jpeg data atom).
1 parent c18f268 commit 8bce0bc
29 files changed
Lines changed: 945 additions & 22 deletions
File tree
- tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src
- main/java/org/apache/tika/parser
- mp3
- mp4
- boxes
- ogg
- test
- java/org/apache/tika/parser
- mp3
- mp4
- ogg
- resources/test-documents
Lines changed: 86 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
166 | 197 | | |
167 | 198 | | |
168 | 199 | | |
| |||
198 | 229 | | |
199 | 230 | | |
200 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
201 | 241 | | |
202 | 242 | | |
203 | 243 | | |
| |||
258 | 298 | | |
259 | 299 | | |
260 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
261 | 347 | | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
81 | 89 | | |
82 | 90 | | |
83 | 91 | | |
| |||
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
82 | 90 | | |
83 | 91 | | |
84 | 92 | | |
| |||
135 | 143 | | |
136 | 144 | | |
137 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| |||
Lines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
| |||
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
| |||
163 | 175 | | |
164 | 176 | | |
165 | 177 | | |
166 | | - | |
| 178 | + | |
| 179 | + | |
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
0 commit comments