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

发布于 2024-10-28 14:32:40 字数 480 浏览 2 评论 0原文

我的代码:

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。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白况 2024-11-04 14:32:40

来自 MediaRecord.setProfile

public void setProfile(CamcorderProfile 配置文件)

自:API 级别 8 使用设置
来自 CamcorderProfile 对象
记录。这个方法应该是
在视频和音频之后调用
源已设置
,并且之前
setOutputFile()。

来自 Android - CamcorderProfile 文档

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

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

我想说,您可以从所需的 CamcorderProfile 中读取相关的视频相关设置,并自行明确设置它们。

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.

迟月 2024-11-04 14:32:40

的方法 setProfile()

MediaRecorder Implementation

我们可以看到,如果:

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

不会有 setAudio*()
因此,在代码中,您可以在 setProfile() 之前手动设置 profile.quality=[any int from 1002 to 1007]
它会起作用的,我已经尝试过。

我找到了正确的答案:

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

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);
}
明媚殇 2024-11-04 14:32:40
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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文