Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android record video without audio

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

Goal: to reduce the output file size.

like image 840
Sergii Avatar asked Aug 12 '12 08:08

Sergii


People also ask

Can you screen record without sound?

1) Slide up to access the Control Center. 2) Press firmly (or tap and hold) the Screen Recording button. 3) Tap the red microphone icon to turn Off the external audio. 4) Tap Start Recording.

How do I record a video without turning the music off?

Visit Play Store and install Play Music While Recording app. Start playing music you want to hear while recording. Open the Installed app and stay in Video mode. Start recording your video by tap on camera icon.


1 Answers

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;
}
like image 120
Nishant Singh Avatar answered Nov 09 '22 02:11

Nishant Singh