2011-04-02 95 views
2

我的代碼:是否有可能在沒有音頻源的情況下使用CamcorderProfile?

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); 

它的工作原理。 但我只需要錄製視頻。

如果我不使用mediaRecorder.setAudioSource(),則mediaRecorder.setProfile()會失敗,並顯示IllegalStateException。

有什麼想法?

回答

5

MediaRecord.setProfile

公共無效setProfile(CamcorderProfile輪廓)

自:API等級8使用來自CamcorderProfile對象的設置 爲 記錄。在視頻和音頻 源設置爲之前以及在 setOutputFile()之前,此方法應爲 ,稱爲

Android - CamcorderProfile docs

每個配置文件指定以下 組參數:

  • 文件輸出格式
  • 視頻編解碼器格式
  • 視頻比特每秒比特率
  • Vid EO幀速率在每秒
  • 視頻幀的寬度和高度的幀,
  • 音頻編解碼器格式的音頻比特率的比特每秒
  • 音頻採樣率,用於記錄音頻通道
  • 數目。

我說你可以讀取所需CamcorderProfile相關視頻相關的設置,並設置他們自己的明確。

+0

這確實應該是適用於CamcorderProfiles任何剪裁;例如如果您不想使用默認的視頻比特率但不是一個(不是所有的配置文件參數都可以更改,有的會四捨五入到最接近的可能值) – ysmartin 2014-05-08 21:37:41

4

的方法setProfile(MediaRecorder的)

Implementation

我們可以看到,如果:

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

不會有setAudio *() 因此,在你的代碼,你可以手動設置profile.quality=[any int from 1002 to 1007]之前setProfile()。 它會工作,我試過了。

心中已經找到了正確的答案:

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); 
} 
0
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 

CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); 
mediaRecorder.setOutputFormat(profile.fileFormat); 
mediaRecorder.setVideoFrameRate(profile.videoFrameRate); 
mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); 
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate); 
mediaRecorder.setVideoEncoder(profile.videoCodec); 
+1

請在回答中添加一些說明,以便它對OP有幫助,其他 – 2015-12-02 15:22:08

相關問題