gpt4 book ai didi

Android录制没有音频的视频

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:27 26 4
gpt4 key购买 nike

Android 是否可以在没有音频流的情况下从相机录制视频?

目标:减少输出文件的大小。

最佳答案

您可以通过从内置配置文件 (CamcorderProfile) 复制所需字段来准备 MediaRecorder。只需省略音频设置,您就可以开始了。根据您的需要编辑下面的代码,第 3 步是此处必不可少的部分。

private boolean prepareVideoRecorder() {

mCamera = getCameraInstance();
mMediaRecorder = new MediaRecorder();

// store the quality profile required
CamcorderProfile profile = CamcorderProfile.get(cameraid, CamcorderProfile.QUALITY_HIGH);

// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);

// Step 2: Set sources
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

// Step 3: Set all values contained in profile except audio settings
mMediaRecorder.setOutputFormat(profile.fileFormat);
mMediaRecorder.setVideoEncoder(profile.videoCodec);
mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());

// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}

关于Android录制没有音频的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11920898/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com