title: Error while encode HEVC using Android MediaCodec on Samsung Galaxy S6
body: <p>I try using HEVC encoder support in Android MediaCodec for my stream app.
  It's succeed when i using H64 but crashed when i switch to HEVC.</p>
  
  <p>I tested in Samsung Galaxy S6 with Android 7.0, it crash while i queue a buffer to encoder.
  No problem when i using MediaRecorder with HEVC.</p>
  
  <p>My init code here:</p>
  
  <pre><code>        MediaFormat format = MediaFormat.createVideoFormat(CUR_CODEC, 640, 480);
          format.setInteger(MediaFormat.KEY_BIT_RATE, 500000);
          format.setInteger("bitrate-mode", 2);
          format.setInteger(MediaFormat.KEY_COLOR_FORMAT, COLOR_FormatYUV420Flexible);
          format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
          format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, -1);
  
          try {
              mEncoder = MediaCodec.createEncoderByType(CUR_CODEC);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
          mEncoder.start();
          outputBuffers = mEncoder.getOutputBuffers();
  </code></pre>
  
  <p>It run success with the log:</p>
  
  <pre><code>8-16 10:53:22.120 2285-2285/com.example.hanhnv.camapp I/ACodec:  [] Now uninitialized
  08-16 10:53:22.121 2285-5049/com.example.hanhnv.camapp I/ACodec: [] onAllocateComponent
  08-16 10:53:22.125 2285-5049/com.example.hanhnv.camapp I/OMXClient: MuxOMX ctor
  08-16 10:53:22.134 2285-5049/com.example.hanhnv.camapp I/ACodec: Set Google AAC Dec for aacProfile 0
  08-16 10:53:22.190 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] Now Loaded
  08-16 10:53:22.196 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] using color format 0x13 in place of 0x7f420888
  08-16 10:53:22.202 2285-5049/com.example.hanhnv.camapp I/ACodec: Success set VideoMinQP(0/0/0) VideoMaxQP(50/50/50)
  08-16 10:53:22.203 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] cannot encode color aspects. Ignoring.
  08-16 10:53:22.203 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] cannot encode HDR static metadata. Ignoring.
  08-16 10:53:22.203 2285-5049/com.example.hanhnv.camapp I/ACodec: setupVideoEncoder succeeded
  08-16 10:53:22.222 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] Now Loaded-&gt;Idle
  08-16 10:53:22.256 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] Now Idle-&gt;Executing
  08-16 10:53:22.258 2285-5049/com.example.hanhnv.camapp I/ACodec: [OMX.Exynos.HEVC.Encoder] Now Executing
  </code></pre>
  
  <p>This is my encode code:</p>
  
  <pre><code>        ByteBuffer data = mNewFrame.duplicate();
          ByteBuffer[] inputBuffers = mEncoder.getInputBuffers();
          int inputBufferIndex = mEncoder.dequeueInputBuffer(0);
          if (inputBufferIndex &gt;= 0) {
              inputBuffer = inputBuffers[inputBufferIndex];
              inputBuffer.clear();
              inputBuffer.put(data);
              mEncoder.queueInputBuffer(inputBufferIndex, 0, mNewDataSize, System.currentTimeMillis(), 0);
              Log.d(TAG, "addFrame " + System.nanoTime() / 1000 + "data size=" + mNewDataSize);
  
              mTotalFrame++;
              getEncodedFrame();
  
              mNewFrame = null;
              return true;
          }
  </code></pre>
  
  <p>And it raise an error while i dequeInputBuffer or queueInputBuffer and crashed with log:</p>
  
  <pre><code>08-16 10:53:22.293 3195-5087/? E/ExynosVideoEncoder: MFC_Encoder_Set_EncParam: Failed to SetControls
  08-16 10:53:22.293 3195-5087/? E/EXYNOS_HEVC_ENC: [0xe4c1b500][HEVCCodecSrcSetup] Failed to set encParam
  08-16 10:53:22.293 3195-5087/? E/EXYNOS_HEVC_ENC: [0xe4c1b500][Exynos_HEVCEnc_SrcIn] Failed to HEVCCodecSrcSetup(0xe8009000)
  08-16 10:53:22.294 2285-5049/com.example.hanhnv.camapp E/ACodec: [OMX.Exynos.HEVC.Encoder] ERROR(0x80001000)
  08-16 10:53:22.294 2285-5049/com.example.hanhnv.camapp E/ACodec: signalError(omxError 0x80001000, internalError -2147483648)
  08-16 10:53:22.294 2285-5048/com.example.hanhnv.camapp E/MediaCodec: Codec reported err 0x80001000, actionCode 0, while in state 6
  </code></pre>
  
  <p>I think that i used wrong setting for the encode before encoding. It run success if a change the codec to H264.
  Any one can help me please.
  Thank for your focus. </p>