Android record video without audio

Sergii picture Sergii · Aug 12, 2012 · Viewed 15.6k times · Source

Is it possible in Android to record video from Camera without audio stream?

Goal: to reduce the output file size.

Answer

Nishant Singh picture Nishant Singh · Feb 12, 2014

You can prepare MediaRecorder by copying the required fields from inbuilt profile (CamcorderProfile). Just leave out the audio settings and you should be good to go. Edit code below for your needs, step 3 is the essential part here.

private boolean prepareVideoRecorder() {

    mCamera = getCameraInstance();
    mMediaRecorder = new MediaRecorder();

    // store the quality profile required
    CamcorderProfile profile = CamcorderProfile.get(cameraid, CamcorderProfile.QUALITY_HIGH);

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set all values contained in profile except audio settings
    mMediaRecorder.setOutputFormat(profile.fileFormat);
    mMediaRecorder.setVideoEncoder(profile.videoCodec);
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());

    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    // Step 6: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        releaseMediaRecorder();
        return false;
    }
    return true;
}