#include "media/mediarecorder.h"
using namespace android;
MediaRecorder *mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
camera_->unlock();
android::status_t err = mMediaRecorder->setCamera(camera_->remote(),
camera_->getRecordingProxy());
LOGD("Error %d", err);
// Step 2: Set sources
err = mMediaRecorder->setVideoSource(VIDEO_SOURCE_CAMERA);
LOGD("Error %d", err);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
err = mMediaRecorder->setOutputFormat(OUTPUT_FORMAT_MPEG_4);
LOGD("Error %d", err);
err = mMediaRecorder->setVideoEncoder(VIDEO_ENCODER_H264);
LOGD("Error %d", err);
// Step 4: Set output file
const char *fileName = "/sdcard/outputSurfEncMSourceGLDiff.mp4";
int fd = open(fileName, O_RDWR | O_CREAT, 0744);
if (fd < 0) {
LOGD("ERROR: Could not open the the file %s, fd = %d !!", fileName,
fd);
}
err = mMediaRecorder->setOutputFile(fd, 0, 0);
// Step 5: Set the preview output
// PS: I try to do without this step on android 4.1.1 but no success :(
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
LOGD("Error %d", err);
err = mMediaRecorder->setVideoSize(640, 480);
LOGD("Error %d", err);
err = mMediaRecorder->setVideoFrameRate(30);
LOGD("Error %d", err);
// Step 6: Prepare configured MediaRecorder
err = mMediaRecorder->prepare();
LOGD("Prepare err %d", err);
// Step 7: Start recording
err = mMediaRecorder->start();
// This is how to stop MediaRecorder from document: http://developer.android.com/guide/topics/media/camera.html
// Stop recording using MediaRecorder.stop()
// Release the media recorder with MediaRecorder.release()
// Lock the camera using Camera.lock()