Tag: avcapture

AVCaptureStillImageOutput&UIImagePNGRepresentation

对于我认为不应该那么困难的事情,我很难过,所以我认为我必须从错误的angular度看问题。 为了解如何AVCaptureStillImageOutput和相机工作,我做了一个小应用程序。 这个应用程序能够拍照并将其保存为PNG文件(我不需要JPEG)。 下次启动应用程序时,会检查文件是否存在,如果存在,则将存储在文件内的图像用作应用程序的背景视图。 这个想法很简单。 问题是它不起作用。 如果有人能告诉我我做错了什么,这将是非常有帮助的。 我希望图片以与显示时相同的方式出现在背景上,但是它被旋转或者尺寸错误.. .. 这里是相关的代码(如果需要,我可以提供更多的信息)。 viewDidLoad方法: override func viewDidLoad() { super.viewDidLoad() // For the photo capture: captureSession.sessionPreset = AVCaptureSessionPresetHigh // Select the appropriate capture devices: for device in AVCaptureDevice.devices() { // Make sure this particular device supports video. if (device.hasMediaType(AVMediaTypeVideo)) { // Finally check the position and confirm we've got […]

播放声音时不停止录制Avcapture

我有一个video录像,那么我有一个AVAudioPlayer,问题是,当声音,你停止注册video。 testAudioPlayer = [[AVAudioPlayer alloc] initWithData:sampleData error:&audioError]; [sampleData release]; if(audioError != nil) { NSLog(@"An audio error occurred: \"%@\"", audioError); } else { [testAudioPlayer setVolume:100]; [testAudioPlayer setNumberOfLoops: -1]; [testAudioPlayer play];“ 提前致谢

AVCaptureStillImageOutput区域select

在用Swift编写的iOS应用程序中保存从相机拍摄的图像时,这是我面临的挑战。 我并不是完全按照自己的意愿去储蓄,而是在储蓄之外,而不是那么做。 这是这个问题的两个相关的代码块。 首先在会议开始的地方,人们可以看到我只看着一个椭圆形区域: previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) previewLayer?.frame = self.view.layer.frame self.view.layer.addSublayer(previewLayer!) let maskLayer = CAShapeLayer() maskLayer.path = CGPathCreateWithEllipseInRect(CGRect(x: 50.0, y: 100.0, width: 200.0, height: 100.0), nil) previewLayer!.mask = maskLayer captureSession.startRunning() 第二,保存图像并停止会话: if captureSession.running { if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) { stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) { (imageDataSampleBuffer, error) -> Void in if error == nil { let imageData […]

获取AvCaptureVideoDataOutput可用的实际NSStringVideoCVPixelFormatTypes

我正试图find一个AVFoundation输出接受的格式: self.theOutput=[[AVCaptureVideoDataOutput alloc]init]; if ([self.theSession canAddOutput:self.theOutput]) [self.theSession addOutput:self.theOutput]; 然后,我在之后插入一个断点: po [self.theOutput availableVideoCVPixelFormatTypes] 我得到这个: (NSArray *) $5 = 0x2087ad00 <__NSArrayM 0x2087ad00>( 875704438, 875704422, 1111970369 ) 我如何获得这些格式types的string值? 谢谢

捕获金属MTKView作为电影实时?

什么是从MTKView捕获帧的最有效的方法? 如果可能的话,我想实时保存帧中的.mov文件。 是否有可能渲染成一个AVPlayer框架或东西? 目前正在使用此代码(基于@warrenm PerformanceShaders 项目 )进行绘制: func draw(in view: MTKView) { _ = inflightSemaphore.wait(timeout: DispatchTime.distantFuture) updateBuffers() let commandBuffer = commandQueue.makeCommandBuffer() commandBuffer.addCompletedHandler{ [weak self] commandBuffer in if let strongSelf = self { strongSelf.inflightSemaphore.signal() } } // Dispatch the current kernel to perform the selected image filter selectedKernel.encode(commandBuffer: commandBuffer, sourceTexture: kernelSourceTexture!, destinationTexture: kernelDestTexture!) if let renderPassDescriptor […]

以与预览图层相匹配的大小导出AVCaptureSessionvideo

我使用AVCaptureSession录制video,会话预设为AVCaptureSessionPreset640x480 。 我正在使用非标准尺寸(300 x 300)的AVCaptureVideoPreviewLayer ,并在录制时将重力设置为方向填充。 它的设置是这样的: self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession]; _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; _previewLayer.frame = _previewView.bounds; // 300 x 300 [_previewView.layer addSublayer:_previewLayer]; 录制video后,我想以快速格式将其写入文件。 在播放过程中,我再次以300 x 300的非标准尺寸图层播放video。 由于这些video最终将通过networking连接进行传输,因此保留完整的640x480video看起来很浪费。 导出video以匹配我的300 x 300预览图层的最佳方式是什么? 我是一个AVFoundation noob,所以如果我正在做这个错误的方式,请让我知道。 我只想在logging期间预览层中显示的录制video与磁盘上导出的video相匹配。

iOS 5 – AVCaptureDevice设置对焦点和对焦模式冻结现场摄像头图像

我使用以下方法来设置从iOS 4开始的焦点: – (void) focusAtPoint:(CGPoint)point { AVCaptureDevice *device = [[self captureInput] device]; NSError *error; if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus] && [device isFocusPointOfInterestSupported]) { if ([device lockForConfiguration:&error]) { [device setFocusPointOfInterest:point]; [device setFocusMode:AVCaptureFocusModeAutoFocus]; [device unlockForConfiguration]; } else { NSLog(@"Error: %@", error); } } } 在iOS 4设备上,这个工作没有任何问题。 但在iOS 5上,实时摄像机馈送冻结,几秒钟后完全变黑。 没有exception或错误抛出。 如果我注释掉setFocusPointOfInterest或setFocusMode,则错误不会发生。 所以他们的组合都会导致这种行为。

AVCaptureDevice相机变焦

我有一个简单的AVCaptureSession运行在我的应用程序中获取相机源并拍照。 我如何使用相机的UIGestureRecognizer实现“捏放大”function?

如何在不使用预设的情况下在iOS上录制video?

在iOS上录制video更简单的方法是设置AVCaptureSession.sessionPreset 。 但是,这并不适合我,因为我想控制像binning,稳定(电影,标准,或无)和ISO参数。 我find了我想要的格式并将其分配给activeFormat ,但是当我尝试开始录制时,出现错误: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] No active/enabled connections' 这是我的初始化代码: let device = AVCaptureDevice.defaultDevice( withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .back)! let session = AVCaptureSession() session.addInput(try! AVCaptureDeviceInput(device: device)) output = AVCaptureMovieFileOutput() session.addOutput(output) device.setFormatWithHighestIso() session.startRunning() setFormatWithHighestIso()被定义为: extension AVCaptureDevice { var goodVideoFormats: [AVCaptureDeviceFormat] { return (formats as! [AVCaptureDeviceFormat]) […]

iOS:captureOutput:didOutputSampleBuffer:fromConnection不被调用

我想从AVCaptureSession的实时反馈中提取帧,我正在使用Apple的AVCam作为testing用例。 这里是AVCam的链接: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html 我发现captureOutput:didOutputSampleBuffer:fromConnection不被调用,我想知道为什么或者我在做什么错误。 这是我所做的: (1)我使AVCamViewController成为一个委托 @interface AVCamViewController () <AVCaptureFileOutputRecordingDelegate, AVCaptureVideoDataOutputSampleBufferDelegate> (2)我创build了一个AVCaptureVideoDataOutput对象并将其添加到会话中 AVCaptureVideoDataOutput *videoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; if ([session canAddOutput:videoDataOutput]) { [session addOutput:videoDataOutput]; } (3)我添加了委托方法,并通过logging随机string来testing – (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { NSLog(@"I am called"); } testing应用程序工作,但captureOutput:didOutputSampleBuffer:fromConnection不被调用。 (4)我在SO上读到AVCaptureSession *session = [[AVCaptureSession alloc] init];中的会话variablesAVCaptureSession *session = [[AVCaptureSession alloc] init]; 在viewDidLoad中是本地的,这是委托没有被调用的一个可能的原因,我把它作为AVCamViewController类的一个实例variables,但它没有被调用。 这里是我正在testing的viewDidLoad方法(取自AVCam),我添加AVCaptureDataOutput方法的结尾: – (void)viewDidLoad { [super […]