1

Hello friends I am new in android developing and i am facing some problem while i am working with camera in my app. I am developing app and in this app i am using the inbuilt functionality of camera. In my app camera will perform the task to capture video and then i save the captured video.

Now problem is that when i shoot video i want to know that in which orientation video is recorded? Because i am increasing or lapsing the speed of the video by using the library. And when i pass this recorded video in another activity this video is not coming as same as it was record. So Help me to resolve this problem.

Jignesh Patel
  • 27
  • 1
  • 7

2 Answers2

2

You could try do something like this: (viewSource is your video source)

MediaPlayer mp = new MediaPlayer();
String orientation = "";
try {
  mp.setDataSource(viewSource);
  mp.prepare();
  mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
      @Override
      public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
          if(width < height){
              orientation = "vertical";
          } else {
              orientation = "horizontal";
          }
      } 
  });
} catch (IllegalArgumentException e) {
  e.printStackTrace();
} catch (SecurityException e) {
  e.printStackTrace();
} catch (IllegalStateException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

You can see here for more variants: Detect orientation of a recorded video in android

Community
  • 1
  • 1
Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30
  • Anybody can tell me how to get height and width of recorded video??? pls answer me pls.... – Jignesh Patel Apr 29 '15 at 06:27
  • You become them from the OnVideoSizeChangedListener() as I wrote up there. Another way is to use the methods from android.media.MediaPlayer getVideoWidth() and getVideoHeight(), but they only work, when the event for the size is already fired – Gabriella Angelova Apr 29 '15 at 06:33
  • And sir i m recording video and after recording i m lapse it using library. but video is not coming as it was shooted its rotate by it self but i do not want to roate it. For example if shoot video in landscape then it must come with landscape or if i shoot video in portraitthen it must come with portrait. – Jignesh Patel Apr 29 '15 at 06:55
  • What should i have to make changes in ffmpeg command so i can get the video as it was shooted ? pls help me sir.. – Jignesh Patel Apr 29 '15 at 06:56
  • You could create a simple button in the activity, where your video is playing, from which you could change the orientation something like this http://stackoverflow.com/questions/18268218/change-screen-orientation-programatically-using-a-button – Gabriella Angelova Apr 29 '15 at 07:04
  • Another way I found is to set the rotation (`setRotation()`) of the view with the video http://developer.android.com/reference/android/view/View.html#setRotation(float) – Gabriella Angelova Apr 29 '15 at 07:05
2

The class MediaRecorder, which is what is used to record the video, has this:

mMediaRecorder.setOrientationHint(90);

This hint is set on the mp4 container but the catch is that not all mp4 "reader" or extractor take this orientation into account.

Android seems to not really care about although I could be wrong. If I build opencv with ffmpeg, the orientation is ignored but if I build opencv with quicktime, frames comes out with the correct orientation.

Using ffprobe on the file should tell you whether the file was saved with an orientation.

If MediaPlayer doesn't respect the orientation, you might have to parse the mp4 metadata yourself to obtain the orientation and then rotate the frames in accordance.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67