android - 使用 Surface 的 MediaCodec 编码器在各种设备上崩溃不一致

标签 android android-mediaplayer android-mediacodec

我正在开发一个应用程序,通过将图形和文本应用到视频来对视频进行后期处理。我的代码是基于Android CTS测试DecodeEditEncodeTest它在 Nexus 4 和 Nexus 5 (4.4) 上运行良好,但在我尝试过的任何其他设备上运行不佳;甚至 4.4 上的 Nexus 7 II 也不行。例如,在 Galaxy S3 上,我收到以下错误:

E/ACodec(17651):  configureCodec multi window instance fail  appPid : 17651
E/ACodec(17651): [OMX.qcom.video.decoder.avc] configureCodec returning error -38
E/MediaCodec(17651): Codec reported an error. (omx error 0x80001001, internalError -38)

相关代码:

        MediaCodecInfo codecInfo = selectCodec(MIME_TYPE);
        if (codecInfo == null) {
            // Don't fail CTS if they don't have an AVC codec (not here, anyway).
            Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
            return false;
        }
        if (VERBOSE) Log.d(TAG, "found codec: " + codecInfo.getName());

        // We avoid the device-specific limitations on width and height by using values that
        // are multiples of 16, which all tested devices seem to be able to handle.
        MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);

        // 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, mBitRate);
        format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
        format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
        if (VERBOSE) Log.d(TAG, "format: " + format);
        output.setMediaFormat(format);

        // Create a MediaCodec for the desired codec, then configure it as an encoder with
        // our desired properties.
        encoder = MediaCodec.createByCodecName(codecInfo.getName());
        encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

它在其他设备上以不同的方式失败;我已经尝试过 Nexus 7 II、G3 和 HTC One(没有失败,但创建了一个垃圾视频)。

基于此错误,系统似乎对上述代码是从使用 MediaPlayer 和 SurfaceView 显示原始视频的 Fragment 执行这一事实感到不满。

我想保持此 View 可见,所以我尝试重置 () 和销毁 () MediaPlayer,实际上这使应用程序在 Nexus 7 上正常工作,但在 G3 和 HTC One 上仍然不行.

还有什么我需要发布的吗?或者我是否被迫销毁 fragment 并使用不同的 fragment 进行后期处理?

最佳答案

答案是输入和输出视频都不要超过 720p

关于android - 使用 Surface 的 MediaCodec 编码器在各种设备上崩溃不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22581107/

相关文章:

android - 如何使用 Android AudioRecord 和 MediaCodec 作为音频编码器正确处理 PTS?

java - 安卓/java : stop a method from returning value until a part of the method is executed

android - LiveData 和 MVVM 模式

android - 将 Robolectric 与 android.support.v7.app.MediaRouteButton 结合使用

android - 当我在媒体播放器中单击 ListView 时,正在播放多首歌曲

android - 如何从MediaCodec获取解码格式?

android - 将来自 Android 应用程序的数据存储在 App Engine 数据存储区中

android - 在 Unity 中使用 Play Asset 交付后应用程序大小翻倍

android - 如何停止或取消 Mediaplayer.setOnPreparedListener 表单执行 Android

android - 使用 MediaCodec 在 Android 上使用 H264 数据解码 RTP 流