Commit c32794f0 by tofunmi Committed by microkatz

Update sample pipelines and frame processors to handle image input.

PiperOrigin-RevId: 506965394
parent 7684949f
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.util; package com.google.android.exoplayer2.util;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.EGLExt; import android.opengl.EGLExt;
import android.view.Surface; import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -123,6 +124,20 @@ public interface FrameProcessor { ...@@ -123,6 +124,20 @@ public interface FrameProcessor {
long DROP_OUTPUT_FRAME = -2; long DROP_OUTPUT_FRAME = -2;
/** /**
* Provides an input {@link Bitmap} to the {@link FrameProcessor}.
*
* <p>Can be called on any thread.
*
* @param inputBitmap The {@link Bitmap} queued to the {@link FrameProcessor}.
* @param durationUs The duration for which to display the {@code inputBitmap}, in microseconds.
* @param frameRate The frame rate at which to display the {@code inputBitmap}, in frames per
* second.
*/
// TODO(b/262693274): Remove duration & frameRate parameters when EditedMediaItem can be signalled
// down to the processors.
void queueInputBitmap(Bitmap inputBitmap, long durationUs, int frameRate);
/**
* Returns the input {@link Surface}, where {@link FrameProcessor} consumes input frames from. * Returns the input {@link Surface}, where {@link FrameProcessor} consumes input frames from.
* *
* <p>Can be called on any thread. * <p>Can be called on any thread.
......
...@@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; ...@@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.getLast;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
...@@ -408,6 +409,9 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -408,6 +409,9 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
} }
@Override @Override
public void queueInputBitmap(Bitmap inputBitmap, long durationUs, int frameRate) {}
@Override
public Surface getInputSurface() { public Surface getInputSurface() {
return inputSurface; return inputSurface;
} }
......
...@@ -34,7 +34,7 @@ import com.google.android.exoplayer2.video.ColorInfo; ...@@ -34,7 +34,7 @@ import com.google.android.exoplayer2.video.ColorInfo;
private final long streamStartPositionUs; private final long streamStartPositionUs;
private final MuxerWrapper muxerWrapper; private final MuxerWrapper muxerWrapper;
private final @C.TrackType int trackType; private final @C.TrackType int outputTrackType;
private boolean muxerWrapperTrackAdded; private boolean muxerWrapperTrackAdded;
...@@ -42,7 +42,10 @@ import com.google.android.exoplayer2.video.ColorInfo; ...@@ -42,7 +42,10 @@ import com.google.android.exoplayer2.video.ColorInfo;
Format firstInputFormat, long streamStartPositionUs, MuxerWrapper muxerWrapper) { Format firstInputFormat, long streamStartPositionUs, MuxerWrapper muxerWrapper) {
this.streamStartPositionUs = streamStartPositionUs; this.streamStartPositionUs = streamStartPositionUs;
this.muxerWrapper = muxerWrapper; this.muxerWrapper = muxerWrapper;
trackType = MimeTypes.getTrackType(firstInputFormat.sampleMimeType); outputTrackType =
MimeTypes.isImage(firstInputFormat.sampleMimeType)
? C.TRACK_TYPE_VIDEO
: MimeTypes.getTrackType(firstInputFormat.sampleMimeType);
} }
protected static TransformationException createNoSupportedMimeTypeException(Format format) { protected static TransformationException createNoSupportedMimeTypeException(Format format) {
...@@ -113,7 +116,7 @@ import com.google.android.exoplayer2.video.ColorInfo; ...@@ -113,7 +116,7 @@ import com.google.android.exoplayer2.video.ColorInfo;
} }
if (isMuxerInputEnded()) { if (isMuxerInputEnded()) {
muxerWrapper.endTrack(trackType); muxerWrapper.endTrack(outputTrackType);
return false; return false;
} }
...@@ -127,7 +130,7 @@ import com.google.android.exoplayer2.video.ColorInfo; ...@@ -127,7 +130,7 @@ import com.google.android.exoplayer2.video.ColorInfo;
// buffer from all samples so that they are guaranteed to start from zero in the output file. // buffer from all samples so that they are guaranteed to start from zero in the output file.
try { try {
if (!muxerWrapper.writeSample( if (!muxerWrapper.writeSample(
trackType, outputTrackType,
checkStateNotNull(muxerInputBuffer.data), checkStateNotNull(muxerInputBuffer.data),
muxerInputBuffer.isKeyFrame(), muxerInputBuffer.isKeyFrame(),
samplePresentationTimeUs)) { samplePresentationTimeUs)) {
......
...@@ -25,6 +25,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkState; ...@@ -25,6 +25,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkState;
import static com.google.android.exoplayer2.util.Util.SDK_INT; import static com.google.android.exoplayer2.util.Util.SDK_INT;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.view.Surface; import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -205,6 +206,11 @@ import org.checkerframework.dataflow.qual.Pure; ...@@ -205,6 +206,11 @@ import org.checkerframework.dataflow.qual.Pure;
} }
@Override @Override
public void queueInputBitmap(Bitmap inputBitmap, long durationUs, int frameRate) {
frameProcessor.queueInputBitmap(inputBitmap, durationUs, frameRate);
}
@Override
public Surface getInputSurface() { public Surface getInputSurface() {
return frameProcessor.getInputSurface(); return frameProcessor.getInputSurface();
} }
...@@ -352,10 +358,15 @@ import org.checkerframework.dataflow.qual.Pure; ...@@ -352,10 +358,15 @@ import org.checkerframework.dataflow.qual.Pure;
this.transformationRequest = transformationRequest; this.transformationRequest = transformationRequest;
this.fallbackListener = fallbackListener; this.fallbackListener = fallbackListener;
requestedOutputMimeType = String inputSampleMimeType = checkNotNull(inputFormat.sampleMimeType);
transformationRequest.videoMimeType != null
? transformationRequest.videoMimeType if (transformationRequest.videoMimeType != null) {
: checkNotNull(inputFormat.sampleMimeType); requestedOutputMimeType = transformationRequest.videoMimeType;
} else if (MimeTypes.isImage(inputSampleMimeType)) {
requestedOutputMimeType = MimeTypes.VIDEO_H265;
} else {
requestedOutputMimeType = inputSampleMimeType;
}
supportedEncoderNamesForHdrEditing = supportedEncoderNamesForHdrEditing =
EncoderUtil.getSupportedEncoderNamesForHdrEditing( EncoderUtil.getSupportedEncoderNamesForHdrEditing(
requestedOutputMimeType, inputFormat.colorInfo); requestedOutputMimeType, inputFormat.colorInfo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment