mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Move VideoFrameProcessorFactory setter to Transformer
PiperOrigin-RevId: 531123743
This commit is contained in:
parent
82ede47398
commit
e8072ca2c7
@ -121,26 +121,23 @@ public class TransformerEndToEndTest {
|
||||
String testId = "videoEditing_withTextureInput_completesWithCorrectFrameCountAndDuration";
|
||||
Bitmap bitmap =
|
||||
new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET_URI_STRING)).get();
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setAssetLoaderFactory(
|
||||
new TestTextureAssetLoaderFactory(bitmap.getWidth(), bitmap.getHeight()))
|
||||
.build();
|
||||
int expectedFrameCount = 2;
|
||||
EGLContext currentContext = createOpenGlObjects();
|
||||
DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory =
|
||||
new DefaultVideoFrameProcessor.Factory.Builder()
|
||||
.setGlObjectsProvider(new DefaultGlObjectsProvider(currentContext))
|
||||
.build();
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setAssetLoaderFactory(
|
||||
new TestTextureAssetLoaderFactory(bitmap.getWidth(), bitmap.getHeight()))
|
||||
.setVideoFrameProcessorFactory(videoFrameProcessorFactory)
|
||||
.build();
|
||||
ImmutableList<Effect> videoEffects = ImmutableList.of(Presentation.createForHeight(480));
|
||||
EditedMediaItem editedMediaItem =
|
||||
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.EMPTY))
|
||||
.setDurationUs(C.MICROS_PER_SECOND)
|
||||
.setEffects(
|
||||
new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
videoEffects,
|
||||
videoFrameProcessorFactory))
|
||||
.setEffects(new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects))
|
||||
.build();
|
||||
int texId = generateTextureFromBitmap(bitmap);
|
||||
HandlerThread textureQueuingThread = new HandlerThread("textureQueuingThread");
|
||||
@ -178,25 +175,21 @@ public class TransformerEndToEndTest {
|
||||
String testId = "videoTranscoding_withTextureInput_completesWithCorrectFrameCountAndDuration";
|
||||
Bitmap bitmap =
|
||||
new DataSourceBitmapLoader(context).loadBitmap(Uri.parse(PNG_ASSET_URI_STRING)).get();
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setAssetLoaderFactory(
|
||||
new TestTextureAssetLoaderFactory(bitmap.getWidth(), bitmap.getHeight()))
|
||||
.build();
|
||||
int expectedFrameCount = 2;
|
||||
EGLContext currentContext = createOpenGlObjects();
|
||||
DefaultVideoFrameProcessor.Factory videoFrameProcessorFactory =
|
||||
new DefaultVideoFrameProcessor.Factory.Builder()
|
||||
.setGlObjectsProvider(new DefaultGlObjectsProvider(currentContext))
|
||||
.build();
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setAssetLoaderFactory(
|
||||
new TestTextureAssetLoaderFactory(bitmap.getWidth(), bitmap.getHeight()))
|
||||
.setVideoFrameProcessorFactory(videoFrameProcessorFactory)
|
||||
.build();
|
||||
EditedMediaItem editedMediaItem =
|
||||
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.EMPTY))
|
||||
.setDurationUs(C.MICROS_PER_SECOND)
|
||||
.setEffects(
|
||||
new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
/* videoEffects= */ ImmutableList.of(),
|
||||
videoFrameProcessorFactory))
|
||||
.build();
|
||||
int texId = generateTextureFromBitmap(bitmap);
|
||||
HandlerThread textureQueuingThread = new HandlerThread("textureQueuingThread");
|
||||
|
@ -17,10 +17,8 @@ package androidx.media3.transformer;
|
||||
|
||||
import androidx.media3.common.Effect;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.VideoFrameProcessor;
|
||||
import androidx.media3.common.audio.AudioProcessor;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.effect.DefaultVideoFrameProcessor;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
|
||||
@ -44,35 +42,15 @@ public final class Effects {
|
||||
* order of the list.
|
||||
*/
|
||||
public final ImmutableList<Effect> videoEffects;
|
||||
/**
|
||||
* The {@link VideoFrameProcessor.Factory} for the {@link VideoFrameProcessor} to use when
|
||||
* applying the {@code videoEffects} to the video frames.
|
||||
*/
|
||||
public final VideoFrameProcessor.Factory videoFrameProcessorFactory;
|
||||
|
||||
/**
|
||||
* Creates an instance using a {@link DefaultVideoFrameProcessor.Factory}.
|
||||
*
|
||||
* <p>This is equivalent to calling {@link Effects#Effects(List, List,
|
||||
* VideoFrameProcessor.Factory)} with a {@link DefaultVideoFrameProcessor.Factory}.
|
||||
*/
|
||||
public Effects(List<AudioProcessor> audioProcessors, List<Effect> videoEffects) {
|
||||
this(audioProcessors, videoEffects, new DefaultVideoFrameProcessor.Factory.Builder().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
*
|
||||
* @param audioProcessors The {@link #audioProcessors}.
|
||||
* @param videoEffects The {@link #videoEffects}.
|
||||
* @param videoFrameProcessorFactory The {@link #videoFrameProcessorFactory}.
|
||||
*/
|
||||
public Effects(
|
||||
List<AudioProcessor> audioProcessors,
|
||||
List<Effect> videoEffects,
|
||||
VideoFrameProcessor.Factory videoFrameProcessorFactory) {
|
||||
public Effects(List<AudioProcessor> audioProcessors, List<Effect> videoEffects) {
|
||||
this.audioProcessors = ImmutableList.copyOf(audioProcessors);
|
||||
this.videoEffects = ImmutableList.copyOf(videoEffects);
|
||||
this.videoFrameProcessorFactory = videoFrameProcessorFactory;
|
||||
}
|
||||
}
|
||||
|
@ -423,6 +423,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
return sampleConsumer.queueInputBitmap(inputBitmap, durationUs, frameRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) {
|
||||
sampleConsumer.setOnInputFrameProcessedListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queueInputTexture(int texId, long presentationTimeUs) {
|
||||
long globalTimestampUs = totalDurationUs + presentationTimeUs;
|
||||
@ -436,11 +441,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
return sampleConsumer.queueInputTexture(texId, presentationTimeUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) {
|
||||
sampleConsumer.setOnInputFrameProcessedListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getInputSurface() {
|
||||
return sampleConsumer.getInputSurface();
|
||||
|
@ -274,12 +274,16 @@ public final class Transformer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Set the {@link VideoFrameProcessor.Factory} in an {@link EditedMediaItem}, and
|
||||
* pass it to {@link #start(EditedMediaItem, String)} instead.
|
||||
* Sets the factory to be used to create {@link VideoFrameProcessor} instances.
|
||||
*
|
||||
* <p>The default value is a {@link DefaultVideoFrameProcessor.Factory} built with default
|
||||
* values.
|
||||
*
|
||||
* @param videoFrameProcessorFactory A {@link VideoFrameProcessor.Factory}.
|
||||
* @return This builder.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
@Deprecated
|
||||
public Builder setFrameProcessorFactory(
|
||||
public Builder setVideoFrameProcessorFactory(
|
||||
VideoFrameProcessor.Factory videoFrameProcessorFactory) {
|
||||
this.videoFrameProcessorFactory = videoFrameProcessorFactory;
|
||||
return this;
|
||||
@ -721,6 +725,7 @@ public final class Transformer {
|
||||
path,
|
||||
transformationRequest,
|
||||
assetLoaderFactory,
|
||||
videoFrameProcessorFactory,
|
||||
encoderFactory,
|
||||
muxerFactory,
|
||||
transformerInternalListener,
|
||||
@ -799,7 +804,7 @@ public final class Transformer {
|
||||
.setRemoveAudio(removeAudio)
|
||||
.setRemoveVideo(removeVideo)
|
||||
.setFlattenForSlowMotion(flattenForSlowMotion)
|
||||
.setEffects(new Effects(audioProcessors, videoEffects, videoFrameProcessorFactory))
|
||||
.setEffects(new Effects(audioProcessors, videoEffects))
|
||||
.build();
|
||||
start(editedMediaItem, path);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import androidx.media3.common.DebugViewProvider;
|
||||
import androidx.media3.common.Effect;
|
||||
import androidx.media3.common.Format;
|
||||
import androidx.media3.common.MimeTypes;
|
||||
import androidx.media3.common.VideoFrameProcessor;
|
||||
import androidx.media3.common.util.Clock;
|
||||
import androidx.media3.common.util.ConditionVariable;
|
||||
import androidx.media3.common.util.HandlerWrapper;
|
||||
@ -131,6 +132,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
String outputPath,
|
||||
TransformationRequest transformationRequest,
|
||||
AssetLoader.Factory assetLoaderFactory,
|
||||
VideoFrameProcessor.Factory videoFrameProcessorFactory,
|
||||
Codec.EncoderFactory encoderFactory,
|
||||
Muxer.Factory muxerFactory,
|
||||
Listener listener,
|
||||
@ -154,6 +156,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
/* sequenceIndex= */ i,
|
||||
composition,
|
||||
transformationRequest,
|
||||
videoFrameProcessorFactory,
|
||||
fallbackListener,
|
||||
debugViewProvider);
|
||||
EditedMediaItemSequence sequence = composition.sequences.get(i);
|
||||
@ -444,6 +447,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
private final ImmutableList<EditedMediaItem> editedMediaItems;
|
||||
private final Composition composition;
|
||||
private final TransformationRequest transformationRequest;
|
||||
private final VideoFrameProcessor.Factory videoFrameProcessorFactory;
|
||||
private final FallbackListener fallbackListener;
|
||||
private final DebugViewProvider debugViewProvider;
|
||||
private final Map<Integer, AddedTrackInfo> addedTrackInfoByTrackType;
|
||||
@ -454,12 +458,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
int sequenceIndex,
|
||||
Composition composition,
|
||||
TransformationRequest transformationRequest,
|
||||
VideoFrameProcessor.Factory videoFrameProcessorFactory,
|
||||
FallbackListener fallbackListener,
|
||||
DebugViewProvider debugViewProvider) {
|
||||
this.sequenceIndex = sequenceIndex;
|
||||
editedMediaItems = composition.sequences.get(sequenceIndex).editedMediaItems;
|
||||
this.composition = composition;
|
||||
this.transformationRequest = transformationRequest;
|
||||
this.videoFrameProcessorFactory = videoFrameProcessorFactory;
|
||||
this.fallbackListener = fallbackListener;
|
||||
this.debugViewProvider = debugViewProvider;
|
||||
addedTrackInfoByTrackType = new HashMap<>();
|
||||
@ -565,7 +571,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
transformationRequest,
|
||||
firstEditedMediaItem.effects.videoEffects,
|
||||
compositionPresentation,
|
||||
firstEditedMediaItem.effects.videoFrameProcessorFactory,
|
||||
videoFrameProcessorFactory,
|
||||
encoderFactory,
|
||||
muxerWrapper,
|
||||
/* errorConsumer= */ this::onError,
|
||||
|
@ -134,14 +134,14 @@ public class TextureAssetLoaderTest {
|
||||
|
||||
private static final class FakeSampleConsumer implements SampleConsumer {
|
||||
|
||||
@Override
|
||||
public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) {}
|
||||
|
||||
@Override
|
||||
public boolean queueInputTexture(int texId, long presentationTimeUs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnInputFrameProcessedListener(OnInputFrameProcessedListener listener) {}
|
||||
|
||||
@Override
|
||||
public void signalEndOfVideoInput() {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user