Tag: avfoundation

知道AVCaptureSession会话预设的parsing

我正在iOS中访问摄像头,并使用会话预设: captureSession.sessionPreset = AVCaptureSessionPresetMedium; 很标准的东西。 不过,由于这个预设,我想提前知道video的分辨率(尤其是因为根据设备的不同而不同)。 我知道有网上的表格,你可以看看这个(如在这里: http : //cmgresearch.blogspot.com/2010/10/augmented-reality-on-iphone-with-ios40.html )。 但是我希望能够以编程方式获得这个结果,这样我就不仅仅依靠魔术数字。 所以,这样(理论上): [captureSession resolutionForPreset:AVCaptureSessionPresetMedium]; 这可能会返回一个CGSize {宽度:360,高度:480}。 我一直没有find任何这样的API,到目前为止,我不得不等待获得我的第一个捕获的图像,然后查询(由于其他原因,在我的程序stream程是不好的)。

如何使用AVCaptureStillImageOutput拍摄照片

我有一个预览图层,正在从相机中拉出,并按照它应该的工作。 我想按一下button就能拍照。 我已经像这样引入了AVCaptureStillImageOutput: AVCaptureStillImageOutput *avCaptureImg = [[AVCaptureStillImageOutput alloc] init]; 然后,我正在尝试使用此对象拍摄照片: [avCaptureImg captureStillImageAsynchronouslyFromConnection:(AVCaptureConnection *) completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { }]; 我需要关于如何拍摄照片并将其保存在variables中的帮助。 谢谢

如何将AVAssetReader和AVAssetWriter同时用于多个音轨(audio和video)?

我知道如何使用AVAssetReader和AVAssetWriter,并成功地使用它们从一部电影中抓取video轨道并将其转码为另一部电影。 不过,我也想用audio来做这个。 在完成初始转码后,是否必须创buildAVAssetExportSession,还是在写作过程中有一些方法可以在音轨之间切换? 我讨厌不得不处理AVAssetExportSession的开销。 我问,因为使用拉风格的方法 – (while([assetWriterInput isReadyForMoreMediaData]){…} – 假设只有一个轨道,它怎么能用于多个轨道,即audio和video轨道?

AVFoundation:将文本添加到CMSampleBufferRefvideo帧

我正在使用AVFoundation构build一个应用程序。 就在我调用[assetWriterInput appendSampleBuffer:sampleBuffer] – (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection – 方法。 我操纵样本缓冲区中的像素(使用像素缓冲区来应用效果)。 但是客户希望我在框架中input文本(时间戳和帧计数器),但是我还没有find一种方法来完成这个任务。 我试图将samplebuffer转换成图像,在图像上应用文本,然后将图像转换回采样缓冲区,但是 CMSampleBufferDataIsReady(sampleBuffer) 失败。 这里是我的UIImage类别的方法: + (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0); uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, […]

在AVCaptureVideoPreviewLayer中精确剪裁捕获的图像

我有一个使用AV基础的照片应用程序。 我使用AVCaptureVideoPreviewLayer设置了一个预览图层,占用屏幕的上半部分。 所以当用户试图拍照时,他们只能看到屏幕的上半部分。 这样做效果很好,但是当用户真正拍摄照片时,我尝试将照片设置为图层内容,图像失真。 我做了研究,并意识到我需要裁剪图像。 我想要做的就是裁剪完整的图像,以便所有剩下的东西正是用户最初在屏幕上半部分看到的。 我已经能够做到这一点,但我通过input手动CGRect值来做到这一点,它仍然看起来不完美。 必须有一个更简单的方法来做到这一点。 在过去的两天里,我已经翻阅了关于裁剪图像的每一篇文章,并没有任何工作。 必须以编程方式裁剪捕获的图像,以便最终图像与预览图层中最初看到的图像完全一致。 这是我的viewDidLoad实现: – (void)viewDidLoad { [super viewDidLoad]; AVCaptureSession *session =[[AVCaptureSession alloc]init]; [session setSessionPreset:AVCaptureSessionPresetPhoto]; AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error = [[NSError alloc]init]; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error]; if([session canAddInput:deviceInput]) [session addInput:deviceInput]; CALayer *rootLayer = [[self view]layer]; [rootLayer setMasksToBounds:YES]; _previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:session]; [_previewLayer setFrame:CGRectMake(0, […]

使用AVFoundation的video的第一帧

我正在尝试使用AVFoundation中的类获取video的第一帧。 但它似乎没有得到一个形象。 我的代码目前看起来像这样 AVURLAsset* asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoPath] options:nil]; AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]]; [videoFrame setImage:image]; videopath的值是/var/mobile/Applications/02F42CBF-D8BD-4155-85F2-8CF1E55B5023/Documents/videos/1334300431637030.mp4这绝对是一个video,因为我可以用MPMoviePlayerViewController播放它。 我不知道我做错了什么,但任何build议将是有益的。 谢谢。

AVCaptureVideoPreviewLayer平滑的方向旋转

我试图禁用任何可辨别的方向旋转到AVCaptureVideoPreviewLayer,同时仍然保持任何子视图的旋转。 AVCaptureVideoPreviewLayer确实有一个方向属性,改变它确实允许图层正确显示任何方向。 然而,旋转涉及AVCaptureVideoPreviewLayer的一些时髦的旋转,而不是像在相机应用程序中一样保持平滑。 这就是我如何正确工作的方向,减去旋转中的障碍: – (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { _captureVideoPreviewLayer.frame = self.view.bounds; _captureVideoPreviewLayer.orientation = [[UIDevice currentDevice] orientation]; } 如何让这个图层像Camera应用一样运行,同时保持子视图的旋转? 此外,顺便说一下,我已经看到AVCaptureVideoPreviewLayer方向属性折旧,AVCaptureConnection的videoOrientation属性应该用来代替,但我不认为我有一个AVCaptureConnection访问在这里(我只是显示相机在屏幕上)。 我应该如何设置这个访问videoOrientation?

xcode:如何使用AVFoundation录制audio后保存audio文件

我浏览了与这个主题相关的各种post,但答案并没有真正的帮助。 我使用本教程来实现录制audio文件和播放。 似乎缺less的是如何永久保存logging。 当我退出我的应用程序的声音文件是在那里,但没有任何内容。 我甚至不知道它是保存rocerd还是只创build文件。 这是一个代码示例: NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"tmpSound.caf"]; tempRecFile = [NSURL fileURLWithPath:soundFilePath]; NSDictionary *recSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt:16], AVEncoderBitRateKey, [NSNumber numberWithInt: 2], AVNumberOfChannelsKey, [NSNumber numberWithFloat:44100.0], AVSampleRateKey, nil]; recorder = [[AVAudioRecorder alloc] initWithURL:tempRecFile settings:recSettings error:nil]; [recorder setDelegate:self]; [recorder […]

有谁知道如何正确实施AVAssetResourceLoaderDelegate方法?

我试图哄AVFoundation从自定义URL读取。 自定义url的东西工作。 下面的代码创build一个带有电影文件的NSData: NSData* movieData = [NSData dataWithContentsOfURL:@"memory://video"]; 我使用下面的代码设置了一个AVAssetResourceLoader对象: NSURL* url = [NSURL URLWithString:@"memory://video"]; AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:url options:nil]; AVAssetResourceLoader* loader = [asset resourceLoader]; [loader setDelegate:self queue:mDispatchQueue]; 调度队列是并发的。 然后我尝试从电影中提取第一帧: AVAssetImageGenerator* imageGen = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; CMTime time = CMTimeMakeWithSeconds(0, 600); NSError* error = nil; CMTime actualTime; CGImageRef image = [imageGen copyCGImageAtTime:time actualTime:&actualTime error:&error]; if […]

如何在保持界面响应的同时以可接受的性能logging屏幕?

我在基于Objective-C的iOS应用程序中寻找有关性能问题的帮助。 我有一个iOS应用程序,使用CALayer的renderInContext方法捕获屏幕的内容。 它试图捕获足够的屏幕帧,使用AVFoundation创buildvideo。 然后将屏幕录制与其他元素结合起来用于可用性的研究。 在捕捉屏幕的同时,应用程序也可能会显示UIWebView的内容,通过networking去获取数据等等。Web视图的内容不在我的控制之下 – 它是来自网页。 这个设置正在工作,但你可能想象的是,它不是平稳的。 由于图层必须在主线程上呈现,因此比我想要的更多的UI争用。 我想要做的就是进行一个设置,将UI的响应优先于屏幕截图。 例如,如果用户正在滚动Web视图,我宁愿放弃录制的帧,而不是有可怕的滚动体验。 我已经尝试了几种技术,从dispatch_source合并到将框架捕获请求作为块提交给主要队列到CADisplayLink。 到目前为止,他们似乎都performance相同。 当前正在屏幕的主视图的drawRect中触发帧捕获。 我在这里问的是:鉴于上述情况,你会build议我采取什么技术来实现我的目标? 我意识到答案可能是没有很好的答案…但是我想尝试一下,不过听起来很古怪。 注意:无论什么技术都需要App Store友好。 不能使用显示logging器使用/使用的CoreSurface入侵。 谢谢你的帮助!