Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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

Following steps worked for me :-

  1. Uninstall the test app from your phone.

  2. Open command prompt at root folder location.

  3. cd ./android

  4. ./gradlew clean

  5. Run the project now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top