当我通过 MediaRecorder 录制视频时,它总是以横向模式录制,无论实际设备方向如何。如何强制 MediaRecorder/Camera 使用真实方向?
问问题
31240 次
5 回答
20
有关详细信息,请参阅Camera.Parameters.setRotation()。
那里有一个例子,而不是调用 setRotation(rotation) 尝试在录制视频时调用 mediaRecorder.setOrientationHint(rotation) 。
于 2011-08-22T02:06:42.637 回答
15
添加以下两行代码:
Camera.setDisplayOrientation(90); // use for set the orientation of the preview
mRecorder.setOrientationHint(90); // use for set the orientation of output video
前:
mRecorder.setCamera(mCamera);
完整示例:
mRecorder = new MediaRecorder();
// Both are required for Portrait Video
mCamera.setDisplayOrientation(90);
mRecorder.setOrientationHint(90);
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mRecorder.setCamera(mCamera);
// Step 2: Set sources
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
于 2016-12-24T09:07:01.110 回答
8
看看这里的文档
http://developer.android.com/guide/topics/media/camera.html#capture-video
这个例子最常见的陷阱是 setCamera() 。您必须在制作 MediaRecorder 后立即设置相机,否则您会出错。
Camera mCamera = getCameraInstance();
// adjust the camera the way you need
mCamera.setDisplayOrientation(90);
MediaRecorder recorder = new MediaRecorder();
mCamera.unlock();
recorder.setCamera(mCamera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(filePath);
// add any limits
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
我希望这可以帮助别人。祝你好运!!
于 2012-03-20T18:30:43.870 回答
3
我以前也遇到过这个问题。我发现您可以使用函数setOrientationHint (API 9)。在调用 MediaRecorder.prepare() 之前调用此函数。您可以设置输出视频的方向度。
希望对你有帮助,祝你好运!
于 2012-09-08T01:47:04.973 回答
3
mMediaRecorder = new MediaRecorder();
mServiceCamera.setDisplayOrientation(90);
mMediaRecorder.setOrientationHint(90);
mServiceCamera.unlock();
mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
于 2017-08-11T05:33:23.080 回答