setOrientationHint rotates video counterclockwise on some phones' front facing cameras (HTC)
Asked Answered
M

1

9

The Problem: Certain Android devices (listed at the bottom of the question) exhibit unexpected behavior when utilizing the setOrientationHint(int degrees) function for videos taken with the front facing camera. The expected behavior is for the video to be rotated clockwise, but these devices rotate the video counterclockwise.

My Goal: To identify a variable within either the camera settings or hardware orientations that allows me to predictably know when this will occur. Specifically, I would like to avoid special casing these phones in my code!

Further Explanation: I am recording video using the standard MediaRecorder object, and in preparing for recording, I set the orientation of the video using setOrientationHint(). In the documentation for setOrientationHint(), the following is specified for the degrees parameter:

degrees –– the angle to be rotated clockwise in degrees. The supported angles are 0, 90, 180, and 270.

The function is intended to add a composition matrix containing the rotation angle so that a video player can display the video as intended. So, what I do is that I get the camera hardware's orientation using the CameraInfo class and use that as the degrees parameter in the setOrientationHint fn. (I have tried variation on this code using the AOSP as a guide, but I had the exact same result.)

A Real Example: The Samsung Galaxy S3 front-facing camera (and most others, in fact) will have a hardware orientation of 270, so I use this when recording, and the resulting video is displayed correctly. An HTC Vivid will similarly return a hardware orientation of 270 for the same camera, but will only be displayed correctly if I use 90 as the degrees parameter in the setOrientationHint fn. If I use the 270 of the hardware orientation like any other phone, the video will be upside down.

NB: The setOrientationHint() function includes a warning:

Note that some video players may choose to ignore the compostion matrix in a video during playback.

However, this is not what is happening, because I can easily fix this issue on these phones if I fake it and put in 90 instead of 270.

Phones that I have seen specifically exhibit this issue: HTC Vivid (PH39100) running Android 4.0.3, HTC EVO 4G (PG86100) running Android 4.0.3, HTC Thunderbolt (ADR6400L) running Android 2.3.4. Notice that they are all HTC phones. Perhaps someone at HTC mistook clockwise for counterclockwise.

Macrogamete answered 7/2, 2013 at 23:37 Comment(2)
Daniel, did you find any solution for this? I am having the same problem.Hindquarter
Please take a look at https://mcmap.net/q/1320748/-android-video-recording-output-orientation-flipped You can find solutionQuinte
T
1

Yes, the HTC phones rotate in the wrong direction for the front facing cameras. Instead of trying to guess, I ended up adding a settings screen that would take two pictures with the second one rotating 90 degrees. Then the user could keep hitting next as I cycled through the different rotation direction and angle combinations until both pictures appeared oriented the same way.

Terrorstricken answered 5/3, 2013 at 4:57 Comment(4)
There are obviously ways to get around this by allowing users to set a custom orientation, but I am looking for a specific way to know that a phone will do this. This is not an issue with all HTC devices–only some.Macrogamete
That's why I went with a settings solution. With all the devices out there, you will run into many devices with camera rotation issues, so might as well be flexible. Just my 2 cents...Terrorstricken
I also went with a settings solution but I feel very uncomfortable with the solution, and do not feel that it satisfactorily addresses this question (though I do feel it is worth keeping here as an "answer" to be thorough–hence no -1 from me). Users in this scenario will have a terrible first experience with a camera application, many not even knowing that they should check in a "settings" menu to fix the problem. This terrible UX will likely impact first impressions on thousands of users.Macrogamete
Agreed, not ideal. It's sometimes tough to come up with an ideal solution when dealing with manufacturer bugs and inconsistencies.Terrorstricken

© 2022 - 2024 — McMap. All rights reserved.