Tag: avfoundation

使用AVFoundation从video中捕获图片

我正试图从iPad上的video中捕捉图片。 我以苹果的AVCam例子为出发点。 我能够看到我的应用程序中的video,并从中拍照。 我的问题是,结果图像的像素大小是错误的。 我想要一个全屏图片(1024×768),但我得到一个较小的(1024×720)。 这些是我的实例variables: @property (retain) AVCaptureStillImageOutput *stillImageOutput; @property (retain) AVCaptureVideoPreviewLayer *previewLayer; @property (retain) AVCaptureSession *captureSession; @property (retain) AVCaptureConnection *captureConnection; @property (retain) UIImage *stillImage; 这里的代码拍照: – (void)takePicture { AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo]) { videoConnection […]

iOS旋转videoAVAsset avfoundation

例 嗨, 努力旋转此video以正确的方向显示并填满整个屏幕。 我无法使用videocompisition获得avasset,但无法使其正常工作。 let videoAsset: AVAsset = AVAsset(URL: outputFileURL) as AVAsset let clipVideoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo).first! as AVAssetTrack let newHeight = CGFloat(clipVideoTrack.naturalSize.height/3*4) let composition = AVMutableComposition() composition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID()) let videoComposition = AVMutableVideoComposition() var videoSize = CGSize() videoSize = clipVideoTrack.naturalSize videoComposition.renderSize = videoSize videoComposition.frameDuration = CMTimeMake(1, 30) let instruction = AVMutableVideoCompositionInstruction() instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(180, […]

路由audioinput从iPhone上的TOP麦克风接收

我正在写一个小应用程序来logging多个轨道,并将其重新播放。 我正在使用PlaybackAndRecord模式,并将我的输出路由到主扬声器。 问题是底部的麦克风还在使用input,所以现在当我录音的时候,新轨道上的其他音轨输出真的很响。 这是我到目前为止: audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; OSStatus propertySetError = 0; UInt32 allowMixing = true; propertySetError = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing); UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); [audioSession setActive:YES error:nil];

使用AVFoundation将章节信息添加到现有video

我正在尝试将章节标记(文本+图像)添加到iOS中的现有video。 使用内置函数读取它们非常简单: NSLocale * locale = [chapterLocalications lastObject]; NSLog(@"Locale: %@", [locale localeIdentifier]); NSArray *keys = @[AVMetadataCommonKeyTitle, AVMetadataCommonKeyArtwork]; NSArray *chapters = [asset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:keys]; for (AVTimedMetadataGroup * metadataGroup in chapters) { NSArray * items = metadataGroup.items; CMTimeRange timeRange = metadataGroup.timeRange; NSLog(@"time: %@", CMTimeCopyDescription(NULL, timeRange.start)); for (AVMetadataItem * metadataItem in items) { NSLog(@"key: %@", metadataItem.commonKey); NSLog(@"value: %@", […]

核心数据错误 – NSDate localizedCaseInsensitiveCompare:无法识别的select器发送到实例

我已经search了最近几个小时,但还没有find答案。 我实现了一个AVFoundation相机,我将图像数据保存到磁盘,并只存储在核心数据的path。 一切工作正常,但随机数拍摄的照片后,我得到这个错误: CoreData:错误:严重的应用程序错误。 核心数据更改处理期间发生exception。 这通常是NSManagedObjectContextObjectsDidChangeNotification观察者中的一个错误。 – [__ NSDate localizedCaseInsensitiveCompare:]:无法识别的select器发送到实例 这是我的抓取请求代码: NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notebook = %@", notebookItem]; [request setPredicate:predicate]; request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"dateTaken" ascending:NO selector:@selector(compare:)]]; 这里是我如何将数据保存在一个单独的类: //I create a photo Object to save to core data and set properties like dateTaken and tittle //Here is where I create […]

iOS 9:AVFoundation导出会话缺lessaudio

在使用原始audio合并video时,我正在使用以下代码。 它一直在工作,直到我升级到iOS9。 任何人都面临同样的问题,任何帮助解决将不胜感激。 经过一整天的研究,我找不到任何东西。 AVAssetTrack *videoTrack = nil; AVAssetTrack *audioTrack = nil; CMTime insertionPoint = kCMTimeZero; if([[url tracksWithMediaType:AVMediaTypeVideo] count] != 0) { videoTrack = [url tracksWithMediaType:AVMediaTypeVideo][0]; } if([[url tracksWithMediaType:AVMediaTypeAudio] count] != 0) { audioTrack = [url tracksWithMediaType:AVMediaTypeAudio][0]; } // Insert the video and audio tracks from AVAsset if (videoTrack != nil) { AVMutableCompositionTrack *compositionVideoTrack = […]

如何录制video并以当前重放速度放慢速度?

我可以从临时url获取video并将video保存在照片库中。 如何制作带有缓变慢动作的video? 我知道这可以通过currentplayrate来完成。 我不知道如何应用它。 如何调整速度,然后将其保存到照片库? 注:我使用MPMoviePlayerViewController来播放/修剪和保存video。 参考编号: -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // 1 – Get media type NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; // 2 – Dismiss image picker [self dismissModalViewControllerAnimated:NO]; // Handle a movie capture if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) { // 3 – Play the video MPMoviePlayerViewController *theMovie = […]

在录制的video上合成基于帧的animation贴纸的最佳方法是什么?

我们希望允许用户将animation“贴纸”放在他们在应用程序中录制的video中,并考虑采用不同的方法来组合这些贴纸。 使用AVAssetWriter从基于帧的animation贴纸(可以旋转,并应用翻译)创buildAVAssetWriter 。 问题是AVAssetWriter只写入一个文件,并不保持透明度。 这将阻止我们能够使用AVMutableComposition对video进行AVMutableComposition 。 提前创build.mov文件用于我们的基于框架的贴纸,并使用AVMutableComposition和带有transformations layer指令进行AVMutableComposition 。 这个问题是没有工具可以轻松地将我们的PNG帧转换为.mov同时保持一个alpha通道,我们必须写我们自己的。 为贴图animation中的每个帧创build单独的CALayers 。 这可能会在video的每帧速率上创build大量的图层。 还是有更好的点子? 谢谢。

在swift 2中无法使用AVCaptureVideoDataOutput通过CGDataProviderCopyData获取像素数据

我正在更新这个 swift 2.0,我目前得到fatal error: unexpectedly found nil while unwrapping an Optional value上线: let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef)) as! NSData let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef)) as! NSData func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) { print("Capture output running") let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) CVPixelBufferLockBaseAddress(imageBuffer!, 0) let baseAddress = CVPixelBufferGetBaseAddressOfPlane(imageBuffer!, 0) let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!) let width = […]

初始化The Amazing Audio Engine后,没有录像中的audio(使用GPUImage)

我在我的项目中使用了两个第三方工具。 一个是“惊人的audio引擎” 。 我使用这个audiofilter。 另一个是GPUImage,或者更具体地说是GPUImageMovieWriter 。 当我录制video时,我将录音与video合并在一起。 这工作正常。 但是,有时我不使用惊人的audio引擎,只使用GPUImageMovieWriter录制一个正常的video。 问题是,即使在初始化“惊人的audio引擎”之后,video在开始时只有一小部分的audio,然后audio消失了。 + (STAudioManager *)sharedManager { static STAudioManager *manager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ if (!manager) { manager = [[STAudioManager alloc] init]; manager.audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES]; manager.audioController.preferredBufferDuration = 0.005; manager.audioController.voiceProcessingEnabled = YES; manager.audioController.useMeasurementMode = YES; } }); return manager; } TAAE初始化时发生了一些事情。 我怀疑这是AVAudioSession的事情,因为它是一个sharedInstance。 […]