Use audio passthrough if flattening is requested but not needed.
When the input is not a slow motion video, then flattening should do nothing, so there is no need to re-encode audio. PiperOrigin-RevId: 412443097
This commit is contained in:
parent
51762a4795
commit
041c3e9971
@ -19,12 +19,15 @@ package com.google.android.exoplayer2.transformer;
|
||||
import static com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT;
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.FormatHolder;
|
||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.mp4.SlowMotionData;
|
||||
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
|
||||
|
||||
@RequiresApi(18)
|
||||
@ -59,13 +62,29 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
|
||||
return false;
|
||||
}
|
||||
Format inputFormat = checkNotNull(formatHolder.format);
|
||||
if ((transformation.audioMimeType != null
|
||||
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType))
|
||||
|| transformation.flattenForSlowMotion) {
|
||||
boolean shouldChangeMimeType =
|
||||
transformation.audioMimeType != null
|
||||
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType);
|
||||
boolean shouldFlattenForSlowMotion =
|
||||
transformation.flattenForSlowMotion && isSlowMotion(inputFormat);
|
||||
if (shouldChangeMimeType || shouldFlattenForSlowMotion) {
|
||||
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
|
||||
} else {
|
||||
samplePipeline = new PassthroughSamplePipeline(inputFormat);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isSlowMotion(Format format) {
|
||||
@Nullable Metadata metadata = format.metadata;
|
||||
if (metadata == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < metadata.length(); i++) {
|
||||
if (metadata.get(i) instanceof SlowMotionData) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user