mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Format.Builder: Migrate MatroskaExtractor
Selection flags and language tags appear to apply to all tracks in MKV, so I think the change in output is correct. PiperOrigin-RevId: 297646190
This commit is contained in:
parent
56dbe83a4c
commit
db97d0c37c
@ -2064,18 +2064,20 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
throw new ParserException("Unrecognized codec identifier.");
|
throw new ParserException("Unrecognized codec identifier.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int type;
|
|
||||||
Format format;
|
|
||||||
@C.SelectionFlags int selectionFlags = 0;
|
@C.SelectionFlags int selectionFlags = 0;
|
||||||
selectionFlags |= flagDefault ? C.SELECTION_FLAG_DEFAULT : 0;
|
selectionFlags |= flagDefault ? C.SELECTION_FLAG_DEFAULT : 0;
|
||||||
selectionFlags |= flagForced ? C.SELECTION_FLAG_FORCED : 0;
|
selectionFlags |= flagForced ? C.SELECTION_FLAG_FORCED : 0;
|
||||||
|
|
||||||
|
int type;
|
||||||
|
Format.Builder formatBuilder = new Format.Builder();
|
||||||
// TODO: Consider reading the name elements of the tracks and, if present, incorporating them
|
// TODO: Consider reading the name elements of the tracks and, if present, incorporating them
|
||||||
// into the trackId passed when creating the formats.
|
// into the trackId passed when creating the formats.
|
||||||
if (MimeTypes.isAudio(mimeType)) {
|
if (MimeTypes.isAudio(mimeType)) {
|
||||||
type = C.TRACK_TYPE_AUDIO;
|
type = C.TRACK_TYPE_AUDIO;
|
||||||
format = Format.createAudioSampleFormat(Integer.toString(trackId), mimeType, null,
|
formatBuilder
|
||||||
Format.NO_VALUE, maxInputSize, channelCount, sampleRate, pcmEncoding,
|
.setChannelCount(channelCount)
|
||||||
initializationData, drmInitData, selectionFlags, language);
|
.setSampleRate(sampleRate)
|
||||||
|
.setPcmEncoding(pcmEncoding);
|
||||||
} else if (MimeTypes.isVideo(mimeType)) {
|
} else if (MimeTypes.isVideo(mimeType)) {
|
||||||
type = C.TRACK_TYPE_VIDEO;
|
type = C.TRACK_TYPE_VIDEO;
|
||||||
if (displayUnit == Track.DISPLAY_UNIT_PIXELS) {
|
if (displayUnit == Track.DISPLAY_UNIT_PIXELS) {
|
||||||
@ -2086,9 +2088,9 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
if (displayWidth != Format.NO_VALUE && displayHeight != Format.NO_VALUE) {
|
if (displayWidth != Format.NO_VALUE && displayHeight != Format.NO_VALUE) {
|
||||||
pixelWidthHeightRatio = ((float) (height * displayWidth)) / (width * displayHeight);
|
pixelWidthHeightRatio = ((float) (height * displayWidth)) / (width * displayHeight);
|
||||||
}
|
}
|
||||||
ColorInfo colorInfo = null;
|
@Nullable ColorInfo colorInfo = null;
|
||||||
if (hasColorInfo) {
|
if (hasColorInfo) {
|
||||||
byte[] hdrStaticInfo = getHdrStaticInfo();
|
@Nullable byte[] hdrStaticInfo = getHdrStaticInfo();
|
||||||
colorInfo = new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo);
|
colorInfo = new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo);
|
||||||
}
|
}
|
||||||
int rotationDegrees = Format.NO_VALUE;
|
int rotationDegrees = Format.NO_VALUE;
|
||||||
@ -2117,60 +2119,40 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
rotationDegrees = 270;
|
rotationDegrees = 270;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format =
|
formatBuilder
|
||||||
Format.createVideoSampleFormat(
|
.setWidth(width)
|
||||||
Integer.toString(trackId),
|
.setHeight(height)
|
||||||
mimeType,
|
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
|
||||||
/* codecs= */ null,
|
.setRotationDegrees(rotationDegrees)
|
||||||
/* bitrate= */ Format.NO_VALUE,
|
.setProjectionData(projectionData)
|
||||||
maxInputSize,
|
.setStereoMode(stereoMode)
|
||||||
width,
|
.setColorInfo(colorInfo);
|
||||||
height,
|
|
||||||
/* frameRate= */ Format.NO_VALUE,
|
|
||||||
initializationData,
|
|
||||||
rotationDegrees,
|
|
||||||
pixelWidthHeightRatio,
|
|
||||||
projectionData,
|
|
||||||
stereoMode,
|
|
||||||
colorInfo,
|
|
||||||
drmInitData);
|
|
||||||
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) {
|
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) {
|
||||||
type = C.TRACK_TYPE_TEXT;
|
type = C.TRACK_TYPE_TEXT;
|
||||||
format =
|
|
||||||
Format.createTextSampleFormat(
|
|
||||||
Integer.toString(trackId), mimeType, selectionFlags, language)
|
|
||||||
.copyWithDrmInitData(drmInitData);
|
|
||||||
} else if (MimeTypes.TEXT_SSA.equals(mimeType)) {
|
} else if (MimeTypes.TEXT_SSA.equals(mimeType)) {
|
||||||
type = C.TRACK_TYPE_TEXT;
|
type = C.TRACK_TYPE_TEXT;
|
||||||
initializationData = new ArrayList<>(2);
|
initializationData = new ArrayList<>(2);
|
||||||
initializationData.add(SSA_DIALOGUE_FORMAT);
|
initializationData.add(SSA_DIALOGUE_FORMAT);
|
||||||
initializationData.add(codecPrivate);
|
initializationData.add(codecPrivate);
|
||||||
format =
|
|
||||||
Format.createTextSampleFormat(
|
|
||||||
Integer.toString(trackId),
|
|
||||||
mimeType,
|
|
||||||
selectionFlags,
|
|
||||||
language,
|
|
||||||
/* accessibilityChannel= */ Format.NO_VALUE,
|
|
||||||
Format.OFFSET_SAMPLE_RELATIVE,
|
|
||||||
initializationData)
|
|
||||||
.copyWithDrmInitData(drmInitData);
|
|
||||||
} else if (MimeTypes.APPLICATION_VOBSUB.equals(mimeType)
|
} else if (MimeTypes.APPLICATION_VOBSUB.equals(mimeType)
|
||||||
|| MimeTypes.APPLICATION_PGS.equals(mimeType)
|
|| MimeTypes.APPLICATION_PGS.equals(mimeType)
|
||||||
|| MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)) {
|
|| MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)) {
|
||||||
type = C.TRACK_TYPE_TEXT;
|
type = C.TRACK_TYPE_TEXT;
|
||||||
format =
|
|
||||||
Format.createImageSampleFormat(
|
|
||||||
Integer.toString(trackId),
|
|
||||||
mimeType,
|
|
||||||
selectionFlags,
|
|
||||||
initializationData,
|
|
||||||
language)
|
|
||||||
.copyWithDrmInitData(drmInitData);
|
|
||||||
} else {
|
} else {
|
||||||
throw new ParserException("Unexpected MIME type.");
|
throw new ParserException("Unexpected MIME type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Format format =
|
||||||
|
formatBuilder
|
||||||
|
.setId(trackId)
|
||||||
|
.setSampleMimeType(mimeType)
|
||||||
|
.setMaxInputSize(maxInputSize)
|
||||||
|
.setLanguage(language)
|
||||||
|
.setSelectionFlags(selectionFlags)
|
||||||
|
.setInitializationData(initializationData)
|
||||||
|
.setDrmInitData(drmInitData)
|
||||||
|
.build();
|
||||||
|
|
||||||
this.output = output.track(number, type);
|
this.output = output.track(number, type);
|
||||||
this.output.format(format);
|
this.output.format(format);
|
||||||
}
|
}
|
||||||
@ -2335,7 +2317,5 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
throw new ParserException("Error parsing MS/ACM codec private");
|
throw new ParserException("Error parsing MS/ACM codec private");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ track 1:
|
|||||||
sampleMimeType = video/avc
|
sampleMimeType = video/avc
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
|
selectionFlags = 1
|
||||||
|
language = und
|
||||||
initializationData:
|
initializationData:
|
||||||
data = length 30, hash F6F3D010
|
data = length 30, hash F6F3D010
|
||||||
data = length 10, hash 7A0D0F2B
|
data = length 10, hash 7A0D0F2B
|
||||||
|
@ -14,6 +14,8 @@ track 1:
|
|||||||
sampleMimeType = video/avc
|
sampleMimeType = video/avc
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
|
selectionFlags = 1
|
||||||
|
language = und
|
||||||
initializationData:
|
initializationData:
|
||||||
data = length 30, hash F6F3D010
|
data = length 30, hash F6F3D010
|
||||||
data = length 10, hash 7A0D0F2B
|
data = length 10, hash 7A0D0F2B
|
||||||
|
@ -14,6 +14,8 @@ track 1:
|
|||||||
sampleMimeType = video/avc
|
sampleMimeType = video/avc
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
|
selectionFlags = 1
|
||||||
|
language = und
|
||||||
initializationData:
|
initializationData:
|
||||||
data = length 30, hash F6F3D010
|
data = length 30, hash F6F3D010
|
||||||
data = length 10, hash 7A0D0F2B
|
data = length 10, hash 7A0D0F2B
|
||||||
|
@ -14,6 +14,8 @@ track 1:
|
|||||||
sampleMimeType = video/avc
|
sampleMimeType = video/avc
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
|
selectionFlags = 1
|
||||||
|
language = und
|
||||||
initializationData:
|
initializationData:
|
||||||
data = length 30, hash F6F3D010
|
data = length 30, hash F6F3D010
|
||||||
data = length 10, hash 7A0D0F2B
|
data = length 10, hash 7A0D0F2B
|
||||||
|
@ -14,6 +14,8 @@ track 1:
|
|||||||
sampleMimeType = video/avc
|
sampleMimeType = video/avc
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
|
selectionFlags = 1
|
||||||
|
language = und
|
||||||
initializationData:
|
initializationData:
|
||||||
data = length 30, hash F6F3D010
|
data = length 30, hash F6F3D010
|
||||||
data = length 10, hash 7A0D0F2B
|
data = length 10, hash 7A0D0F2B
|
||||||
|
@ -11,6 +11,8 @@ track 1:
|
|||||||
sampleMimeType = video/x-vnd.on2.vp9
|
sampleMimeType = video/x-vnd.on2.vp9
|
||||||
width = 360
|
width = 360
|
||||||
height = 240
|
height = 240
|
||||||
|
selectionFlags = 1
|
||||||
|
language = en
|
||||||
drmInitData = 1305012705
|
drmInitData = 1305012705
|
||||||
sample 0:
|
sample 0:
|
||||||
time = 0
|
time = 0
|
||||||
|
@ -11,6 +11,8 @@ track 1:
|
|||||||
sampleMimeType = video/x-vnd.on2.vp9
|
sampleMimeType = video/x-vnd.on2.vp9
|
||||||
width = 360
|
width = 360
|
||||||
height = 240
|
height = 240
|
||||||
|
selectionFlags = 1
|
||||||
|
language = en
|
||||||
drmInitData = 1305012705
|
drmInitData = 1305012705
|
||||||
sample 0:
|
sample 0:
|
||||||
time = 0
|
time = 0
|
||||||
|
@ -11,6 +11,8 @@ track 1:
|
|||||||
sampleMimeType = video/x-vnd.on2.vp9
|
sampleMimeType = video/x-vnd.on2.vp9
|
||||||
width = 360
|
width = 360
|
||||||
height = 240
|
height = 240
|
||||||
|
selectionFlags = 1
|
||||||
|
language = en
|
||||||
drmInitData = 1305012705
|
drmInitData = 1305012705
|
||||||
sample 0:
|
sample 0:
|
||||||
time = 0
|
time = 0
|
||||||
|
@ -11,6 +11,8 @@ track 1:
|
|||||||
sampleMimeType = video/x-vnd.on2.vp9
|
sampleMimeType = video/x-vnd.on2.vp9
|
||||||
width = 360
|
width = 360
|
||||||
height = 240
|
height = 240
|
||||||
|
selectionFlags = 1
|
||||||
|
language = en
|
||||||
drmInitData = 1305012705
|
drmInitData = 1305012705
|
||||||
sample 0:
|
sample 0:
|
||||||
time = 0
|
time = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user