Tag: avfoundation

为什么AVAssetImageGenerator generateCGImagesAsynchronouslyForTimes崩溃了应用程序

我想使用generateCGImagesAsynchronouslyForTimes从video中提取每秒2帧。 但我的应用程序崩溃。 我正在监视内存使用情况,但不超过14 MB。 这里是代码: – (void) createImagesFromVideoURL:(NSURL *) videoUrl atFPS: (int) reqiuredFPS completionBlock: (void(^) (NSMutableArray *frames, CGSize frameSize)) block { NSMutableArray *requiredFrames = [[NSMutableArray alloc] init]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoUrl options:nil]; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; generator.requestedTimeToleranceAfter = kCMTimeZero; generator.requestedTimeToleranceBefore = kCMTimeZero; generator.appliesPreferredTrackTransform = YES; UIImage *sampleGeneratedImage; for (Float64 i = […]

AVAssetExportSession – 在IOS中join2个mp4文件

我试图用以下代码将2个预先存在的mpeg4video连接到一个ipad2上。 -(void)mergeTestVideos { //setup asset NSString *firstassetpath = [NSString stringWithFormat:@"%@mpeg4-1.mp4", NSTemporaryDirectory()]; NSString *secondassetpath = [NSString stringWithFormat:@"%@mpeg4-2.mp4", NSTemporaryDirectory()]; NSFileManager *fileManager = [NSFileManager defaultManager]; AVAsset *firstAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:firstassetpath]]; AVAsset *secondAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:secondassetpath]]; NSLog(@"FirstAsset Is Readable = %d", firstAsset.isReadable); NSLog(@"FirstAsset Is playable = %d", firstAsset.isPlayable); NSLog(@"FirstAsset Is exportable = %d", firstAsset.exportable); NSLog(@"SecondAsset Is Readable […]

IOS 8电影从后面和前面照相机

如何在iOS 8或甚至iOS 7上录制(如果可能),并在相机之间切换? 我已经看到应用程序从前置摄像头进行录制,然后切换到后置摄像头,当电影完成时,您可以从两个摄像头完全看到它的拍摄? 我觉得Glide应用程序有它,也许Snapchat(不知道最后一个)

使用AVCaptureSession录制video时,音乐应用程序(在后台播放)会中断

我正在开发像应用程序一样的function。 在我的应用程序中,音乐应用程序在后台运行,我的应用程序处于前台状态。 我必须同时在后台运行音乐应用程序捕捉video。 问题: – 当我的应用程序进入前台状态,音乐应用程序audio暂停一秒钟,然后继续。 同样的问题出现时,用户点击HOMEbutton,应用程序进入后台状态和音乐应用程序audiorest一秒钟。 我已经下载了用于录制的苹果示例代码https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112 下载后,在AppDelegate中完成了以下更改 在AppDelegate.h中 导入AVFoundation @property(nonatomic,retain)AVAudioSession * session1; 在AppDelegate.m中 self.session1 = [AVAudioSession sharedInstance]; [self.session1 setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:nil]; [self.session1 setActive:YES error:nil]; // Inform the device that we want to use the device orientation. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 在AAPLCameraViewController.m中 两个属性已被添加 self.session.usesApplicationAudioSession = TRUE; self.session.automaticallyConfiguresApplicationAudioSession = FALSE; 其他方式 我已经尝试使用SCRecorder库,但同样的问题是与该库。 […]

drawRect不想绘制任何东西

我有一个故事板上的ViewController。 我已经使用界面生成器在屏幕底部设置了一个工具栏。 我已经将自定义视图设置为一个视图覆盖drawRect。 但是,在我的生活中,我从来没有得到任何东西在屏幕上显示,从drawRect调用。 drawRect本身被称为很好,但没有任何显示在屏幕上。 此外,我有这个ViewController的方法,使用AVCaptureSession切换到相机input实时视图的背景。 我怀疑这可能是错误的原因,但删除AVCaptureSession的所有引用后,我仍然无法得到这个工作。 对不起,我的写作和/或缺乏逻辑,我现在没有任何睡眠。 编辑:这是一个不能工作的小例子。 里面的每个方法都被调用,但是没有什么是显示的。 – (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); // Draw them with a 2.0 stroke width so they are a bit more visible. CGContextSetLineWidth(context, 2.0); CGContextMoveToPoint(context, 0,0); //start at this point CGContextAddLineToPoint(context, 100, 100); //draw to this point // and now […]

如何使用AVAssetWriter将静态和dynamic叠加添加到video?

什么是正确的方式来添加一个图像叠加到AVAssetWriter创build的video? 有可能用AVAssetExportSession这样做,但是这个问题是关于如何用AVAssetWriter这样做的,所以对质量和输出有更多的控制。 有两种情况: 1)简单:在video的整个持续时间内添加单个叠加(类似于水印)。 2)复杂:添加不同的覆盖,在不同的时间进出video(类似于使用AVVideoCompositionCoreAnimationTool)。

如何将任何颜色的色度键filter应用于相机馈送ios?

基本上我想将色度键filter应用于ios实时摄像头,但我希望用户select将被另一种颜色replace的颜色。 我发现一些使用绿色屏幕的例子,但我不知道如何dynamicreplace颜色,而不是只是绿色。 任何想法如何才能达到最佳性能?

captureOutput中的iOS应用程序相机方向

首先,我知道很多人都问过类似的问题 – 但我找不到任何类似的问题。 当调用这个接口时: – (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); // get buffer dimensions size_t bufferHeight = CVPixelBufferGetHeight(pixelBuffer); size_t bufferWidth = CVPixelBufferGetWidth(pixelBuffer); … 当手机处于“肖像模式”时 ,我得到480的高度和640的宽度。 奇怪的是,当我检查[connection videoOrientation]它被正确设置为肖像。 为什么连接方向不会影响采样缓冲区? 我应该自己旋转图像吗? 有没有一种方法来configuration设备方向的样品? 谢谢 @ Gabriel:我已经有这个代码: -(void) viewWillLayoutSubviews { // Handle camera if (_videoPreviewLayer) { _videoPreviewLayer.frame = self.view.bounds; for (AVCaptureOutput* […]

如何在转换为video的同时对图像进行animation处理

我想平滑地将图像制作成animation,同时将它们转换为video。 尽pipe如此,我无法理解如何实现它。 我试图改变旋转angular度(CGAffineTransformRotation),翻译和缩放,但没有find一种方法来平滑的animation。 inheritance人如何将照片数组转换为video: – (void)createVideoWithArrayImages:(NSMutableArray*)images size:(CGSize)size time:(float)time output:(NSURL*)output { //getting a random path NSError *error; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:output fileType:AVFileTypeMPEG4 error: &error]; NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey, [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil]; AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput: videoWriterInput sourcePixelBufferAttributes:nil]; videoWriterInput.expectsMediaDataInRealTime = YES; […]

AVFoundation覆盖另一个video上的alpha通道video?

我试图覆盖一个video资产的图像,也想到应该有一种方式来覆盖另一个video上的alpha通道video。 有什么方法可以在另一个video资源上叠加Alpha通道video吗?