title: Android Record Video from SURFACEVIEW using MediaRecorder
body: <p>I am new here.</p>
  
  <p>I have an app in android that streams camera over network and has a surfaceView component to show the preview(what I am streaming).</p>
  
  <p>I'd like to record what I see in preview(surfaceview) without reopen camera, because it is just opened from streaming.</p>
  
  <p>In lollipop I saw you can record using MediaRecorder api and setting the video source to SURFACE.</p>
  
  <p>How can I record simply adding a new MediaRecorder object that record from surface. Suppose you have all stuff setting, the app works and streams, showing preview in surfaceview component. I 'd like define a new recorder with the source set to surfaceview.</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>Hi, I have tryied to record using this code:</p>
  
  <pre><code>mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  mMediaRecorder.setOutputFile(getVideoFile(activity, true).getAbsolutePath());
  mMediaRecorder.setVideoEncodingBitRate(10000000);
  mMediaRecorder.setVideoFrameRate(30);
  mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  int orientation = ORIENTATIONS.get(rotation);
  mMediaRecorder.setOrientationHint(orientation);
  mMediaRecorder.prepare();
  </code></pre>
  
  <p>Consider you have the app that open the camera and stream out network and show preview in surfaceView. I want add a new mediarecorder that record what is in surfaceview.</p>