自定义相机使用AVFoundation录制video时放大/缩小
在最新的iOS 7.1中,原生相机应用可以在录制video时放大/缩小,而照片中保存的video确实显示放大/缩小效果。
现在,我正在使用AVFoundation来实现自定义video。 我可以在录制video时放大/缩小,使用videoMaxScaleAndCropFactor修改AVCaptureVideoPreviewLayer。 但是,保存的video不会显示放大/缩小效果。
是否有任何提示实现此function????
我也在寻找那个。 下面的链接提供了缩放video的解决方案。
http://www.iphonelife.com/blog/87/imaging-video-guru-reporting-lossless-video-zooming-ios7
缩放video的逻辑是:
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];
尝试这个:
float zoomLevel = 2.0f; float zoomRate = 2.0f; if ([device respondsToSelector:@selector(rampToVideoZoomFactor:)] && device.activeFormat.videoMaxZoomFactor >= zoomLevel) { if ([[device lockForConfiguration:nil]) { [device rampToVideoZoomFactor:zoomLevel withRate:zoomRate]; [device unlockForConfiguration]; } }
这样可以实现平滑的变焦。 对于即时缩放(例如,响应由UISlider触发大量数据引起的小变化),使用setVideoZoomFactor:
而不是rampToVideoZoomFactor:withRate:
.