Search in sources :

Example 1 with TransformationException

use of com.google.android.exoplayer2.transformer.TransformationException in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withIoError_completesWithError.

@Test
public void startTransformation_withIoError_completesWithError() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri("asset:///non-existing-path.mp4");
    transformer.startTransformation(mediaItem, outputPath);
    TransformationException exception = TransformerTestRunner.runUntilError(transformer);
    assertThat(exception).hasCauseThat().hasCauseThat().isInstanceOf(IOException.class);
    assertThat(exception.errorCode).isEqualTo(TransformationException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 2 with TransformationException

use of com.google.android.exoplayer2.transformer.TransformationException in project ExoPlayer by google.

the class FrameEditor method create.

/**
 * Returns a new {@code FrameEditor} for applying changes to individual frames.
 *
 * @param context A {@link Context}.
 * @param outputWidth The output width in pixels.
 * @param outputHeight The output height in pixels.
 * @param pixelWidthHeightRatio The ratio of width over height, for each pixel.
 * @param transformationMatrix The transformation matrix to apply to each frame.
 * @param outputSurface The {@link Surface}.
 * @param enableExperimentalHdrEditing Whether to attempt to process the input as an HDR signal.
 * @param debugViewProvider Provider for optional debug views to show intermediate output.
 * @return A configured {@code FrameEditor}.
 * @throws TransformationException If the {@code pixelWidthHeightRatio} isn't 1, reading shader
 *     files fails, or an OpenGL error occurs while creating and configuring the OpenGL
 *     components.
 */
public static FrameEditor create(Context context, int outputWidth, int outputHeight, float pixelWidthHeightRatio, Matrix transformationMatrix, Surface outputSurface, boolean enableExperimentalHdrEditing, Transformer.DebugViewProvider debugViewProvider) throws TransformationException {
    if (pixelWidthHeightRatio != 1.0f) {
        // TODO(b/211782176): Consider implementing support for non-square pixels.
        throw TransformationException.createForFrameEditor(new UnsupportedOperationException("Transformer's frame editor currently does not support frame edits on non-square" + " pixels. The pixelWidthHeightRatio is: " + pixelWidthHeightRatio), TransformationException.ERROR_CODE_GL_INIT_FAILED);
    }
    @Nullable SurfaceView debugSurfaceView = debugViewProvider.getDebugPreviewSurfaceView(outputWidth, outputHeight);
    EGLDisplay eglDisplay;
    EGLContext eglContext;
    EGLSurface eglSurface;
    int textureId;
    GlUtil.Program glProgram;
    @Nullable EGLSurface debugPreviewEglSurface = null;
    try {
        eglDisplay = GlUtil.createEglDisplay();
        if (enableExperimentalHdrEditing) {
            eglContext = GlUtil.createEglContextEs3Rgba1010102(eglDisplay);
            // TODO(b/209404935): Don't assume BT.2020 PQ input/output.
            eglSurface = GlUtil.getEglSurfaceBt2020Pq(eglDisplay, outputSurface);
            if (debugSurfaceView != null) {
                debugPreviewEglSurface = GlUtil.getEglSurfaceBt2020Pq(eglDisplay, checkNotNull(debugSurfaceView.getHolder()));
            }
        } else {
            eglContext = GlUtil.createEglContext(eglDisplay);
            eglSurface = GlUtil.getEglSurface(eglDisplay, outputSurface);
            if (debugSurfaceView != null) {
                debugPreviewEglSurface = GlUtil.getEglSurface(eglDisplay, checkNotNull(debugSurfaceView.getHolder()));
            }
        }
        GlUtil.focusSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight);
        textureId = GlUtil.createExternalTexture();
        glProgram = configureGlProgram(context, transformationMatrix, textureId, enableExperimentalHdrEditing);
    } catch (IOException | GlUtil.GlException e) {
        throw TransformationException.createForFrameEditor(e, TransformationException.ERROR_CODE_GL_INIT_FAILED);
    }
    int debugPreviewWidth;
    int debugPreviewHeight;
    if (debugSurfaceView != null) {
        debugPreviewWidth = debugSurfaceView.getWidth();
        debugPreviewHeight = debugSurfaceView.getHeight();
    } else {
        debugPreviewWidth = C.LENGTH_UNSET;
        debugPreviewHeight = C.LENGTH_UNSET;
    }
    return new FrameEditor(eglDisplay, eglContext, eglSurface, textureId, glProgram, outputWidth, outputHeight, debugPreviewEglSurface, debugPreviewWidth, debugPreviewHeight);
}
Also used : EGLSurface(android.opengl.EGLSurface) EGLDisplay(android.opengl.EGLDisplay) GlUtil(com.google.android.exoplayer2.util.GlUtil) EGLContext(android.opengl.EGLContext) IOException(java.io.IOException) Nullable(androidx.annotation.Nullable) SurfaceView(android.view.SurfaceView)

Example 3 with TransformationException

use of com.google.android.exoplayer2.transformer.TransformationException in project ExoPlayer by google.

the class TransformerAudioRenderer method ensureConfigured.

/**
 * Attempts to read the input format and to initialize the {@link SamplePipeline}.
 */
@Override
protected boolean ensureConfigured() throws TransformationException {
    if (samplePipeline != null) {
        return true;
    }
    FormatHolder formatHolder = getFormatHolder();
    @ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
    FLAG_REQUIRE_FORMAT);
    if (result != C.RESULT_FORMAT_READ) {
        return false;
    }
    Format inputFormat = checkNotNull(formatHolder.format);
    if (shouldPassthrough(inputFormat)) {
        samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
    } else {
        samplePipeline = new AudioTranscodingSamplePipeline(inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 4 with TransformationException

use of com.google.android.exoplayer2.transformer.TransformationException in project ExoPlayer by google.

the class TransformerBaseRenderer method feedMuxerFromPipeline.

/**
 * Attempts to write sample pipeline output data to the muxer.
 *
 * @return Whether it may be possible to write more data immediately by calling this method again.
 * @throws Muxer.MuxerException If a muxing problem occurs.
 * @throws TransformationException If a {@link SamplePipeline} problem occurs.
 */
@RequiresNonNull("samplePipeline")
private boolean feedMuxerFromPipeline() throws Muxer.MuxerException, TransformationException {
    if (!muxerWrapperTrackAdded) {
        @Nullable Format samplePipelineOutputFormat = samplePipeline.getOutputFormat();
        if (samplePipelineOutputFormat == null) {
            return false;
        }
        muxerWrapperTrackAdded = true;
        muxerWrapper.addTrackFormat(samplePipelineOutputFormat);
    }
    if (samplePipeline.isEnded()) {
        muxerWrapper.endTrack(getTrackType());
        muxerWrapperTrackEnded = true;
        return false;
    }
    @Nullable DecoderInputBuffer samplePipelineOutputBuffer = samplePipeline.getOutputBuffer();
    if (samplePipelineOutputBuffer == null) {
        return false;
    }
    if (!muxerWrapper.writeSample(getTrackType(), checkStateNotNull(samplePipelineOutputBuffer.data), samplePipelineOutputBuffer.isKeyFrame(), samplePipelineOutputBuffer.timeUs)) {
        return false;
    }
    samplePipeline.releaseOutputBuffer();
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 5 with TransformationException

use of com.google.android.exoplayer2.transformer.TransformationException in project ExoPlayer by google.

the class TransformerVideoRenderer method ensureConfigured.

/**
 * Attempts to read the input format and to initialize the {@link SamplePipeline}.
 */
@Override
protected boolean ensureConfigured() throws TransformationException {
    if (samplePipeline != null) {
        return true;
    }
    FormatHolder formatHolder = getFormatHolder();
    @ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
    FLAG_REQUIRE_FORMAT);
    if (result != C.RESULT_FORMAT_READ) {
        return false;
    }
    Format inputFormat = checkNotNull(formatHolder.format);
    if (shouldPassthrough(inputFormat)) {
        samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
    } else {
        samplePipeline = new VideoTranscodingSamplePipeline(context, inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener, debugViewProvider);
    }
    if (transformationRequest.flattenForSlowMotion) {
        sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)7 Nullable (androidx.annotation.Nullable)6 Test (org.junit.Test)5 Format (com.google.android.exoplayer2.Format)4 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)4 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)3 FormatHolder (com.google.android.exoplayer2.FormatHolder)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 IOException (java.io.IOException)2 SuppressLint (android.annotation.SuppressLint)1 Matrix (android.graphics.Matrix)1 MediaCodecInfo (android.media.MediaCodecInfo)1 MediaFormat (android.media.MediaFormat)1 Uri (android.net.Uri)1 EGLContext (android.opengl.EGLContext)1 EGLDisplay (android.opengl.EGLDisplay)1 EGLSurface (android.opengl.EGLSurface)1 SurfaceView (android.view.SurfaceView)1 TransformationException (com.google.android.exoplayer2.transformer.TransformationException)1 TransformationRequest (com.google.android.exoplayer2.transformer.TransformationRequest)1