旋转纵向模式拍摄的视频

发布于 2024-12-04 16:53:15 字数 1280 浏览 0 评论 0原文

我的应用程序允许用户捕获视频:

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

或图片:

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

就图片而言,我可以判断它们是否是以横向以外的任何模式拍摄的,然后在将它们上传到网络之前旋转它们:

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);
}

我如何通过视频?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞别 2024-12-11 16:53:15

我似乎不完全理解你的问题。我认为以下一些问题至少可以引导您走向正确的方向。希望它有帮助

  1. 您想旋转视频以使用 MediaPlayer 进行播放吗?

  2. 是否要更改视频文件中的硬代码以使其随处旋转播放?

  3. 旋转缓冲视频方向?

=================================================== =================================
问题 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);

问题 2 的答案:

至于更改视频的硬代码。我建议使用一个不错的 GUI 视频编解码器来旋转视频,它应该保存其设置。否则,您将必须从解码器访问源代码,然后根据我的建议访问您的 SOL。

问题 3 的答案:

下面的帖子介绍了如何旋转缓冲视频和/或更改不同模式的方向设置。

在此发布:Android VideoView 方向随缓冲视频发生变化

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

如果这对您没有帮助,那么我相信它会对其他人有所帮助,祝您好运。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文