Jef*_*rod 4 video android video-capture orientation android-video-player
我正在使用MediaStore.ACTION_VIDEO_CAPTURE捕获视频的意图,然后使用a来播放它VideoView.我想知道所拍摄视频的方向.
我不想在意图呼叫时使用方向,因为用户可能在按下快门按钮之前旋转设备.我也不想实现自己的自定义视频捕获.
视频的方向是存储在保存的文件中还是/或在意图结果中返回?
Joe*_*Joe 13
视频的方向是存储在保存的文件中还是/或在意图结果中返回?
AOSP VideoCamera活动确实将相机设备的旋转值提供给该MediaRecorder.setOrientationHint()方法.以下是VideoCamera.initializeRecorder()与此相关的代码中的代码摘录:
// See android.hardware.Camera.Parameters.setRotation for
// documentation.
// Note that mOrientation here is the device orientation, which is
// the opposite of what getWindowManager().getDefaultDisplay().getRotation()
// would return, which is the orientation the graphics need to rotate
// in order to render correctly.
int rotation = 0;
if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - mOrientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + mOrientation) % 360;
}
}
mMediaRecorder.setOrientationHint(rotation);
Run Code Online (Sandbox Code Playgroud)
这是用于setOrientationHint()解释信息存储的文档:
设置输出视频播放的方向提示.应在prepare()之前调用此方法.如果输出格式为OutputFormat.THREE_GPP或OutputFormat.MPEG_4,则此方法不会在视频录制期间触发源视频帧旋转,而是在输出视频中添加包含旋转角度的合成矩阵,以便视频播放器可以选择正确的播放方向.请注意,某些视频播放器可能会选择在播放期间忽略视频中的合成矩阵.
由于您使用框架的VideoView小部件来播放视频,它应该已经正确处理合成矩阵中的信息,您只需要比较视频的宽度和高度来决定是否为播放设置横向或纵向方向活动.一种简单的方法是调用ThumbnailUtils.createVideoThumbnail()(内部使用MediaMetaDataRetriever)并检查返回的位图的分辨率.
| 归档时间: |
|
| 查看次数: |
6886 次 |
| 最近记录: |