-
-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My device starts the camera in an inverted way #1576
Comments
Hello, You will need to handle the orientation manually to fix it. If you have autohandleOrientation, set it to false: private val sensorRotationManager = SensorRotationManager(context, true, true, object: SensorRotationManager.RotationChangedListener {
override fun onRotationChanged(rotation: Int, isPortrait: Boolean) {
genericStream.getGlInterface().setCameraOrientation(rotation)
genericStream.getGlInterface().setIsPortrait(!isPortrait)
}
}) In this case, I did !isPortrait in setIsPortrait because I think that the fail is related with that parameters because the orientation seems fine. sensorRotationManager.start()
sensorRotationManager.stop() |
Its not working with that code, I tried several options. What's happening is that the camera in portrait mode is opening like if it was recording with native camera in landscape mode, this is, 1920x1080 so at the time of converting that 1920x1080 in the portrait mode is getting stretched because portrait mode expects video data of 1080x1920. I tried the setCameraOrientation and setIsPortrait with all the combinations but the result was the same in every case. EDIT: setCameraOrientation() and setIsPortrait() work after call startPreview(mCameraView), anyway I can't find the way to open the camera in the right way, I think is an initial issue, before prepareVideo() |
Hello, prepareVideo could change orientation depend of the rotation value. Using 0 you have landscape and using 90 you have portrait but the preview should be correct in both cases. This only should affect to the stream result rotating the resolution depend of the value. For example:
Try add this: genericStream.getGlInterface().forceOrientation(OrientationForced.LANDSCAPE)
genericStream.getGlInterface().forceOrientation(OrientationForced.PORTRAIT)
genericStream.getGlInterface().forceOrientation(OrientationForced.NONE) //this is used to disable this mode Try using one of that for landscape or portrait. Test all combinations |
Ok so I was able to draw in the surface the correct preview, but the issue is that the streaming output is inverted. a 1080x1920 preview is streaming in 1920x1080, and viceversa. I add the code and pictures of the output: @Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
genericStream = new GenericStream(requireContext(), this);
genericStream.getGlInterface().setAspectRatioMode(AspectRatioMode.Fill);
Size cameraSize = getCameraSize();
genericStream.prepareVideo(
cameraSize.getWidth(),
cameraSize.getHeight(),
1200 * 1000,
30,
2,
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? 90 : 0
);
genericStream.prepareAudio(32000, true, 128 * 1000);
genericStream.startPreview(mCameraView);
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
genericStream.getGlInterface().setCameraOrientation(isPortrait ? 0 : 270);
genericStream.getGlInterface().setIsPortrait(!isPortrait);
} Pictures: All these results were obtained using width=1920, height=1080. If I use width=1080,height=1920, all is the same except portrait streaming result, which is this: |
Was the streaming result working fine before that changes? Can you tell me the values of SensorManager in all orientations? |
I have a device which seems to start the camera in an inverted way: if I start the activity in portrait mode, this loads the camera with a landscape resolution, and if I start it in landscape mode, the camera starts with a portrait resolution, Is there any way to open the camera inverting the width and the height? I tried playing with rotation, width and height but didn't achieve what I want. Here is some pictures of the issue, my goal is to get the inverted result: the portrait preview in portrait mode and landscape preview in landscape mode. I could get this result but output video is stretched, as initial width and height of the signal of the camera is inverted as I said.
My current code is working fine with all devices except this one, so I guess is software issue or something related at the time of starting the camera, even before the surface is created.
The text was updated successfully, but these errors were encountered: