簡體   English   中英

Samsung Galaxy Note 4中的MediaCodec CodecException

[英]MediaCodec CodecException in Samsung galaxy note 4

我正在嘗試使用https://github.com/saki4510t/ScreenRecordingSample/tree/master/app/src/main/java/com/serenegiant/media來錄制屏幕,並提供了一些相關的代碼片段:

@Override
void prepare() throws IOException {
    if (DEBUG) Log.i(TAG, "prepare: ");
    mSurface = prepare_surface_encoder(MIME_TYPE, fps, bitrate);
    mMediaCodec.start();
    mIsRecording = true;
    new Thread(mScreenCaptureTask, "ScreenCaptureThread").start();
    if (DEBUG) Log.i(TAG, "prepare finishing");
    if (mListener != null) {
        try {
            mListener.onPrepared(this);
        } catch (final Exception e) {
            Log.e(TAG, "prepare:", e);
        }
    }
}   
protected MediaFormat create_encoder_format(final String mime, final int frame_rate, final int bitrate) {
    if (DEBUG) Log.v(TAG, String.format("create_encoder_format:(%d,%d),mime=%s,frame_rate=%d,bitrate=%d", mWidth, mHeight, mime, frame_rate, bitrate));
    final MediaFormat format = MediaFormat.createVideoFormat(mime, mWidth, mHeight);
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);  // API >= 18
    format.setInteger(MediaFormat.KEY_BIT_RATE, bitrate > 0 ? bitrate : calcBitRate(frame_rate)); //800000
    format.setInteger(MediaFormat.KEY_FRAME_RATE,30);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
    return format;
}

protected Surface prepare_surface_encoder(final String mime, final int frame_rate, final int bitrate)
    throws IOException, IllegalArgumentException {

    if (DEBUG) Log.v(TAG, String.format("prepare_surface_encoder:(%d,%d),mime=%s,frame_rate=%d,bitrate=%d", mWidth, mHeight, mime, frame_rate, bitrate));

    mTrackIndex = -1;
    mMuxerStarted = mIsEOS = false;

    final MediaCodecInfo videoCodecInfo = selectVideoCodec(mime);
    if (videoCodecInfo == null) {
        throw new IllegalArgumentException("Unable to find an appropriate codec for " + mime);
    }
    if (DEBUG) Log.i(TAG, "selected codec: " + videoCodecInfo.getName());

    final MediaFormat format = create_encoder_format(mime, frame_rate, bitrate);
    if (DEBUG) Log.i(TAG, "format: " + format);

    mMediaCodec = MediaCodec.createEncoderByType(mime);
    mMediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    // get Surface for encoder input
    // this method only can call between #configure and #start
    return mMediaCodec.createInputSurface();    // API >= 18
}

它適用於大多數設備,但不適用於運行android 6.0.1的Samsung Galaxy note 4。 我在哪里跟隨錯誤。

`Non-fatal Exception: android.media.MediaCodec$CodecException: Error 0xffffec77
   at android.media.MediaCodec.native_configure(MediaCodec.java)
   at android.media.MediaCodec.configure(MediaCodec.java:1778)
   at com.urcaddy.utilities.utils.media.MediaVideoEncoderBase.prepare_surface_encoder(MediaVideoEncoderBase.java:90)
   at com.urcaddy.utilities.utils.media.MediaScreenEncoder.prepare(MediaScreenEncoder.java:87)
   at com.urcaddy.utilities.utils.media.MediaMuxerWrapper.prepare(MediaMuxerWrapper.java:74)
   at com.urcaddy.services.backgroundservices.ScreenRecorderService.startScreenRecord(ScreenRecorderService.java:229)
   at com.urcaddy.services.backgroundservices.ScreenRecorderService.onStartCommand(ScreenRecorderService.java:139)
   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4062)
   at android.app.ActivityThread.access$2400(ActivityThread.java:221)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:158)
   at android.app.ActivityThread.main(ActivityThread.java:7225)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)`

經過大量的思考之后,我們發現問題出在高度和寬度上,下面是對我們有用的代碼。

protected MediaFormat create_encoder_format(final String mime, final int frame_rate, final int bitrate) {
if (DEBUG) Log.v(TAG, String.format("create_encoder_format:(%d,%d),mime=%s,frame_rate=%d,bitrate=%d", 720, 1280, mime, frame_rate, bitrate));
final MediaFormat format = MediaFormat.createVideoFormat(mime, 720, 1280);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);  // API >= 18
format.setInteger(MediaFormat.KEY_BIT_RATE, bitrate > 0 ? bitrate : calcBitRate(frame_rate)); //800000
format.setInteger(MediaFormat.KEY_FRAME_RATE,30);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
return format;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM