简体   繁体   English

Android-MediaCodec的视频编码质量

[英]Android - Video encoding quality with MediaCodec

I use a Surface where I draw openGL images on it (and rotate them). 我在Surface上绘制openGL图像(并旋转它们)。 For some images, when I encode the video using MediaCodec, the result looks pixelated, or compressed.. 对于某些图像,当我使用MediaCodec编码视频时,结果看起来像是像素化的或压缩的。

Original background picture : 原始背景图片:

在此处输入图片说明

Result encoded : 结果编码:

在此处输入图片说明

You can see that on the bottom-left corner, it is pixelated. 您可以在左下角看到它是像素化的。

Here is the values I use to create the MediaCodec encoder : 这是我用来创建MediaCodec编码器的值:

    int width = 800;
    int height = 800;
    int bitRate = 10485760; // bps, = 10Mbps (1080p)
    bufferInfo = new MediaCodec.BufferInfo();
    MediaFormat format = MediaFormat.createVideoFormat(GLVideoEncoderImpl.MIME_TYPE, width, height);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
    try {
        mediaCodec = MediaCodec.createEncoderByType(GLVideoEncoderImpl.MIME_TYPE);
    } catch (IOException e) {
        e.printStackTrace();
        UtilsAndroid.throwException("Impossible to create media codec");
    }

    mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

Is it possible to improve the output quality ? 是否可以提高输出质量? Thanks in advance 提前致谢

For some images, the result looks pixelated, or compressed. 对于某些图像,结果看起来像素化或压缩。

Well, that's what lossy video compression does, especially when you look at stills of the video frames (video compression is nasty, and the perceptual error relies on the fact it's animating so you don't see it). 好吧,这就是有损视频压缩的作用,尤其是当您查看视频帧的静止图像时(视频压缩是令人讨厌的,并且感知错误取决于动画的事实,因此您看不到它)。

Things to try: 尝试的事情:

  • increase bitrate at a fixed FPS 以固定的FPS增加比特率
  • drop the framerate at a fixed bitrate, 以固定的比特率降低帧率
  • increase the number of I frames (which will reduce error propagation artefacts) 增加I帧的数量(这将减少错误传播伪像)
  • decrease the number of I frames (I frame take a lot more bits to encode than P frames and B frames, so lots of I frames means worse compression, which means worse quality in a fixed bitrate). 减少I帧的数量(与P帧和B帧相比,I帧需要编码的位要多得多,因此,大量I帧意味着更差的压缩率,这意味着固定比特率下的质量较差)。

However, note that most video encoders are designed to compress videos of the real world, and the perceptual errors are designed with that in mind. 但是,请注意,大多数视频编码器旨在压缩现实世界中的视频,并且在设计感知错误时会考虑到这一点。 Most tend to be rubbish at compressing simple gradient fills, line art, etc, unless you run them at very high bitrates. 除非您以非常高的比特率运行它们,否则大多数压缩简单的渐变填充,线条图等时都会产生垃圾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM