15

My app lets the user capture video:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_VIDEO_REQUEST); 

or pics:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

In the case of the pics, I can tell whether they were taken in any mode other than landscape and then rotate them before I upload them to the web:

ExifInterface exif = new ExifInterface(fileName);
int exifOrientation = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION));
float rotate = 0;
switch (exifOrientation){
case ExifInterface.ORIENTATION_ROTATE_90:
    rotate = 90;
    break;
case ExifInterface.ORIENTATION_ROTATE_180:
    rotate = 180;
    break;
case ExifInterface.ORIENTATION_ROTATE_270:
    rotate = 270;
    break;
}

if(rotate > 0){
    Bitmap bitmap = BitmapFactory.decodeFile(fileName);
    Matrix matrix = new Matrix();
    matrix.postRotate(rotate);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    OutputStream outStream = context.getContentResolver().openOutputStream(Uri.fromFile(file));
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
}

How do I accomplish the same with video?

Jeffrey Greenham
  • 1,252
  • 5
  • 15
  • 33
shaharsol
  • 949
  • 1
  • 8
  • 27

1 Answers1

2

I do not seem to fully understand your question. Here are some questions that I thought would at least steer you in the right direction. Hope it helps

  1. Do you want to rotate the video for playback with the MediaPlayer?

  2. Do you want to change the hard code in the video file to make it play rotated everywhere?

  3. Rotate buffered video orientation?

================================================================================== This answer to question # 1:

//rotating a SurfaceView that contains the MediaPlayer
/*
    Create a new MediaPlayer SurfaceView, then use the SurfaceHolder interface
*/
video = new SurfaceView();
video.getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);

video.getHolder().lockCanvas().rotate(90);

This answer to question # 2:

As for changing the hard code of a video. I would advise to use a nice GUI video codec to rotate the video and it should save its settings. Otherwise you will have to access the source code from the decoder then your SOL with my advice.

This answer to question # 3:

The post below explains how you can rotate a buffered video and/or change its orientation settings for different modes.

Post here: Android VideoView orientation change with buffered video

==================================================================================

If this doesn't help you then I am sure it will help someone else, and good luck.

Community
  • 1
  • 1
CommonKnowledge
  • 763
  • 1
  • 10
  • 33
  • >video.getHolder().lockCanvas().rotate(90); This not work with MediaPlayer as it show Unknown error and doesn't play video. – Ernest Feb 05 '14 at 12:39
  • @Ernest Are you using .... video.getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL); or video.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); ? – CommonKnowledge Feb 17 '14 at 15:20
  • Its been years, but I believed this did work for me. If it doesnt work maybe try... http://stackoverflow.com/questions/8327774/rotating-the-actual-videobuffer-in-videoview – CommonKnowledge Feb 17 '14 at 15:21