媒体编解码器可以输出类似RGB的格式吗?

问题描述 投票:0回答:1

我正在尝试使用Android Media Codec转换VP9视频。当我设置KEY_COLOR_FORMAT格式转换为YUV格式以外的格式时,出现以下错误:“ [[OMX.qcom.video.decoder.vp9]不支持颜色格式XXXX。“

例如,似乎不支持

COLOR_FormatSurface格式。或我做错了什么。我需要手动执行YUV到RGB转换吗?如果是,能够为编解码器提供Surfacetexture的目的是什么?

这里是示例代码:

public class VideoDecoder
{
    private MediaCodec mVideoCodec = null;
    private ByteBuffer[] mInputBuffers;
    private ByteBuffer[] mOutputBuffers;

    public VideoDecoder(int width, int height)
    {
        try
        {

            // Media settings
            MediaFormat format = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_VP9,
                    width,
                    height);


            format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
            // COLOR_FormatYUV420Flexible

            // Configure the decoder
            mVideoCodec =  MediaCodec.createDecoderByType(MediaFormat.MIMETYPE_VIDEO_VP9);

            mVideoCodec.configure(format,
                    null,
                    null,
                    0);

            // Start the decoder
            mVideoCodec.start();

            mInputBuffers = mVideoCodec.getInputBuffers();
            mOutputBuffers = mVideoCodec.getOutputBuffers();
        }
        catch(Exception e)
        {
            Log.e("VideoDecoder", "CreateCodec failed message =" + e.getMessage());
        }
    }

    public void release()
    {
        mVideoCodec.stop();
        mVideoCodec.release();
    }

    public void decode(byte[] rawBuffer, int frameSize)
    {
        //todo
    }
}

谢谢!

android mediacodec yuv
1个回答
0
投票

从媒体编解码器documentation开始,方法是使用Surface。它可以隐式地进行从编解码器输出到其纹理(BGRA)的转换。所以流程想:

1)在收到onFrameAvailable

回调后,调用Surface.updateTexImage()。需要在拥有当前图形上下文的线程上调用。

2)将纹理数据复制到另一个纹理。将需要使用着色器根据Surface变换矩阵来变换纹理坐标。

3)如果需要,请在CPU上读回结果。对于带有gles20.glreadpixels的ex]

© www.soinside.com 2019 - 2024. All rights reserved.