TIKA-4779: Add audio:bitrate, audio:is-variable-bitrate and audio:has-drm#2953
Open
dschmidt wants to merge 1 commit into
Open
TIKA-4779: Add audio:bitrate, audio:is-variable-bitrate and audio:has-drm#2953dschmidt wants to merge 1 commit into
dschmidt wants to merge 1 commit into
Conversation
…s-drm
Part 2 of TIKA-4779, covering the audio properties that need parser work
rather than plain mapping.
MP3: the parser already walks every audio frame for the duration, and
frame duration does not depend on the bitrate, so the plain mean over
the frames is the true average bitrate and differing frame bitrates are
an exact variable bitrate signal. The only special case is the leading
Xing/Info/VBRI tag frame some encoders write: it is a valid MPEG frame
that carries no audio and may use a different bitrate, so it is detected
(via a new peek method on MpegStream) and kept out of the statistics.
Vorbis: the identification header declares upper/nominal/lower rates.
The nominal rate is mapped to audio:bitrate (or the shared bound when a
zero-width bracket is declared without a nominal rate), and the stream
counts as fixed rate when all three declared rates agree or when only a
zero-width bracket is declared.
MP4: a TikaMp4SoundHandler (same pattern as the box handler extensions
from TIKA-2861) walks the sound track's sample description entries.
Protected sample entry formats ('drms', 'enca') set audio:has-drm; the
esds elementary stream descriptor is located structurally below the
entry (honoring the version-dependent entry layout, QuickTime 'wave'
wrappers and the optional ES descriptor fields) and its average bitrate
is mapped to audio:bitrate.
Verified against the real files in the repo where they cover the
behavior: testVORBIS.ogg (copied from the integration tests; a real
quality-mode encoding with nominal 80000 and no bounds), the 192 kbps
testMP3lyrics.mp3 and the 128 kbps ID3 fixtures for constant bitrate,
and testMP4.m4a whose esds declares an average bitrate of 256000.
Synthetic fixtures fill only the gaps the repo has no real specimen
for: a variable bitrate MP3 (frames alternating 128/192 kbps), a
constant bitrate MP3 with an 'Info' tag frame at a different rate, a
DRM-protected M4A ('drms' sample entry) and an M4A whose ES descriptor
uses the optional dependency/URL/OCR fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of TIKA-4779, following up on #2947 with the three audio properties that need parser work rather than plain mapping:
audio:bitrate(average, bits per second),audio:is-variable-bitrateandaudio:has-drm, defined under Tika's own namespace inAudio.java.MP3: the parser already walks every audio frame for the duration, and since frame duration does not depend on the bitrate, the plain mean over the frames is the exact average and differing frame bitrates are an exact VBR signal. The one special case is the Xing/Info/VBRI tag frame some encoders write first: it is a valid MPEG frame without audio, often at a different bitrate than the stream, so it is detected and excluded (a CBR file with an Info tag would otherwise be misreported as VBR, there is a fixture proving exactly that). I deliberately did not go the usual route of reading the bitrate from the Xing table itself: the full frame walk already happens for the duration, so the exact mean is free and works for files without any tag frame.
Vorbis: the identification header declares upper/nominal/lower rates. Nominal maps to
audio:bitrate; a zero-width bracket (upper == lower, no nominal) also pins an exact rate. Fixed rate means all three declared rates agree, or only a zero-width bracket is declared; anything else counts as variable.MP4/M4A: a
TikaMp4SoundHandler(same extension pattern as TIKA-2861) structurally walks the sample description entries. Protected sample entry formats (drms,enca) setaudio:has-drm; these markers are readable by design since DRM encrypts the payload, not the metadata. The average bitrate comes from the esds elementary stream descriptor, located as a child box of the entry (honoring the version-dependent entry layout, QuickTimewavewrappers and the optional ES descriptor fields). I deliberately avoided scanning the stsd bytes for fourcc markers: codec private data or a URL field can legally contain the stringsinf, and a fixture covers that false positive.For files with several audio tracks the properties reflect the last sound track's sample description, consistent with how the existing MP4 audio metadata behaves.
Note: the
hdlrdispatch hook inTikaMp4BoxHandleroverlaps with #2936; whichever merges second has a trivial rebase.Tests run against real files where the repo has them (
testMP4.m4awith a declared average of 256000, the constant bitrate MP3 fixtures,testVORBIS.oggcopied from the integration tests). Synthetic fixtures cover only what no real specimen exercises: a VBR MP3, a CBR MP3 with an Info tag frame, adrmsprotected M4A and an M4A whose ES descriptor uses the optional fields.