Skip to content

Commit

Permalink
Fix color info conversion in vpccBox method
Browse files Browse the repository at this point in the history
The color space should be used to determine the color
primaries and matrix coefficients, not the video range.

PiperOrigin-RevId: 688489212
(cherry picked from commit 31ece8c)
  • Loading branch information
SheenaChhabra authored and icbaker committed Nov 19, 2024
1 parent ca01023 commit 761cf4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions libraries/muxer/src/main/java/androidx/media3/muxer/Boxes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,11 @@ private static ByteBuffer vpcCBox(Format format) {
ByteBuffer contents = ByteBuffer.allocate(MAX_FIXED_LEAF_BOX_SIZE);

contents.putInt(versionAndFlags);
// Default value of videoRange is 0.
int videoRange = format.colorInfo != null ? format.colorInfo.colorRange : 0;
// Default value of videoRange is limited range (value 0).
int videoRange =
format.colorInfo != null && format.colorInfo.colorRange != Format.NO_VALUE
? format.colorInfo.colorRange
: 0;
ByteBuffer codecPrivateContent = parseVp9CodecPrivateFromCsd(csd0, videoRange);
contents.put(codecPrivateContent);

Expand All @@ -1542,10 +1545,16 @@ private static ByteBuffer vpcCBox(Format format) {
int matrixCoefficients = 1;

if (format.colorInfo != null) {
colourPrimaries = MEDIAFORMAT_STANDARD_TO_PRIMARIES_AND_MATRIX.get(videoRange).get(0);
transferCharacteristics =
MEDIAFORMAT_TRANSFER_TO_MP4_TRANSFER.get(format.colorInfo.colorTransfer);
matrixCoefficients = MEDIAFORMAT_STANDARD_TO_PRIMARIES_AND_MATRIX.get(videoRange).get(1);
ColorInfo colorInfo = format.colorInfo;
if (colorInfo.colorSpace != Format.NO_VALUE) {
colourPrimaries =
MEDIAFORMAT_STANDARD_TO_PRIMARIES_AND_MATRIX.get(colorInfo.colorSpace).get(0);
matrixCoefficients =
MEDIAFORMAT_STANDARD_TO_PRIMARIES_AND_MATRIX.get(colorInfo.colorSpace).get(1);
}
if (colorInfo.colorTransfer != Format.NO_VALUE) {
transferCharacteristics = MEDIAFORMAT_TRANSFER_TO_MP4_TRANSFER.get(colorInfo.colorTransfer);
}
}

contents.put((byte) colourPrimaries);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vp09 (141 bytes):
Data = length 133, hash 86CBFAF0
Data = length 133, hash 4A5066E0

0 comments on commit 761cf4a

Please sign in to comment.