Android flip front camera mirror flipped video
Solution 1
In my case, I just need to horizontal-flip when playing it. When recording it's already flipped for mirror effect and as I see it's not possible to modify it. However below code solved my problem when playing.
videoPlayer.setScaleX(-1);
Solution 2
In the documentation of the setDisplayOrientation method (http://developer.android.com/reference/android/hardware/Camera.html), we can find:
Note that preview display of front-facing cameras is flipped horizontally before the rotation, that is, the image is reflected along the central vertical axis of the camera sensor. So the users can see themselves as looking into a mirror.
So your preview display should be flipped but not your recorded video. With your preview display, do you see yourself as looking into a mirror? If so, everything is working fine.
Solution 3
I don't have a solution, but it seems to me the key is:
MediaRecorder.setOrientationHint
Sets the orientation hint for output video playback. This method should be called before prepare(). This method will not trigger the source video frame to rotate during video recording, but to add a composition matrix containing the rotation angle in the output video if the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4 so that a video player can choose the proper orientation for playback. Note that some video players may choose to ignore the compostion matrix in a video during playback.
I'm recording video in H264 and it doen't work for me :( But it might help you. did to try it?
Related videos on Youtube
Danny Kim
Updated on September 25, 2021Comments
-
Danny Kim over 2 years
I'm trying to record a video from Android's front camera while displaying on surface view as well.
What I found out with the front camera is that it mirror flips the video during recording, even though the surface view shows a normal view.
Is there any way I can prevent this or fix it?
I read upon other stackoverflow articles like How to keep android from inverting the image from the front facing camera?
But it seems to be only talking about taking photos with the front camera and reversing the image, which I already fixed using matrix myself. However, it seems like using a matrix for a video does not work.
-
clwhisk over 10 yearsWeird. If you are able to apply a matrix to the video there must be a way to flip it.
-
Danny Kim over 10 yearsHi, the preview looks fine, but the actually recording for some reason mirror flips it.
-
keuninkske over 10 years
-
colintheshots about 9 yearsThat answer does not seem relevant. There seems to be no way to apply matrix transformations to video MediaRecorders, only to alter the view shown on recording surfaces.
-
user1154390 almost 9 yearsHi @DannyKim, Have u found the solution of above problem?
-
Tofeeq Ahmad over 7 yearsHave a look at androidtrainningcenter.blogspot.in
-
Imene Noomene about 7 yearsDid anyone find a way to this issue ?
-
Piyush almost 7 years@DannyKim i am facing same issue. did you find solution?
-
Alex Cohn over 6 years@Piyush, see my illustrated answer
-
-
Danny Kim over 10 yearsit only flips the orientation of the video (hence the method name). but the recorded video is still mirror flipped from preview :/
-
colintheshots about 9 yearsNo, I can't see myself in the front camera preview as if looking in a mirror. The problem I see is the exact opposite of what the documentation describes. The preview is correct after Camera.setDisplayOrientation(), but the H.264 video is flipped horizontally after MediaRecorder.setOrientationHint().
-
colintheshots about 9 yearsThere is no way to apply a matrix transformation to anything except views i.e. preview and playback. If the video recording itself is flipped, MediaRecorder does not seem to offer any functions to apply a transformation to fix the video it saves.
-
Alex Cohn about 9 yearsIf you can't see yourself in the front camera preview as if looking in a mirror, your device probably has a problem. I would suggest that you first try some other device with front facing camera.
-
colintheshots almost 9 yearsBoth the original poster and I see the same "problem" and it occurs on every Nexus device I own with a front-facing camera and a recent OS. Perhaps the documentation is outdated?
-
colintheshots almost 9 yearsI have yet to find any device running KitKat or Lollipop that does not reproduce this behavior when recording videos from the front facing camera. I have tried Samsung Galaxy S3, S4, S5, S6, Moto G, Nexus 4, and Nexus 6. I believe the docs are outdated or wrong.
-
colintheshots almost 9 yearsThe above answer is unrelated to the question.
-
Alex Cohn over 6 years@colintheshots I finally wrote an illustrated answer, please check.
-
user924 about 3 years@colintheshots yes, only possible if we use surface as input for mediarecorder and opengl for image processing, in this case we can do anything, flip and so on