why the video is rotated by 90 degrees at PC? - android

Shooting video with MediaRecorder class is good, shooting results in the phone, it was also ok, but uploaded to the computer to see the video,but it is rotated by 90 degrees. How to solve?

Usually, some vendor like samsung or sony... make their devices to record video in landscape mode. Maybe you record video in vertical orientation and review video after that on the laptop should be rotated by 90 degrees. I faced this issue in my project and the way to solve that is: detect the orientation by use the phone's sensor, after that use setOrientationHint(int degrees) method in MediaRecorder class to have a suitable orientation .

Related

Inconsistent video rotation when using MediaCodec

I have two devices, a Nexus 7 (Android 5) and a Galaxy S3 (4.3). On both devices I recorded a video in portrait mode and saved it with rotation hint 90 degrees. This is the correct orientation hint cause when played using the default media player the orientation is fine on both devices. I can even copy the video from the Nexus to the Galaxy and the orientation is still fine when I play the video file.
However, when I decode the video using the MediaCodec api I get some problems with the video rotation. When I display the video data I get from the MediaCodec the video on the Nexus is correct but on the Galaxy S3 the video is rotated by 90 degrees. My problem is that I have no clue what parameters on both devices differ so that I can decide why I have to rotate the video on the Galaxy but not on the Nexus!
On both devices the display rotation is 0 and the orientation is portrait:
int rotation = windowManager.getDefaultDisplay().getRotation();
int orientation = context.getResources().getConfiguration().orientation;
Is there another parameter I have to take into account?
Was there some api changes between 4.3 and 5 that affects the rotation of the decoded video? For example, is that video rotated automatically now?
I use opengl to display the video in case it matters...
Update: Solution
The problem was in the OpenGL transformation matrix that I get back from the MediaCodec. MediaCodec renders onto a SurfaceTexture and in case of the Nexus the transformation matrix of the SurfaceTexture is updated correctly, the Galaxy does not do that. When rendering the final output texture I used this matrix. To solve this I ignore the transformation matrix and rotate the video manually according to the recording hint.

Use FFmpeg to rotate the video based on its <rotate> metadata? Why does Android put the wrong metadata?

I have a website where the user uploads a video.
For my website i have also an Android application.
The website creates a thumbnail of each uploaded video (from browser or Android).
The problem is that for normal videos it's all OK, but for android my videos are rotated by 90°.
I think that Android has a bug, because when I see with FFmpeg the video's metadata, for a normal recorded video I got a rotate=90 value, and for a 90° rotated video, I don't have anything in the metadata (and the thumbnail is correct).
Why?
This is an image of a normal recorded video (with the phone in portrait mode).
Anyway, I have the metadata in the video, can I create its thumbnail based on its metadata's rotate value without extracting the metadata and then use ffmpeg to rotate the video on this value?
Thank you in advance.
On android, holding your phone in portrait is considered to be 90 degrees. This the convention that android is using:
landscape: 0
portrait: 90
reverse landscape: 180
reverse portrait: 270
I know this doesn't make sense for phones but it does for tablets and there is realy no difference between tablets and phones on android.
So the metadata in the file are correct. The actual problem is that your browser ignores them. See me question here

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.

Video Chat app using portrait orientation mode on Android using Adobe AIR 3.6

I developing a video chat app using Adobe AIR 3.6 beta on Android using the front camera.
As explained by Adobe they expect you to capture video in landscape mode.
I really need to do this in portrait mode, right now the video is 90 degrees in the wrong direction and 180 degrees in the wrong direction on the other side of my video app
I using the camera class and I fully understand that the Camera class is designed to only be used in Landscape mode.
Currenly I using the Camera and Video classes and will eventually use StageVideo!
I tried rotating the video clip using rotateX or a matrix, this works but it is still sending the video sideways in landscape mode even after I locked the mobile device in portrait. This only solves half my problem.
I need to rotate the physical camera so The user can user can use the app in portrait mode and the video is being sent in portrait mode. Is they ANY way to do this without having to resort to ActionScript extensions?
In Java here how to do this!
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.setRotation(90);
camera.setParameters(parameters);
How to do this in AIR and AS3.0 with both the screen and streaming video being in portrait mode?
Anyone?
I'm sadly search for the same exactly solution. The only thing I have come up with is to also send a notification to the receiving end of the stream to let them know your device has rotated so that they can follow suit... I know painful

How to handle video orientation from mobile devices

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

Categories

Resources