비디오를 사용자 정의보기로 캡처하려고합니다. Camera.setDisplayOrientation (rotation)을 통해 올바른 방향으로 비디오를 표시 할 수 있지만 녹화 된 비디오는 여전히 가로 모드입니다. 세로 모드에서 비디오를 올바르게 캡처 할 수 없습니다.Android, 세로 모드에서 MediaRecorder를 사용하여 녹화 된 비디오를 회전하는 방법
나는 https://github.com/googlesamples/android-Camera2Video을 테스트했으며 동일한 문제가 있습니다.
권한을 확인한 후 Camera.open(currentCameraId)
뒤에 setCameraOrientation()
메서드를 호출합니다.
private void setCameraOrientation()
{
int rotation = getRotation();
mCamera.setDisplayOrientation(rotation);
Camera.Parameters parameters = mCamera.getParameters();
parameters.setRotation(rotation);
mCamera.setParameters(parameters);
}
private int getRotation()
{
Display display = getWindowManager().getDefaultDisplay();
int rotation = 0;
switch (display.getRotation())
{
case Surface.ROTATION_0:
rotation = 90;
break;
case Surface.ROTATION_90:
rotation = 0;
break;
case Surface.ROTATION_180:
rotation = 270;
break;
case Surface.ROTATION_270:
rotation = 180;
break;
}
return rotation;
}
이렇게하면 정확한 방향으로 비디오를 표시 할 수 있습니다. 그러나 MediaRecorder
을 멈추고 저장된 파일을 확인한 후에 90도 회전 된 비디오의 화면 비율이 좋지 않습니다. 내 컴퓨터와 VideoView 요소가있는 다른 조각을 가져 와서 이것을 확인했습니다.
private boolean prepareRecorder()
{
mCamera.lock();
mCamera.unlock();
recorder = new MediaRecorder();
recorder.setCamera(mCamera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
if (!mIsMute)
{
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setProfile(profile);
}
else
{
recorder.setOutputFormat(profile.fileFormat);
recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
recorder.setVideoFrameRate(profile.videoFrameRate);
recorder.setVideoEncoder(profile.videoCodec);
recorder.setVideoEncodingBitRate(profile.videoBitRate);
}
recorder.setMaxDuration(maxVideoDuration - videoProgress);
String fileName = StorageUtil.sharedUtil().getExternalStorageDir() + File.separator + String.format(
fileNameFormat, videoCount);
recorder.setOutputFile(fileName);
recorder.setPreviewDisplay(surfaceHolder.getSurface());
try
{
recorder.prepare();
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
하고 난 그냥 단지 recoreder.prepare();
전에 recorder.setOrientationHint(90);
을 시도 그런데 recorder.start();
를 호출하지만 아무것도하지 않습니다 내 prepareRecorder 방법이다. 정확한 방향을 표시 할 수는 있지만 저장할 수는 없습니다.
답변 해 주셔서 감사합니다.하지만 이것은 정확하게 내 문제는 아닙니다. 나는 이미'setCameraOrientation()'메소드로 디스플레이 방향을 설정하고있다. 이렇게하면 녹화하는 동안 올바르게 표시 할 수 있지만 내 문제는 비디오를 세로 모드로 저장하는 것입니다. 항상 가로 모드로 비디오를 저장하고 추가 시간 (몇 초)이 소요되는 비디오를 회전하려면 ffmpeg를 사용하고 있습니다. 일반 Android Android One with Android7.0 OS로 테스트 중입니다. –
왜 ffmpeg를 사용하여 동영상을 회전시키고 있습니까? 올바른 회전은 동영상의 메타 데이터에 기록되어야합니다. 그런 일이 일어나지 않았나요? –
비디오를 녹화 한 후 다음 화면에서 재생합니다. 회전하지 않으면 비디오가 잘못된 방향으로 재생됩니다. 처음에는 Android에서 내 플레이어와 관련 있다고 생각했지만 그 다음 .mp4 비디오를 내 컴퓨터로 가져 와서 결과는 동일했습니다. 비디오가 -90도 틀린 방향으로 재생되었습니다. 나는 ffmpeg로 동영상을 회전시킬 때만이 문제를 해결할 수 있었다. –