Add getNormalizedTrackType, mapping image to video track type.

PiperOrigin-RevId: 513514142
This commit is contained in:
samrobinson 2023-03-02 13:58:53 +00:00 committed by tonihei
parent 6042bec18a
commit ae4471debf
4 changed files with 50 additions and 14 deletions

View File

@ -21,6 +21,7 @@ import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static androidx.media3.transformer.TransformerUtil.getProcessedTrackType;
import android.graphics.Bitmap;
import android.os.Looper;
@ -191,9 +192,7 @@ import java.util.concurrent.atomic.AtomicInteger;
long streamStartPositionUs,
long streamOffsetUs)
throws ExportException {
// Consider image as video because image inputs are fed to the VideoSamplePipeline.
int trackType =
MimeTypes.isAudio(format.sampleMimeType) ? C.TRACK_TYPE_AUDIO : C.TRACK_TYPE_VIDEO;
@C.TrackType int trackType = getProcessedTrackType(format.sampleMimeType);
SampleConsumer sampleConsumer;
if (currentMediaItemIndex.get() == 0) {
boolean addForcedAudioTrack =

View File

@ -21,6 +21,7 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.transformer.EncoderUtil.getSupportedEncoders;
import static androidx.media3.transformer.EncoderUtil.getSupportedEncodersForHdrEditing;
import static androidx.media3.transformer.TransformerUtil.getProcessedTrackType;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
@ -55,10 +56,7 @@ import java.util.List;
Format firstInputFormat, long streamStartPositionUs, MuxerWrapper muxerWrapper) {
this.streamStartPositionUs = streamStartPositionUs;
this.muxerWrapper = muxerWrapper;
outputTrackType =
MimeTypes.isImage(firstInputFormat.sampleMimeType)
? C.TRACK_TYPE_VIDEO
: MimeTypes.getTrackType(firstInputFormat.sampleMimeType);
this.outputTrackType = getProcessedTrackType(firstInputFormat.sampleMimeType);
}
@Override

View File

@ -24,6 +24,7 @@ import static androidx.media3.transformer.ExportException.ERROR_CODE_FAILED_RUNT
import static androidx.media3.transformer.ExportException.ERROR_CODE_MUXING_FAILED;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static androidx.media3.transformer.TransformerUtil.getProcessedTrackType;
import static java.lang.annotation.ElementType.TYPE_USE;
import android.content.Context;
@ -452,11 +453,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
firstInputFormat, supportedOutputTypes, streamStartPositionUs, streamOffsetUs),
streamStartPositionUs,
streamOffsetUs);
// Consider image as video because image inputs are fed to the VideoSamplePipeline.
int trackType =
MimeTypes.isAudio(firstInputFormat.sampleMimeType)
? C.TRACK_TYPE_AUDIO
: C.TRACK_TYPE_VIDEO;
@C.TrackType int trackType = getProcessedTrackType(firstInputFormat.sampleMimeType);
compositeAssetLoaders
.get(sequenceIndex)
.addOnMediaItemChangedListener(samplePipeline, trackType);
@ -531,12 +528,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
(supportedOutputTypes & SUPPORTED_OUTPUT_TYPE_ENCODED) != 0;
checkArgument(assetLoaderCanOutputDecoded || assetLoaderCanOutputEncoded);
@C.TrackType int trackType = getProcessedTrackType(inputFormat.sampleMimeType);
boolean shouldTranscode = false;
if (!assetLoaderCanOutputEncoded) {
shouldTranscode = true;
} else if (MimeTypes.isAudio(inputFormat.sampleMimeType)) {
} else if (trackType == C.TRACK_TYPE_AUDIO) {
shouldTranscode = shouldTranscodeAudio(inputFormat);
} else if (MimeTypes.isVideo(inputFormat.sampleMimeType)) {
} else if (trackType == C.TRACK_TYPE_VIDEO) {
shouldTranscode = shouldTranscodeVideo(inputFormat, streamStartPositionUs, streamOffsetUs);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.media3.transformer;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.MimeTypes;
/** Utility methods for Transformer. */
/* package */ final class TransformerUtil {
private TransformerUtil() {}
/**
* Returns the {@link C.TrackType track type} constant corresponding to how a specified MIME type
* should be processed, which may be {@link C#TRACK_TYPE_UNKNOWN} if it could not be determined.
*
* <p>{@linkplain MimeTypes#isImage image} mime types are processed as {@link C#TRACK_TYPE_VIDEO}.
*
* <p>See {@link MimeTypes#getTrackType} for more details.
*/
public static @C.TrackType int getProcessedTrackType(@Nullable String mimeType) {
@C.TrackType int trackType = MimeTypes.getTrackType(mimeType);
return trackType == C.TRACK_TYPE_IMAGE ? C.TRACK_TYPE_VIDEO : trackType;
}
}