Change getVideoTrackOutput() to getTrackOutput()

The updated method can be used for audio as well.

PiperOrigin-RevId: 742673561
This commit is contained in:
sheenachhabra 2025-04-01 06:34:34 -07:00 committed by Copybara-Service
parent c95544156d
commit 209ecce6b3
3 changed files with 24 additions and 15 deletions

View File

@ -69,6 +69,7 @@ import androidx.media3.effect.ScaleAndRotateTransformation;
import androidx.media3.effect.SingleInputVideoGraph; import androidx.media3.effect.SingleInputVideoGraph;
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector; import androidx.media3.exoplayer.mediacodec.MediaCodecSelector;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil; import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
import androidx.media3.extractor.ExtractorOutput;
import androidx.media3.muxer.MuxerException; import androidx.media3.muxer.MuxerException;
import androidx.media3.test.utils.BitmapPixelTestUtil; import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.media3.test.utils.FakeExtractorOutput; import androidx.media3.test.utils.FakeExtractorOutput;
@ -1239,14 +1240,21 @@ public final class AndroidTestUtil {
} }
/** /**
* Returns the {@linkplain FakeTrackOutput video track} from the {@link FakeExtractorOutput} or * Returns a {@link FakeTrackOutput} of given {@link C.TrackType} from the {@link
* {@code null} if a video track is not found. * FakeExtractorOutput}.
*
* @param extractorOutput The {@link ExtractorOutput} to get the {@link FakeTrackOutput} from.
* @param trackType The {@link C.TrackType}.
* @return The {@link FakeTrackOutput} or {@code null} if a track is not found.
*/ */
@Nullable @Nullable
public static FakeTrackOutput getVideoTrackOutput(FakeExtractorOutput extractorOutput) { public static FakeTrackOutput getTrackOutput(
FakeExtractorOutput extractorOutput, @C.TrackType int trackType) {
for (int i = 0; i < extractorOutput.numberOfTracks; i++) { for (int i = 0; i < extractorOutput.numberOfTracks; i++) {
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(i); FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(i);
if (MimeTypes.isVideo(checkNotNull(trackOutput.lastFormat).sampleMimeType)) { String sampleMimeType = checkNotNull(trackOutput.lastFormat).sampleMimeType;
if ((trackType == C.TRACK_TYPE_AUDIO && MimeTypes.isAudio(sampleMimeType))
|| (trackType == C.TRACK_TYPE_VIDEO && MimeTypes.isVideo(sampleMimeType))) {
return trackOutput; return trackOutput;
} }
} }

View File

@ -47,7 +47,7 @@ import static androidx.media3.transformer.AndroidTestUtil.createFrameCountingEff
import static androidx.media3.transformer.AndroidTestUtil.createOpenGlObjects; import static androidx.media3.transformer.AndroidTestUtil.createOpenGlObjects;
import static androidx.media3.transformer.AndroidTestUtil.generateTextureFromBitmap; import static androidx.media3.transformer.AndroidTestUtil.generateTextureFromBitmap;
import static androidx.media3.transformer.AndroidTestUtil.getMuxerFactoryBasedOnApi; import static androidx.media3.transformer.AndroidTestUtil.getMuxerFactoryBasedOnApi;
import static androidx.media3.transformer.AndroidTestUtil.getVideoTrackOutput; import static androidx.media3.transformer.AndroidTestUtil.getTrackOutput;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped; import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_NA; import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_NA;
import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_TRANSCODED; import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_TRANSCODED;
@ -1057,7 +1057,7 @@ public class TransformerEndToEndTest {
TestUtil.extractAllSamplesFromFilePath(mp4Extractor, checkNotNull(result.filePath)); TestUtil.extractAllSamplesFromFilePath(mp4Extractor, checkNotNull(result.filePath));
assertThat(result.exportResult.fileSizeBytes).isGreaterThan(0); assertThat(result.exportResult.fileSizeBytes).isGreaterThan(0);
List<Long> videoTimestampsUs = List<Long> videoTimestampsUs =
checkNotNull(getVideoTrackOutput(fakeExtractorOutput)).getSampleTimesUs(); checkNotNull(getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO)).getSampleTimesUs();
assertThat(videoTimestampsUs).hasSize(270); assertThat(videoTimestampsUs).hasSize(270);
assertThat(videoTimestampsUs.get(0)).isEqualTo(0); assertThat(videoTimestampsUs.get(0)).isEqualTo(0);
// The second sample is originally at 1_033_333, clipping at 100_000 results in 933_333. // The second sample is originally at 1_033_333, clipping at 100_000 results in 933_333.
@ -1086,7 +1086,7 @@ public class TransformerEndToEndTest {
TestUtil.extractAllSamplesFromFilePath(mp4Extractor, checkNotNull(result.filePath)); TestUtil.extractAllSamplesFromFilePath(mp4Extractor, checkNotNull(result.filePath));
assertThat(result.exportResult.fileSizeBytes).isGreaterThan(0); assertThat(result.exportResult.fileSizeBytes).isGreaterThan(0);
List<Long> videoTimestampsUs = List<Long> videoTimestampsUs =
checkNotNull(getVideoTrackOutput(fakeExtractorOutput)).getSampleTimesUs(); checkNotNull(getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO)).getSampleTimesUs();
assertThat(videoTimestampsUs).hasSize(270); assertThat(videoTimestampsUs).hasSize(270);
assertThat(videoTimestampsUs.get(0)).isEqualTo(0); assertThat(videoTimestampsUs.get(0)).isEqualTo(0);
// The second sample is originally at 1_033_333, clipping at 100_000 results in 933_333. // The second sample is originally at 1_033_333, clipping at 100_000 results in 933_333.

View File

@ -17,11 +17,12 @@ package androidx.media3.transformer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported; import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported;
import static androidx.media3.transformer.AndroidTestUtil.getVideoTrackOutput; import static androidx.media3.transformer.AndroidTestUtil.getTrackOutput;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import android.content.Context; import android.content.Context;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.extractor.mp4.Mp4Extractor; import androidx.media3.extractor.mp4.Mp4Extractor;
import androidx.media3.extractor.text.DefaultSubtitleParserFactory; import androidx.media3.extractor.text.DefaultSubtitleParserFactory;
@ -98,7 +99,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1024ms with 30 fps. // The gap is for 1024ms with 30 fps.
int expectedBlankFrames = 31; int expectedBlankFrames = 31;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -127,7 +128,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1024ms with 30 fps. // The gap is for 1024ms with 30 fps.
int expectedBlankFrames = 31; int expectedBlankFrames = 31;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -183,7 +184,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1 sec with 30 fps. // The gap is for 1 sec with 30 fps.
int expectedBlankFrames = 30; int expectedBlankFrames = 30;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -216,7 +217,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1 sec with 30 fps. // The gap is for 1 sec with 30 fps.
int expectedBlankFrames = 30; int expectedBlankFrames = 30;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -271,7 +272,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1 sec with 30 fps. // The gap is for 1 sec with 30 fps.
int expectedBlankFrames = 30; int expectedBlankFrames = 30;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -303,7 +304,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1 sec with 30 fps. // The gap is for 1 sec with 30 fps.
int expectedBlankFrames = 30; int expectedBlankFrames = 30;
assertThat(videoTrackOutput.getSampleCount()) assertThat(videoTrackOutput.getSampleCount())
@ -336,7 +337,7 @@ public class TransformerGapsTest {
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath( TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath); new Mp4Extractor(new DefaultSubtitleParserFactory()), result.filePath);
FakeTrackOutput videoTrackOutput = getVideoTrackOutput(fakeExtractorOutput); FakeTrackOutput videoTrackOutput = getTrackOutput(fakeExtractorOutput, C.TRACK_TYPE_VIDEO);
// The gap is for 1024ms with 30 fps. // The gap is for 1024ms with 30 fps.
int expectedBlankFramesForAudioOnlyItem = 31; int expectedBlankFramesForAudioOnlyItem = 31;
// The gap is for 1 sec with 30 fps. // The gap is for 1 sec with 30 fps.