Repository navigation
Conversation
94528b2 to
cda36af
Compare
|
Any chance of this making it into 1.11.0? I am suffering downstream issues that this pull request would solve. |
cda36af to
d658190
Compare
|
Could this PR be reviewed for an upcoming release please? In my setup MKV files with explicit ContentCompAlgo=0 on PGS tracks cause playback failure in Jellyfin Android TV even with subtitles disabled which triggers software transcoding that overwhelms my Raspberry Pi server. |
|
@rohitjoins Will you review this PR? |
|
Hi, any progress here |
| private boolean pendingEndTracks; | ||
|
|
||
| // Inflater for zlib compressed tracks | ||
| @Nullable private Inflater inflater; |
There was a problem hiding this comment.
Inflater holds native zlib resources (z_stream), but release() is still a no-op here. Calling if (inflater != null) { inflater.end(); inflater = null; } in release() avoids leaking native memory until GC finalization.
There was a problem hiding this comment.
The other places in this project where Inflater is used does not manually handle finalization, so I see no reason for this to be an exception. The GC will properly cleanup any native resources.
| // TODO: check and fail if more than one content encoding is present. | ||
| break; | ||
| case ID_CONTENT_COMPRESSION: | ||
| getCurrentTrack(id).hasContentCompression = true; |
There was a problem hiding this comment.
ID_CONTENT_COMPRESSION (0x5034) is the parent element for both zlib (ContentCompAlgo = 0, the Matroska default when omitted) and header stripping (ContentCompAlgo = 3). Setting hasContentCompression = true unconditionally here means header-stripped subtitle tracks will also enter the Util.maybeInflate branch in writeSubtitleSampleData (where ZLIB_INFLATE_HEADER == 0x78, ASCII 'x'). Clearing the zlib flag when ID_CONTENT_COMPRESSION_ALGORITHM is 3 (or tracking the algorithm explicitly) keeps header stripping and zlib separate.
There was a problem hiding this comment.
This is probably also the case for ID_CONTENT_ENCRYPTION. I prefer to follow the status of the current implementation. If you can demonstrate this is a problem with a valid MKV file, we can discuss it further.
| // This extractor only supports header stripping. | ||
| if (value != 3) { | ||
| // This extractor only supports header stripping and zlib compressed text tracks. | ||
| if (value != 3 && (value != 0 || getCurrentTrack(id).type != C.TRACK_TYPE_TEXT)) { |
There was a problem hiding this comment.
In EBML/Matroska, TrackEntry children have no required wire order, so ContentEncodings can appear before TrackType. If ID_CONTENT_COMPRESSION_ALGORITHM (0) is parsed before ID_TRACK_TYPE, getCurrentTrack(id).type is still C.TRACK_TYPE_UNKNOWN and a valid zlib subtitle track will be rejected. Validating ContentCompAlgo == 0 against currentTrack.type == C.TRACK_TYPE_TEXT in endMasterElement(ID_TRACK_ENTRY) avoids order-dependent failures (and also catches omitted ContentCompAlgo, which defaults to 0, on non-text tracks).
There was a problem hiding this comment.
I can't validate it in endMasterElement if the exception is already thrown. The PR would need more changes to not throw exceptions here. If you find an affected MKV and the androidx.media team wants to handle that case, then I can work on that.
|
I reproduced two issues with zlib-compressed SubRip tracks using the patch from
|
This PR solves #2361
The first commit implements the changes to support zlib compressed subtitles in SUBRIP, ASS, SSA and VTT.
PGS and VOBSUB already support zlib compressed subtitles (I verified this by creating a sample file with zlib compression) so no changes were needed.
The second commit adds the samples and new tests and dumps for those samples.
The implementation looks for the master element
ID_CONTENT_COMPRESSIONand when present, enables a boolean flag in the current track.Later, when a subtitle block is processed, a new
inflatedSubtitleSampleis used to hold the uncompressed data, and follows a similar approach toPgsParserandVobsubParserby using the methodUtil.maybeInflateand finally copies the result to the realsubtitleSample.The method
resetcould not be used because the input already contains the codec prefix at the beginning, so I usedSystem.arraycopyafter the prefix. Let me know if you prefer another approach.The samples were created from the existing ones with the closest tool that created them in the first place, so I've used both ffmpeg and mkvmerge. When running diffs on the dumps of the original mkv and derived mkv with zlib compression, the only changes are in the seekMap positions, so I don't think we can reuse other dumps as it's done for other tests, but I'm no expert on the seekMap so let me know if it's possible.
I've also mixed usages of the null terminated samples because zlib data may contain a null byte, so the decompression must be done before looking for a null byte.
The commands used were either of the two: