How to handle video orientation from mobile devices - android

I have a server component that processes video uploads for a web/iOS/Android application.
However I am running into a problem handling the video orientation. Is there a good way to solve this? I have a tool MediaInfo that rips the meta data out of the device but this is what i am encountering
iOS
the portrait is correct 90 or 270
the landscape is crazy. if you hold the device with the button to the left, it reports 0 for the front camera and 180 for the back
Android
here the situation is reversed the landscape is correct both front and back camera
the portrait is 90 or 270 depending on if you are using the front or back camera
furthermore some devices like Motorola Droids and Evo4G dont record the meta data at all
has anyone seen a clean solution for this?

There is no clean solution for android devices that do not report the orientation.
For all the other orientations, I had overly complicated it in my mind. The flip between front and back means the angles are correct if rotated clockwise

Related

Why does my local video stream rotate during calls?

We have a native Android webrtc-based voip app. Only in our Android app (as opposed to other platforms), the local camera stream is rotated after being in a call for a while. Usually it takes about 10 seconds. But sometimes more, even as much as a minute.
The remote will get the stream rotated as well, so it's not a rendering issue.
The stream is always rotated 90 degrees clockwise in portrait orientation, but is correct in one landscape orientation and upside down in the other landscape orientation.
After a while, the stream will be rotated back to the correct orientation again (and back to bugged after a while again).
I've tried several revisions ranging from early 8xxx to the latest (9125), all have the same problem. Apprtc demo has the problem as well. I've tested on several different phones (although only Samsung devices) and the problem exists on all of them.
I was faced with the same issue and I didn't found a right solution, but there is a workaround. I found that the reason of the rotation is cpu overuse detection, it leads to changing quality and it seems there is some bug in this functionality in android implementation. So I just added peerConnectionConstraints.optional.add(new MediaConstraints.KeyValuePair("googCpuOveruseDetection", "false"));
and it prevented this rotation.

Orientation of Phonegap camera picture (Android)

I've been searching for a while, but haven't found a solution.
I'm trying to get my app to capture a photo but always force the photo to be a portrait photo, regardless if you take the photo with your phone in portrait or landscape (Pretty much how Snapchat handles photos being taken).
I've made the app only portrait and that works fine, but if I take a photo with my phone in landscape, the android camera then flips the photo 90 degrees to be landscape.
As it's a portrait only app, I want to be able to show the full image in portrait (the user can turn their phone if the image is sideways!)
Any thoughts on this? I've tried setting targetWidth, targetHeight & correctOrientation but cannot seem to get it to work at all.
Here's what currently happens:
http://postimg.org/image/9k51ptfb1/
And here's what I want to happen:
http://postimg.org/image/mkxvu7nlj/
Note - the suggested duplication has an answer of "can't be done" with no other details, which is obviously not an answer!
Thanks,
Gary

Android Difficult Screen Orientation

I have recently started studying Android, and I would, as first application, create my own camera. After taking a look at the API and other examples on the internet, I was able to create a working app, however I have this problem: if I rotate the tablet that I'm using to try what I do, my app rotates in the wrong way.
So, when I switch from portrait to landscape, the transition is successful and buttons rotate correctly, but what camera really sees is as if it were rotated 90 degrees more than it should.
All this unless I decide to set in my activity screenOrientation: landscape, because in this case the camera sees everything correctly, but the buttons remain fixed in one place, don't rotate with the rotation of the tablet.
I have a tablet with only front-facing camera.
What can I do to fix the problem?
check this answer I gave some time ago, it does have a nice method to call to correctly set the camera orientation.
How can I know the position of the camera on an android device?
and with that code you should let your activity rotate freely

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

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.
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.

Android API - disable right landscape?

I am busy writing an app that lets me use my phone (Galaxy S2 2.2.3) as a steering wheel. Just a nerdy weekend project really.
I have gotten everything working regarding calculating the orientation of the device using SensorManager.GetOrientation() with a slight snag. The rotation around the axis which comes out of the screen and back of the phone rises from 0 to 90 degrees and then falls back down in the same manner to 0 degrees instead of proceeding to 180.
This had me really confused until I read something somewhere that suggested the API might be flipping (internally as the screen doesn't flip) orientation so the phones coordinates system is flipping from left to right landscape (Its worth noting that I have it locked in landscape mode in the Manifest). This explains the weird behaviour in terms of orientation.
Does anyone know how to stop this happening, or have I gone wrong completely in my understanding?

Categories

Resources