Tag: avfoundation

使用AVFoundation混合图像和video

我试图在图像拼接到一个预先存在的video来创build一个新的video文件在Mac上使用AVFoundation。 到目前为止,我已经阅读了苹果文档的例子, ASSETWriterinput从iPhone上的UIImagesvideo制作video问题 使用AVVideoCompositionCoreAnimationTool将video与静态图像混合在CALayer中 AVFoundation教程:添加覆盖和animationvideo和一些其他的SO链接 现在,这些已经被certificate是非常有用的,但是我的问题是,我没有创build一个静态水印或覆盖,我想要在video的各个部分之间放置图像。 到目前为止,我已经设法获取video,并创build空白部分插入这些图像,并将其导出。 我的问题是让图像插入自己在这些空白部分。 我能看到的唯一方法就是创build一系列的animation图层,以在正确的时间改变其不透明度,但似乎无法使animation起作用。 下面的代码是我用来创buildvideo片段和图层animation。 //https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_Editing.html#//apple_ref/doc/uid/TP40010188-CH8-SW7 // let's start by making our video composition AVMutableComposition* mutableComposition = [AVMutableComposition composition]; AVMutableCompositionTrack* mutableCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVMutableVideoComposition* mutableVideoComposition = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:gVideoAsset]; // if the first point's frame doesn't start on 0 if (gFrames[0].startTime.value != 0) { DebugLog("Inserting vid at 0"); // […]

使用AVMutableVideoComposition时,AVMutableComposition的怪异行为被冻结

我正在尝试使用AVMutableComposition合并多个video。 我面对的问题是,每当我尝试添加任何AVMutableVideoComposition来应用任何指令时,我的播放会在AVPlayer以6秒的时间间隔冻结。 另一个有趣的事情是,如果我使用相同的videoComposition导出后在iPad的照片应用程序中播放它,它会发挥很好。 那么为什么它在AVPlayer 6秒钟冻结? 码: AVMutableComposition *mutableComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVMutableCompositionTrack *audioCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; for (AVURLAsset *asset in assets) { AVAssetTrack *assetTrack; assetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; AVAssetTrack *audioAssetTrack = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject; NSError *error; [videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration ) ofTrack:assetTrack atTime:time error:&error]; if (error) { NSLog(@"asset url […]

照片框架:与assetsd的连接被中断或资产死亡

当我尝试使用这个swift库( https://github.com/piemonte/player )播放多个video时,出现此错误。 不知道它是否与该播放器,或相框框架或相关。 会发生什么,我有一个观点,将显示一张照片或一个video。 一切正常工作,直到有几个video播放,然后这个消息将popup,其次是所有的video无法播放,在他们的地方,你只是看到一个黑屏,然后我得到一个内存使用错误。 我正在使用一个名为SwipeView的库,这里有一些相关的代码可能会有所帮助。 func swipeView(swipeView: SwipeView!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! { let asset: PHAsset = self.photosAsset[index] as PHAsset // Create options for retrieving image (Degrades quality if using .Fast) // let imageOptions = PHImageRequestOptions() // imageOptions.resizeMode = PHImageRequestOptionsResizeMode.Fast var imageView: UIImageView! let screenSize: CGSize = UIScreen.mainScreen().bounds.size let […]

Progressive Video在iOS上下载

我正在尝试在iOS应用程序中通过AVPlayer播放video的渐进式下载 。 我已经实现了一个可以下载文件到iPad的下载器模块。 但是,我发现我无法播放仍在写入的文件 所以,据我所知,我唯一的解决办法是通过下载一个文件“块”的列表,然后继续播放每个文件,因为他们准备好了(即:下载),可能使用HLS search我遇到了这个通过hls实现渐进式下载的问题,除此以外 ,我找不到其他方法 不过,我不断遇到search结果,说如何configurationWeb服务器利用iOS支持HTTP渐进式下载,但没有提到如何从iOS端做到这一点 那么,有没有人有任何想法和/或经验呢? 编辑:我也发现有可能是这样做的其他方式(即:stream,然后写stream媒体数据到磁盘),这是由这个问题,但仍然无法得到它的工作,因为它似乎不工作非本地资产!

如何控制AVAssetWriter以正确的FPS写入

让我看看我是否理解正确。 在目前最先进的硬件,iOS允许我logging下面的帧数:30,60,120和240。 但是这些fps的行为有所不同。 如果我以30或60 fps的速度拍摄,我预计这些fps拍摄的video文件分别以30 fps和60 fps的速度播放。 但是,如果我以120或240 fps的速度拍摄,我预计在这些fps下拍摄的video文件可以以30 fps的速度播放,否则我将看不到慢镜头。 几个问题: 我对吗? 有没有办法以120或240 fps的速度拍摄,分别以120和240 fps的速度拍摄? 我的意思是在fps上播放video是在没有慢镜头的情况下拍摄的? 我在写文件时如何控制帧速率? 我正在创build这样的AVAssetWriterinput… NSDictionary *videoCompressionSettings = @{AVVideoCodecKey : AVVideoCodecH264, AVVideoWidthKey : @(videoWidth), AVVideoHeightKey : @(videoHeight), AVVideoCompressionPropertiesKey : @{ AVVideoAverageBitRateKey : @(bitsPerSecond), AVVideoMaxKeyFrameIntervalKey : @(1)} }; _assetWriterVideoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoCompressionSettings]; 并没有明显的办法来控制这一点。 注:我已经尝试了不同的数字,那是1 。 我已经试过1.0/fps ,我已经尝试过fps ,我已经删除了密钥。 没有不同。 这是我如何设置AVAssetWriter: AVAssetWriter *newAssetWriter […]

CVPixelBuffer到CIImage总是返回零

我想转换从AVPlayerItemVideoOutput提取到CIImage的pixelBuffer,但总是得到零。 代码 if([videoOutput_ hasNewPixelBufferForItemTime:player_.internalPlayer.currentItem.currentTime]) { CVPixelBufferRef pixelBuffer = [videoOutput_ copyPixelBufferForItemTime:player_.internalPlayer.currentItem.currentTime itemTimeForDisplay:nil]; CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer]; // Always image === nil CIFilter *filter = [FilterCollection filterSepiaForImage:image]; image = filter.outputImage; CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgimg = [context createCGImage:image fromRect:[image extent]]; [pipLayer_ setContents:(id)CFBridgingRelease(cgimg)]; } 以下是用于创buildCIImage的pixelBuffer详细信息(总是导致为零): $0 = 0x09b48720 <CVPixelBuffer 0x9b48720 width=624 height=352 bytesPerRow=2496 pixelFormat=BGRA iosurface=0x0 […]

在自定义相机层的AVFoundation中自动对焦和自动曝光

什么是为AVFoundation自定义层摄像头创build准确的自动对焦和曝光的最佳方法是什么?例如,目前我的相机预览图层是方形的,我希望相机的焦点和曝光被指定到该帧的边界。 如果可能的话,我需要这个在Swift 2中,如果不是,请写下你的答案我将能够自己转换它。 目前的自动对焦和曝光:但你可以看到,这将在对焦时评估整个视图。 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { //Get Touch Point let Point = touches.first!.locationInView(self.capture) //Assign Auto Focus and Auto Exposour if let device = currentCameraInput { do { try! device.lockForConfiguration() if device.focusPointOfInterestSupported{ //Add Focus on Point device.focusPointOfInterest = Point device.focusMode = AVCaptureFocusMode.AutoFocus } if device.exposurePointOfInterestSupported{ //Add Exposure on Point device.exposurePointOfInterest […]

AVCaptureSession模拟器中的audio

我试图捕捉audio,使用这个问题的方法; 与AVCaptureSession和AVCaptureAudioDataOutput。 这似乎工作正常1不便:它不起作用的模拟器。 AVAudioRecorder和老的SpeakHere演示程序都可以在模拟器中正常工作,使用MacBook Pro上的内置麦克风。 问题是[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]在模拟器中给出null ,所以随后的代码将失败,并显示消息(当它尝试将null作为input添加到AVCaptureSession时): *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Can't add <AVCaptureDeviceInput: 0x9138b40 [(null)]> because the device does not support AVCaptureSessionPresetHigh. Use -[AVCaptureDevice supportsAVCaptureSessionPreset:].' 有没有一种简单的方法来获得这个在模拟器中工作?

AVPlayer / AVPlayerItem如何通知我的应用程序有关不可达的networking故障?

我正在使用AVPlayer在iOS应用程序中实现自定义video播放器。 要从networking播放video,我分配一个播放器: [[AVPlayer alloc] initWithURL:_URL]; 创build资产: AVURLAsset *asset = [AVURLAsset URLAssetWithURL:self.URL options:@{AVURLAssetPreferPreciseDurationAndTimingKey : @(YES)}]; asynchronous加载playable密钥: NSArray *keys = @[@"playable"]; [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ for (NSString *key in keys) { NSError *error; AVKeyValueStatus status = [asset statusOfValueForKey:key error:&error]; if (status == AVKeyValueStatusFailed) { NSLog(@"Failed to load asset key %@ error %@", key, [error localizedDescription]); [self […]

允许用户在迅速2.0的背景音乐

我正在寻找一些代码,以允许用户从手机播放音乐,同时仍然使用我的应用程序。 以前在swift 2.0之前,我会把这个在应用程序委托,它会完美的工作: AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil) AVAudioSession.sharedInstance().setActive(true, error: nil) 有谁知道如何在swift 2.0中实现这个?