繁体   English   中英

自定义相机使用AVFoundation录制视频时放大/缩小

[英]Custom Camera zoom in/out while recording video using AVFoundation

在最新的iOS 7.1中,原生相机应用可以在录制视频时放大/缩小,而照片中保存的视频确实显示放大/缩小效果。

现在,我正在使用AVFoundation来实现自定义视频。 通过使用videoMaxScaleAndCropFactor修改AVCaptureVideoPreviewLayer,我可以在录制视频时放大/缩小。 但是,保存的视频不会显示放大/缩小效果。

是否有任何提示实现此功能????

我也在寻找那个。 下面的链接提供了缩放视频的解决方案。

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];

试试这个:

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: .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM