在最新的iOS 7.1中,原生相机应用程序可以在录制视频时放大/缩小,保存在照片中的视频确实显示了放大/缩小效果。
现在,我使用AVFoundation来实现自定义视频。通过使用videoMaxScaleAndCropFactor修改AVCaptureVideoPreviewLayer,我可以在录制视频时放大/缩小。但是,保存的视频不会显示放大/缩小效果。
有没有实现这个函数的提示?
发布于 2014-04-03 18:31:37
试试这个:
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:。
发布于 2014-04-16 18:31:29
我也在寻找它。下面的链接提供了缩放视频的解决方案。
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];https://stackoverflow.com/questions/22753499
复制相似问题