是否可以在没有音频源的情况下使用CamcorderProfile?

问题描述 投票:2回答:3

我的代码:

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。

任何想法?

android video record
3个回答
5
投票

来自MediaRecord.setProfile

public void setProfile(CamcorderProfile配置文件)

由于:API级别8使用设置来自CamcorderProfile对象的记录。这种方法应该是称为在视频和音频之后源设置,以及之前setOutputFile()。

来自Android - CamcorderProfile docs

每个配置文件指定以下内容参数集:

  • 文件输出格式
  • 视频编解码器格式
  • 视频比特率,以每秒比特数为单位
  • 视频帧速率,以每秒帧数为单位
  • 视频帧的宽度和高度,
  • 音频编解码器格式音频比特率,以每秒比特数为单位
  • 音频采样率
  • 用于记录的音频通道数。

我想你可以从所需的CamcorderProfile中读取与视频相关的设置,然后自己进行显式设置。


4
投票

MediaRecorder的setProfile()方法

“实施”

我们可以看到,如果:

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

将不会设置Audio *()因此,可以在代码中手动设置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);
© www.soinside.com 2019 - 2024. All rights reserved.