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.
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 ????
Try this:
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];
}
}
That gives a smooth zoom. For an instant zoom (e.g. responding to small changes caused by a UISlider firing off lots of data) use setVideoZoomFactor:
instead of rampToVideoZoomFactor:withRate:
.
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
The logic for zooming video is:
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With