【问题标题】:Custom Camera zoom in/out while recording video using AVFoundation使用 AVFoundation 录制视频时自定义相机放大/缩小
【发布时间】:2014-05-10 07:34:13
【问题描述】:

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

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

有实现这个功能的提示吗????

【问题讨论】:

  • 对不起,我在评论中写,但如果你得到一些线索,就必须写在这里..谢谢投票给 que.. :)

标签: ios video avfoundation zooming recording


【解决方案1】:

试试这个:

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:

【讨论】:

  • 我希望我能多次支持你的答案,工作绝对没问题。谢谢,你拯救了我的一天。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多