你的位置:首页 > 软件开发 > 操作系统 > [iOS]关于视频方向的若干问题

[iOS]关于视频方向的若干问题

发布时间:2015-06-30 14:01:19
一、MOV/MP4视频文件中的Rotation元数据iOS上内置相机应用录制的mov/mp4视频可能产生一个Rotation元数据,表示录制视频时摄像头旋转到了多少角度。其值一般为这四个:0、90、180或270。类似于图片文件的Exif信息中的Orientation元数据。Ro ...

[iOS]关于视频方向的若干问题

一、MOV/MP4视频文件中的Rotation元数据

iOS上内置相机应用录制的mov/mp4视频可能产生一个Rotation元数据,表示录制视频时摄像头旋转到了多少角度。其值一般为这四个:0、90、180或270。类似于图片文件的Exif信息中的Orientation元数据。(图一:Rotation值为90)(图二:无Rotation值或者说Rotation值为0)
 1 #import "MPMoviePlayerViewController+Rotation.h" 2  3 @implementation MPMoviePlayerViewController (Rotation) 4  5 - (void)rotateVideoViewWithDegrees:(NSInteger)degrees 6 { 7   if(degrees==0||degrees==360) return; 8   if(degrees<0) degrees = (degrees % 360) + 360; 9   if(degrees>360) degrees = degrees % 360;10  11   // MPVideoView在iOS8中Tag为1002,不排除苹果以后更改的可能性。参考递归查看View层次结构的lldb命令: (lldb) po [movePlayerViewController.view recursiveDescription]12   UIView *videoView = [self.view viewWithTag:1002];13   if ([videoView isKindOfClass:NSClassFromString(@"MPVideoView")]) {14     videoView.transform = CGAffineTransformMakeRotation(M_PI * degrees / 180.0);15     videoView.frame = self.view.bounds;16   }17 }18 19 @end

七、按正确方向对视频进行截图

关键点是将AVAssetImageGrnerator对象的appliesPreferredTrackTransform属性设置为YES。

八、实时视频的方向处理

使用AVFoundation制作自定义相机时,采集出来的视频帧保存在CMSampleBufferRef结构中,颜色空间可以设置为RGB或YUV。进行一些内存操作就可实现旋转。以下代码是针对YUV的。 

原标题:[iOS]关于视频方向的若干问题

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。