我的应用允许用户捕获视频:
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);
}
如何使用视频实现同样的效果?
最佳答案
我似乎没有完全理解你的问题。以下是我认为至少可以引导您朝着正确方向前进的一些问题。希望对你有帮助
是否要旋转视频以使用 MediaPlayer 播放?
是否要更改视频文件中的硬编码以使其随处旋转播放?
旋转缓冲视频方向?
============================================= =================================== 问题 # 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 orientation change with buffered video
============================================= ===================================
如果这对您没有帮助,那么我相信它会对其他人有所帮助,祝您好运。
关于java - 旋转以纵向模式拍摄的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391360/