title: Android Media Recorder Video Encoding for HEVC(H.265) in Android
body: <p>Curently I am using <a href="https://developer.android.com/reference/android/media/MediaRecorder.VideoEncoder.html" rel="nofollow noreferrer"><strong>MediaRecorder.VideoEncoder Class</strong></a> for creating a HEVC(H.265) encoded video in Android.</p>
  
  <p>I am using <a href="https://developer.android.com/guide/topics/media/camera.html" rel="nofollow noreferrer"><strong>Camera Class</strong></a> with <strong>SurfaceView</strong> for start/stop camera preview,  and retrieve frames for encoding video(Recording Video).</p>
  
  <pre><code>   Camera mCamera = Camera.open();
     mCamera.setDisplayOrientation(90);
     mCamera.unlock();
  </code></pre>
  
  <p>For <strong>Encoding and recording</strong> video I am Using <strong><a href="https://developer.android.com/reference/android/media/MediaRecorder.html" rel="nofollow noreferrer">MediaRecorder</a></strong> with HEVC VideoEncoder.</p>
  
  <pre><code>    MediaRecordermMediaRecorder = new MediaRecorder();
      mMediaRecorder.setPreviewDisplay(surface);
      mMediaRecorder.setCamera(mCamera);
      mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
      //       mMediaRecorder.setOutputFormat(8);
      mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.HEVC);
      mMediaRecorder.setVideoEncodingBitRate(5000 * 1000);
      mMediaRecorder.setVideoFrameRate(30);
      mMediaRecorder.setVideoSize(640, 480);
      String basePath = BasePath.getBasePath(getApplicationContext());
      String VIDEO_PATH = new File(basePath, "v_" + currentTime) + ".mp4";
      mMediaRecorder.setOutputFile(VIDEO_PATH);
      try {
          mMediaRecorder.prepare();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
  
     //Used this **Start** function for recording start.
  
         mMediaRecorder.start();
  
     //When we stoped the Video recording Release MediaRecorder and especially the Camera as it's a shared
     // object that can be used by other applications
  
      mMediaRecorder.reset();
      mMediaRecorder.release();
      if (mCamera != null)
          mCamera.release();
  </code></pre>
  
  <p>But at the end I am facing <strong>Problem in saving Recorded video</strong> in local file and I am not able to track the problem which is cousing this issue in my code.</p>
  
  <p><a href="https://codeshare.io/G8NdJ5" rel="nofollow noreferrer">This is my full code class file used for Encoding</a>. </p>