gpt4 book ai didi

android - 尽管我以纵向录制,但横向播放的视频

转载 作者:行者123 更新时间:2023-11-29 21:44:19 25 4
gpt4 key购买 nike

正如标题所说,我有这段代码来准备我的记录器:

private boolean prepareMediaRecorder(){
myCamera = getCameraInstance();

Camera.Parameters p = myCamera.getParameters();

p.set("orientation", "landscape");
p.set("rotation", 90);
myCamera.setParameters(p);

myCamera.setDisplayOrientation(90);

myCamera.unlock();
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(myCamera);

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

File tempFile = new File(Environment.getExternalStorageDirectory(), "/rec/temp/video_" + String.valueOf(videoCount) + ".mp4");
mediaRecorder.setOutputFile(tempFile.getPath());
mediaRecorder.setMaxDuration(12500); // Set max duration 11 sec.
mediaRecorder.setMaxFileSize(7000000); // Set max file size 7M

mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());


try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;

}

在我的表面 View 中有:

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int weight,
int height) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.

if (mHolder.getSurface() == null){
// preview surface does not exist
return;
}

// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e){
// ignore: tried to stop a non-existent preview
}

// make any resize, rotate or reformatting changes here

// start preview with new settings
try {

myCamera.setDisplayOrientation(90);

mCamera.startPreview();

} catch (Exception e){
}
}

那是仅有的两个使用相机的地方(旋转)...录制时一切都很好,但当我播放该视频时,它是横向的。谁能告诉我为什么以及如何解决这个问题?

最佳答案

使用 setOrientationHint(int degrees) http://developer.android.com/reference/android/media/MediaRecorder.html#setOrientationHint(int)

mediaRecorder.setOrientationHint(90); (后置摄像头 90,前置摄像头 270)在 mediaRecorder.prepare() 之前调用它;

关于android - 尽管我以纵向录制,但横向播放的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16284628/

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