MediaCodec encoder using Surface crashes inconsistently on various devices

你。 提交于 2019-12-22 11:25:27

问题


I'm developing an app that post processes video by applying graphics and text to the video. My code is based on the Android CTS test DecodeEditEncodeTest and it works great on the Nexus 4 and Nexus 5 (4.4) but not on any other device I've tried; not even the Nexus 7 II on 4.4. For example, on a Galaxy S3, I get the following errors:

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)

The relevant code:

        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);

It fails in different ways on other devices; I've tried Nexus 7 II, the G3, and HTC One (which didn't fail but created a garbage video).

Based on this error, it seems that the system is unhappy about the fact that the above code is executed from a Fragment that is displaying the original video using a MediaPlayer and SurfaceView.

I'd like to keep this view visible, so I tried to reset() and destroy() the MediaPlayer and in fact this made the app work correctly on the Nexus 7, but still not on the G3 nor the HTC One.

Is there something else I need to release? Or am I forced to destroy the fragment and use a different fragment for the post processing?


回答1:


The answer is to not go over 720p on both input and output videos




回答2:


Some times, the only way, is to restart the device, and the encoder continues working fine. nexus 5.. android 4.2.2.




回答3:


I also faced exactly same error logs during stress test when I was starting and stopping video decoding continuously.

My issues was that I missed releasing video decoder instance. After that I didn't get this issue.

I am not facing this issue when going more than 720p



来源:https://stackoverflow.com/questions/22581107/mediacodec-encoder-using-surface-crashes-inconsistently-on-various-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!