【问题标题】:Is it possible to use CamcorderProfile without audio source?是否可以在没有音频源的情况下使用 CamcorderProfile?
【发布时间】:2011-04-02 17:24:35
【问题描述】:

我的代码:

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


    【解决方案1】:

    来自MediaRecord.setProfile

    public void setProfile(CamcorderProfile 配置文件)

    自:API 级别 8 使用设置 来自 CamcorderProfile 对象 记录。这种方法应该 在视频和音频之后调用 来源已设置,之前 设置输出文件()。

    来自Android - CamcorderProfile docs

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

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

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

    【讨论】:

    • 这确实应该适用于CamcorderProfiles的任何剪裁;例如如果您不想使用默认视频比特率,而是使用不同的比特率(并非所有配置文件参数都可以更改,有些会四舍五入到最接近的可能值)
    【解决方案2】:

    MediaRecorder的setProfile()方法

    我们可以看到,如果:

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

    【讨论】:

      【解决方案3】:
      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);
      

      【讨论】:

      • 请在回答中添加一些描述,以便对 OP 和其他人有所帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多