Tag: avfoundation

内存泄漏在CMSampleBufferGetImageBuffer

我得到一个CMSampleBufferRefvideo缓冲区每N个video帧的UIImage ,如: – (void)imageFromVideoBuffer:(void(^)(UIImage* image))completion { CMSampleBufferRef sampleBuffer = _myLastSampleBuffer; if (sampleBuffer != nil) { CFRetain(sampleBuffer); CIImage *ciImage = [CIImage imageWithCVPixelBuffer:CMSampleBufferGetImageBuffer(sampleBuffer)]; _lastAppendedVideoBuffer.sampleBuffer = nil; if (_context == nil) { _context = [CIContext contextWithOptions:nil]; } CVPixelBufferRef buffer = CMSampleBufferGetImageBuffer(sampleBuffer); CGImageRef cgImage = [_context createCGImage:ciImage fromRect: CGRectMake(0, 0, CVPixelBufferGetWidth(buffer), CVPixelBufferGetHeight(buffer))]; __block UIImage *image = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); […]

内存问题

我正在编写一个库,使用AVFoundation将资产导出到一个文件。 我创build一个阅读器,一个编写器,将input和输出连接到这些input和输出,然后调用input上的requestMediaDataWhenReadyOnQueue方法来开始提取数据。 提供给这个方法的块callback看起来有点像这样: [input requestMediaDataWhenReadyOnQueue:queue usingBlock:^{ while ([input isReadyForMoreMediaData]) { CMSampleBufferRef buffer; // The track has some more data for us if ([reader status] == AVAssetReaderStatusReading && (buffer = [output copyNextSampleBuffer])) { BOOL result = [input appendSampleBuffer:buffer]; CFRelease(buffer); if (!result) { // handle error break; } // The track is finished, for whatever reason } […]

AVCaptureTorchModeAuto不会持续更新火炬模式

我正在写一个应用程序,根据照明条件自动打开iOS设备背面的手电筒。 该应用呈现实时相机视图,并且不loggingvideo。 我曾尝试使用AVCaptureTorchModeAuto ,但它似乎只是在拍摄会话开始时测量图像的亮度,并相应地设置了手电筒。 然后,不pipe摄像机图像的亮度如何,设置都不会改变。 如文件中所述 ,系统可以持续调整割炬吗? 捕捉设备持续监控光照水平,并在必要时使用手电筒。 在iOS 4.0及更高版本中可用。

在iOS中访问所有电影帧的最佳方法

我试图编辑现有的电影与顶部的附加效果,因此我需要能够扫描所有电影帧,获得他们作为UIImage,应用效果,然后或者更新该帧或写入到新的电影。 我发现有人build议使用AVAssetImageGenerator。 下面是我最后编辑的样品,我如何做到这一点: -(void)processMovie:(NSString*)moviePath { NSURL* url = [NSURL fileURLWithPath:moviePath]; AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil]; float movieTimeInSeconds = CMTimeGetSeconds([movie duration]); AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; generator.requestedTimeToleranceBefore = generator.requestedTimeToleranceAfter = kCMTimeZero; generator.appliesPreferredTrackTransform=TRUE; [asset release]; // building array of time with steps as 1/10th of second NSMutableArray* arr = [[[NSMutableArray alloc] init] retain]; for(int i=0; i<movieTimeInSeconds*10; […]

尝试设置(空)audio设备采样率的错误“!dat”

我试图播放一个audio剪辑(使用AVAudioPlayer)和一个video剪辑(使用MPMoviePlayerController),这两个工作。 然后,我将这些文件检入到SVN中,并在另一台Mac上删除它们。 现在,当我尝试播放audio或video时运行应用程序(iPad应用程序)时,都会显示以下错误: 尝试设置(空)audio设备采样率的错误“!dat” 考虑到SVN破坏了文件,(即使Mac的QuickLook也能正常播放),我用Mac上的版本replace了它们。 不过,我仍然收到错误。 所有代码在两台机器上都完全相同,但是原来使用的Mac(MacBook Pro)将在模拟器中同时播放它们,但在第二台Mac(Mac Pro)上,它们将不会播放并出现此错误。 有谁知道这个错误是什么意思,或者我可以修复它(因为覆盖媒体文件不工作) 谢谢 播放audio的代码: NSError *error; [[AVAudioSession sharedInstance] setDelegate:self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:&error]; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Page_7.m4a", [[NSBundle mainBundle] resourcePath]]]; if (audioPlayer == nil) { audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; audioPlayer.numberOfLoops = 0; } if (audioPlayer == nil) NSLog(@"%@", [error […]

捕捉照片时切换AVCaptureSession预设

我目前的设置如下(基于Brad Larson的ColorTrackingCamera项目): 我正在使用一个AVCaptureSession设置为AVCaptureSessionPreset640x480 ,我让输出运行通过OpenGL场景作为纹理。 这个纹理然后由片段着色器操纵。 我需要这个“低质量”预设,因为我想在用户预览时保持较高的帧速率。 然后我想在用户捕捉静止照片时切换到更高质量的输出。 首先,我想我可以改变AVCaptureSession上的sessionPreset ,但这迫使相机重新调整它的可用性。 [captureSession beginConfiguration]; captureSession.sessionPreset = AVCaptureSessionPresetPhoto; [captureSession commitConfiguration]; 目前我想添加第二个AVCaptureStillImageOutput到AVCaptureSession,但我得到一个空的pixelbuffer,所以我觉得我有点卡住了。 这是我的会话设置代码: … // Add the video frame output [captureSession beginConfiguration]; videoOutput = [[AVCaptureVideoDataOutput alloc] init]; [videoOutput setAlwaysDiscardsLateVideoFrames:YES]; [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; [videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; if ([captureSession canAddOutput:videoOutput]) { [captureSession addOutput:videoOutput]; } else { NSLog(@"Couldn't add video output"); […]

在iOS中同时录制和播放audio

我正试图在录制的同时播放录制的内容。 目前我正在使用AVAudioRecorder进行录制, AVAudioPlayer进行播放。 当我试图同时播放内容时,没有任何东西在播放。 请find我正在做的伪代码。 如果我停止录音后一切正常,一切正常。 AVAudioRecorder *recorder; //Initializing the recorder properly. [recorder record]; NSError *error=nil; NSUrl recordingPathUrl; //Contains the recording path. AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordingPathUrl error:&error]; [audioPlayer prepareToPlay]; [audioPlayer play]; 你能请任何人让我知道你的想法或想法?

audioCMSampleBuffer的深度副本

我正在尝试创build一个由CaptureOutput在AVCaptureAudioDataOutputSampleBufferDelegate返回的CMSampleBuffer的副本。 我遇到的问题是,我的框架来自委托方法captureOutput:didOutputSampleBuffer:fromConnection:在我长时间保留在CFArray后被删除。 显然,我需要创build传入缓冲区的深层副本进行进一步处理。 我也知道CMSampleBufferCreateCopy只创build浅拷贝。 SO上提出的相关问题很less: 从CMSampleBuffer提取数据以创build深层副本 在Swift中创buildCMSampleBuffer的副本将返回OSStatus -12743(无效的媒体格式) CMImageBuffer或CVImageBuffer的深度拷贝 但是他们都没有帮我正确使用具有12个参数的CMSampleBufferCreate函数: CMSampleBufferRef copyBuffer; CMBlockBufferRef data = CMSampleBufferGetDataBuffer(sampleBuffer); CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer); CMItemCount itemCount = CMSampleBufferGetNumSamples(sampleBuffer); CMTime duration = CMSampleBufferGetDuration(sampleBuffer); CMTime presentationStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); CMSampleTimingInfo timingInfo; timingInfo.duration = duration; timingInfo.presentationTimeStamp = presentationStamp; timingInfo.decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer); size_t sampleSize = CMBlockBufferGetDataLength(data); CMBlockBufferRef sampleData; if (CMBlockBufferCopyDataBytes(data, 0, sampleSize, &sampleData) != […]

ios AVCaptureVideoPreviewLayer捕获当前图像

一旦默认的iPhone相机应用程序拍摄照片,预览出现,图像animation到相机滚动button。 我正试图复制这个animation。 session = [[AVCaptureSession alloc] init]; session.sessionPreset = AVCaptureSessionPresetPhoto; CALayer *viewLayer = self.vImagePreview.layer; NSLog(@"viewLayer = %@", viewLayer); captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.frame = CGRectMake(0, 0, 322, 425); [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error = nil; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; if (!input) { // Handle the error appropriately. NSLog(@"ERROR: trying […]

AVAssetWriter输出(UIImage写入video)失真

我正在使用AVAssetWriter将一系列图像编码为电影文件,以下是Zoul的答案: 如何将UIImage数组导出为电影? 。 总之我的过程是: 从.png文件创buildUIImage 从UIImage获取CGImage 将CGImage转换为CVPixelBuffer(完全使用zoul的函数pixelBufferFromCGImage) 使用AVAssetWriterInputPixelBufferAdaptor和AVAssetWriter将帧写入.mov 这在大多数情况下工作正常,但有时编码的.mov文件是扭曲的(见下图)。 我想知道这种types的失真图像输出是否对任何人都熟悉,如果有任何的步骤,我可能会采取编码框架,会导致这一点。 当我使用的源图像是由Titanium调用ImageView.toBlob()生成的时候,就会出现这个问题。 除了titanium方面,关于这种types的结果可能出现的任何提示将是伟大的! 谢谢,亚历山大 从电影屏幕: http : //tinypic.com/view.php?pic=8wkqys&s=7 原始图片: http : //commons.wikimedia.org/wiki/File : Phalaenopsis_(aka).jpg