iOS AVFoundation视频捕获方向选项 [英] iOS AVFoundation Video Capture Orientation Options

查看:144
本文介绍了iOS AVFoundation视频捕获方向选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我只想对前置摄像头进行视频捕获.那没问题.但我希望即使手机是纵向放置,视频拍摄也始终能保持横向.

I have an app that I would like to have video capture for the front-facing camera only. That's no problem. But I would like the video capture to always be in landscape, even when the phone is being held in portrait.

我有一个基于Apple发布的AVCamDemo代码的有效实现.并借鉴此技术说明,我可以指定方向.只有一个窍门:视频帧的方向正确时,内容仍然看起来像是纵向拍摄:

I have a working implementation based on the AVCamDemo code that Apple published. And borrowing from the information in this tech note, I am able to specify the orientation. There's just one trick: while the video frame is oriented correctly, the contents still appear as though shot in portrait:

">

我想知道我是否刚被硬件的物理约束所束缚:图像传感器是否只是以这种方式定位?上面引用的技术说明做了以下说明:

I'm wondering if I'm just getting boned by the physical constraints of the hardware: is the image sensor just oriented this way? The referenced tech note above makes this note:

重要:在静止图像输出和动画上设置方向 文件输出不会物理旋转缓冲区.对于电影文件 输出,它将轨道转换(矩阵)应用于视频轨道,因此 影片在播放时旋转,并且用于静止图像输出 它插入exif元数据,供图像查看者用来旋转图像 稍后查看时正确显示.

Important: Setting the orientation on a still image output and movie file output doesn't physically rotate the buffers. For the movie file output, it applies a track transform (matrix) to the video track so that the movie is rotated on playback, and for the still image output it inserts exif metadata that image viewers use to rotate the image properly when viewing later.

但是我播放该视频的建议相反.任何见解或建议,将不胜感激!

But my playback of that video suggests otherwise. Any insight or suggestions would be appreciated!

谢谢, 亚伦.

推荐答案

要回答您的问题,是的,图像传感器的方向就是这样.该摄像机是具有固定方向的大约1兆像素的"1080p"摄像机. 5MP(或用于4S的8MP等)静态相机也具有固定的方向.镜头本身不会旋转,其他任何摄像头也不会旋转,因此进纸本身具有固定的方向.

To answer your question, yes, the image sensor is just oriented that way. The video camera is an approx 1-megapixel "1080p" camera that has a fixed orientation. The 5MP (or 8MP for 4S, etc) still camera also has a fixed orientation. The lenses themselves don't rotate nor do any of the other camera bits, and hence the feed itself has a fixed orientation.

但是等等!",您说,我用相机应用程序(或API)拍摄的照片可以正确旋转.为什么?这是因为iOS会在拍照时查看手机的方向,并将信息与图片一起存储(作为Exif附件).然而,视频并不是那么被标记-每个帧都必须被单独标记,然后当用户在视频过程中旋转手机时出现问题.

"But wait!", you say, "pictures I take with the camera app (or API) get rotated correctly. Why is that?" That's cuz iOS takes a look at the orientation of the phone when a picture is taken and stores that information with the picture (as an Exif attachment). Yet video isn't so flagged -- and each frame would have to be individually flagged, and then there's issues about what to do when the user rotates the phone during video....

因此,不,您不能问视频流或静止图像,当捕获视频时手机所处的方向.但是,您可以直接问电话现在的方向是什么:

So, no, you can't ask a video stream or a still image what orientation the phone was in when the video was captured. You can, however, directly ask the phone what orientation it is in now:

UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;

如果您是在视频捕获开始时(或从视频源抓取静止图像时)执行此操作,则可以使用该信息进行自己的旋转播放.

If you do that at the start of video capture (or when you grab a still image from a video feed) you can then use that information to do your own rotation of playback.

这篇关于iOS AVFoundation视频捕获方向选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆