[英]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.