Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use CamcorderProfile without audio source?

My code:

mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);

CamcorderProfile profile = CamcorderProfile.get(QUALITY_LOW);
mediaRecorder.setProfile(profile);

It works. But I need to record only video.

And if I don't use mediaRecorder.setAudioSource(), mediaRecorder.setProfile() fails with IllegalStateException.

Any idea?

like image 258
Vladimir Berezkin Avatar asked Dec 27 '22 22:12

Vladimir Berezkin


2 Answers

From MediaRecord.setProfile:

public void setProfile(CamcorderProfile profile)

Since: API Level 8 Uses the settings from a CamcorderProfile object for recording. This method should be called after the video AND audio sources are set, and before setOutputFile().

From Android - CamcorderProfile docs

Each profile specifies the following set of parameters:

  • The file output format
  • Video codec format
  • Video bit rate in bits per second
  • Video frame rate in frames per second
  • Video frame width and height,
  • Audio codec format Audio bit rate in bits per second
  • Audio sample rate
  • Number of audio channels for recording.

I'd say you could read the relevant video-related settings from a desired CamcorderProfile and set them explicitly yourself.

like image 189
typo.pl Avatar answered Dec 30 '22 13:12

typo.pl


The method setProfile() of MediaRecorder

Implementation

we can see,if:

profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW //1002
&&
profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA //1007

there will not setAudio*() So in your code you can manually set profile.quality=[any int from 1002 to 1007] before setProfile(). It will work, I'v tried.

I'v found the right answer:

if (getIsMuteShooting()) { // with out audio                                     
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);                  
    mRecorder.setVideoFrameRate(profile.videoFrameRate);                
    mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);              
    mRecorder.setVideoEncodingBitRate(profile.videoBitRate);                
    mRecorder.setVideoEncoder(profile.videoCodec);
} else {
    mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);              
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);               
    mRecorder.setVideoFrameRate(profile.videoFrameRate);                
    mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);              
    mRecorder.setVideoEncodingBitRate(profile.videoBitRate);                
    mRecorder.setAudioEncodingBitRate(profile.audioBitRate);                
    mRecorder.setAudioChannels(profile.audioChannels);              
    mRecorder.setAudioSamplingRate(profile.audioSampleRate);                
    mRecorder.setVideoEncoder(profile.videoCodec);              
    mRecorder.setAudioEncoder(profile.audioCodec);
}
like image 20
bevis Avatar answered Dec 30 '22 12:12

bevis