1

i just played thru the android camera tutorial. the problem i have is about orientation. the recorded videos have wrong orientation if i start in portrait mode. In my case i modified the layout of preview view a bit - now it has some wrong/arbitrary aspect ration but the recorded videos do also have the same (wrong) aspect ratio!?

Why and how are preview and actual recording coupled? is there a way to decouple it: the recorded video should only record what the camera delivers.

So how to create a camera app that ignores orientation on recording (or uses orientation only to store it in metadata) but reflects it in preview (nothing to do - a portrait becomes landscape by rotating the phone). are there any examples of camera apps with correct rotation handling?

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
dermoritz
  • 12,519
  • 25
  • 97
  • 185
  • I am not aware that it is possible to record video in portrait mode, though I will be happy for somebody to prove me wrong. The video will contain a flag in the header that indicates that the player should change the orientation (e.g., rotate 90 degrees clockwise), but not all players will honor that flag. – CommonsWare Jul 22 '13 at 13:19
  • 1
    the problem is that the preview and recorded video is rotated by 90°. And i only want that preview shows what lens sees and the recorded video shall also show "only" what lens sees. i don't want any orientation handling. – dermoritz Jul 22 '13 at 13:35

2 Answers2

3

If you want to record video on Android with a different orientation from the default, you need to use MediaRecorder's setOrientationHint method.

There is no coupling of camera preview orientation (set by Camera's setDisplayOrientation method) and recording orientation, beyond that they both default to be oriented along the long side of the device.

If you change your app's orientation away from landscape, you need to call Camera's setDisplayOrientation to properly adjust preview, and Media Recorder's setOrientationHint to change the recording orientation, independently.

Android's default camera application, available in AOSP, properly handles all this.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • thx for the hint, but i had this problem: http://stackoverflow.com/questions/3841122/android-camera-preview-is-sideways/5110406#5110406 it seems to be kind of a bug?! but with the code from there it works. – dermoritz Jul 22 '13 at 18:59
  • 1
    There's no bug there. The camera by default sends images in landscape orientation. But if your UI is portrait, the activity's coordinate system is rotated 90 degrees from the camera's coordinate system. That is, (0,0) for the app is top-left in the portrait orientation, while (0,0) for camera is top-left in the landscape orientation. So if you draw the camera preview in the app coordinate system, it'll be rotated wrong. That's why the setDisplayOrientation call exists, to compensate for that difference. – Eddy Talvala Aug 01 '13 at 15:27
0
            mSession = SessionBuilder.getInstance()
                .setContext(getApplicationContext())
                .setAudioEncoder(SessionBuilder.AUDIO_AAC)
                .setAudioQuality(new AudioQuality(8000, 16000))             
                .setVideoEncoder(SessionBuilder.VIDEO_H264)
                .setSurfaceView(mSurfaceView).setPreviewOrientation(90)
                .setCallback(this).build();
Dhina k
  • 1,481
  • 18
  • 24