开发者

Rotating video taken in portrait mode

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(rot开发者_运维百科ate);
    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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜