使用AVFoundation录制视频时自定义相机放大/缩小 [英] Custom Camera zoom in/out while recording video using AVFoundation
问题描述
在最新的iOS 7.1中 本地相机应用程序可以在录制视频时放大/缩小,并且保存在照片"中的视频确实显示了放大/缩小效果.
In the latest iOS 7.1 the native camera app can zoom in/out while recording video, and the video saved in the Photos indeed shows the zoom in/out effect.
现在,我正在使用AVFoundation实施自定义视频. 通过使用videoMaxScaleAndCropFactor修改AVCaptureVideoPreviewLayer,可以在录制视频时放大/缩小.但是,保存的视频不会显示放大/缩小效果.
now, I am using AVFoundation to implement custom Video. I can zoom in/out while recording video by using videoMaxScaleAndCropFactor to modify AVCaptureVideoPreviewLayer. However, the saved video doesn't show the zoom in/out effect.
是否有实现此功能的提示?
Is there any hint to implement this function ????
推荐答案
我也在搜索.下面的链接提供了缩放视频的解决方案.
I am also searching for that. The link below gives a solution for zooming video.
http://www. iphonelife.com/blog/87/imaging-video-guru-reporting-lossless-video-zooming-ios7
缩放视频的逻辑是:
int selectedAVCaptureDeviceFormatIdx = 15;
[self.videoDevice lockForConfiguration:nil];
AVCaptureDeviceFormat* currdf = [self.videoDevice.formats objectAtIndex:selectedAVCaptureDeviceFormatIdx];
self.videoDevice.activeFormat = currdf;
if (selectedAVCaptureDeviceFormatIdx==12 || selectedAVCaptureDeviceFormatIdx==13)
self.videoDevice.activeVideoMaxFrameDuration = CMTimeMake(1,60);
NSLog(@"%f", self.videoDevice.activeFormat.videoMaxZoomFactor);
NSLog(@"videoZoomFactorUpscaleThreshold: %f", self.videoDevice.activeFormat.videoZoomFactorUpscaleThreshold);
// If you want to zoom to the threshold of possible zooming before binning occurs
self.videoDevice.videoZoomFactor = videoDevice.activeFormat.videoZoomFactorUpscaleThreshold;
// If you want to set your own zoom factor
//self.videoDevice.videoZoomFactor = 3.0f;// here zoom given in CGFloat like 1, 2, 3, 4, 5.
[self.videoDevice unlockForConfiguration:nil];
这篇关于使用AVFoundation录制视频时自定义相机放大/缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!