简体   繁体   English

以纵向模式拍摄的旋转视频

[英]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(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? 如何通过视频完成相同的操作?

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? 是否要使用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: ================================================== ================================ 对问题#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: 对问题#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. 我建议使用一个漂亮的GUI视频编解码器来旋转视频,它应该保存其设置。 Otherwise you will have to access the source code from the decoder then your SOL with my advice. 否则你将需要从解码器访问源代码,然后根据我的建议访问你的SOL。

This answer to question # 3: 对问题#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 发布在此处: 使用缓冲视频更改Android VideoView方向

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

If this doesn't help you then I am sure it will help someone else, and good luck. 如果这对你没有帮助,那么我相信它会帮助别人,祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM