Tag: avfoundation

合并video(AVFoundation)

在我的应用程序中,我录制了一些小video,并将它们添加到NSMutableArray作为AVAsset以便logging所捕获的内容。 当用户按下一个button合并它们时,最后的结果只是第一个录制的video(例如,如果拍摄三个短video,合并后的最终结果只是第一个video,其他video不会出现)。 我的代码迭代在NSMutableArray和拼接video在这里: if (self.capturedVideos.count != 0) { //Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack. AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init]; for (AVAsset *asset in self.capturedVideos) { //check if the video is the first one captures so that it is placed at time 0. if ([self.capturedVideos indexOfObject:asset] == 0) { AVMutableCompositionTrack *firstTrack = […]

使用AVCaptureStillImageOutput有什么办法来缩短镜头间的时间吗?

我目前使用下面的代码拍摄一系列图像: – (void)shootSeries:(int)photos { if(photos == 0) { [self mergeImages]; } else { [output captureStillImageAsynchronouslyFromConnection:connection completionHandler: ^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { NSLog(@"Shot picture %d.", 7 – photos); [self shootSeries:(photos – 1)]; CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageDataSampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); int dataSize = CVPixelBufferGetDataSize(pixelBuffer); CFDataRef data = CFDataCreate(NULL, (const UInt8 *)CVPixelBufferGetBaseAddress(pixelBuffer), dataSize); CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data); […]

当ViewController加载时,UISlider的AVPlayer currentTime更新

我正在播放AVPlayer歌曲。 我为我的媒体播放器和初始化创build了一个独立的视图控制器,并且我为播放器使用的所有方法(播放,暂停,重复,随机播放)都在同一个视图控制器中。 我更新像这样的滑块 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(sliderUpdate:) userInfo:nil repeats:YES];` – (void) sliderUpdate:(id) sender{ int currentTime = (int)((song.player.currentTime.value)/song.player.currentTime.timescale); slider.value=currentTime; NSLog(@"%i",currentTime); song.currentTime=currentTime; int currentPoint=(int)((song.player.currentTime.value)/song.player.currentTime.timescale); int pointMins=(int)(currentPoint/60); int pointSec=(int)(currentPoint%60); NSString *strMinlabel=[NSString stringWithFormat:@"%02d:%02d",pointMins,pointSec]; lblSlidermin.text=strMinlabel; song.strslidermin=strMinlabel; } 一旦我走出视图控制器,当再来,歌曲播放,但问题是滑块不更新。 所以我创build了一个单独的类来分配当前播放的歌曲细节。 同样在滑块内部更新我为singleton类variables赋值playerCurrentTime(slidercurrent值)。 而我的viewdidload方法我这样分配 if (song.isPlaying==NO) { [self prePlaySong]; }else{ lblAlbum.text=song.currentAlbum; lblArtist.text=song.currentArtist; lblSong.text=song.currentSong; slider.value=song.currentTime; slider.maximumValue=song.sliderMax; slider.minimumValue=song.sliderMin; imgSong.image=song.songImage; [btnMiddle setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; } 但滑块没有得到更新。 […]

UIImage方向Swift

我已经编写了这个代码来使用Swift中的AVFoundation库来捕获图像: @IBAction func cameraButtonWasPressed(sender: AnyObject) { if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo){ stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection){ (imageSampleBuffer : CMSampleBuffer!, _) in let imageDataJpeg = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer) var pickedImage: UIImage = UIImage(data: imageDataJpeg)! let library = ALAssetsLibrary() library.writeImageToSavedPhotosAlbum(pickedImage.CGImage, metadata:nil, completionBlock:nil) } } } 它工作正常,但是当我去照片库图像显示逆时针旋转90度。 有人可以给我一个暗示,在哪里挖来解决这个问题?

是否有可能在捕获的图像中添加自己的元数据在Swift中

我对Swift和Ios编程非常陌生。 如上所述,我喜欢将我自己的元数据插入捕获的图像,然后将其保存到相册中。 我试图用这个代码完成这个。 保存的图像不包含我自己的元数据,但包含其生成的元数据。 任何人都可以告诉我我做错了什么? 或者,也许是不可能添加自己的新的元数据表捕获的图像? 非常感谢你的帮助 @IBAction func btnPressed(sender: UIButton) { capturePicture() } func capturePicture(){ stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG] session.addOutput(stillImageOutput) if let connection = self.stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) { self.stillImageOutput.captureStillImageAsynchronouslyFromConnection(connection) { (imageDataSampleBuffer, error) -> Void in if error == nil { var asset = ALAssetsLibrary() let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) // The Metadata of the Image var metadata:NSDictionary […]

iOS – AVAssestExportSession只能在播放AVPlayer后导出最多8首曲目

我试图循环录制的video的一些片段,并将它们合并成一个video。 我已经成功合并和导出了一个多达16首曲目的作品。 但是当我在合并之前尝试使用AVPlayer播放这个作品时,我最多只能导出8首曲目。 首先,我创buildAVComposition和AVVideoComposition +(void)previewUserClipDanceWithAudio:(NSURL*)videoURL audioURL:(NSURL*)audioFile loop:(NSArray*)loopTime slowMotion:(NSArray*)slowFactor showInViewController:(UIViewController*)viewController completion:(void(^)(BOOL success, AVVideoComposition* videoComposition, AVComposition* composition))completion{ AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init]; NSMutableArray *arrayInstruction = [[NSMutableArray alloc] init]; AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; AVURLAsset *audioAsset = [[AVURLAsset alloc]initWithURL:audioFile options:nil]; //NSLog(@"audio File %@",audioFile); CMTime duration = kCMTimeZero; AVAsset *currentAsset = [AVAsset assetWithURL:videoURL]; BOOL isCurrentAssetPortrait = YES; for(NSInteger […]

核心图像 – 在CMSampleBufferRef上渲染一个透明的图像会导致它周围的黑框

我正在使用AVFoundation的AVCaptureVideoDataOutput录制的video上添加水印/徽标。 我的类被设置为sampleBufferDelegate并接收CMSamplebufferRefs。 我已经将某些效果应用于CMSampleBufferRefs CVPixelBuffer,并将其传回给AVAssetWriter。 左上angular的徽标使用透明PNG提供。 我遇到的问题是,一旦写入video,UIImage的透明部分是黑色的。 任何人都知道我做错了什么或可能会忘记? 下面的代码片段: //somewhere in the init of the class; _eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; _ciContext = [CIContext contextWithEAGLContext:_eaglContext options: @{ kCIContextWorkingColorSpace : [NSNull null] }]; //samplebufferdelegate method: – (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); …. UIImage *logoImage = [UIImage imageNamed:@"logo.png"]; CIImage *renderImage […]

以OpenCV Mat格式从相机捕捉静止图像

我正在开发一个iOS应用程序,并尝试使用捕获会话从相机获取静态图像快照,但是我无法将其成功转换为OpenCV Mat。 静止图像输出是使用此代码创build的: – (void)createStillImageOutput; { // setup still image output with jpeg codec self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; [self.stillImageOutput setOutputSettings:outputSettings]; [self.captureSession addOutput:self.stillImageOutput]; for (AVCaptureConnection *connection in self.stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([port.mediaType isEqual:AVMediaTypeVideo]) { self.videoCaptureConnection = connection; break; } } if (self.videoCaptureConnection) […]

我如何指定AVAudioEngine Mic-Input的格式?

我想用AVAudioEngine和用户麦克风录制一些audio。 我已经有一个工作示例,但只是无法弄清楚如何指定我想要的输出格式… 我的要求是,我需要AVAudioPCMBuffer因为我现在正在说话… 我需要添加一个单独的节点,做一些转码? 我找不到有关这个问题的很多文档/样本。 而Audio-Stuff也是一个小菜鸟。 我知道我希望NSData包含PCM-16bit最高采样率16000(8000会更好) 这是我的工作示例: private var audioEngine = AVAudioEngine() func startRecording() { let format = audioEngine.inputNode!.inputFormatForBus(bus) audioEngine.inputNode!.installTapOnBus(bus, bufferSize: 1024, format: format) { (buffer: AVAudioPCMBuffer, time:AVAudioTime) -> Void in let audioFormat = PCMBuffer.format print("\(audioFormat)") } audioEngine.prepare() do { try audioEngine.start() } catch { /* Imagine some super awesome error handling here */ […]

AV基础相机预览图层放大,如何缩小?

目前我正在使用的应用程序有一个主要function,使用Zxing库( http://code.google.com/p/zxing/ )连续扫描QR /条码。 对于连续的帧捕获,我用来初始化AVCaptureSession和AVCaptureVideoOutput,AVCaptureVideoPreviewLayer中描述的苹果Q&A http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html 。 我的问题是,当我用来运行相机预览时,通过video设备可以看到的图像比通过iPhone的静态相机可以看到的图像大1.5倍。 我们的客户在扫描时需要将iPhone与条码保持5厘米左右的距离,但是如果将iPhone保持为该参数,整个QR码将不可见并且解码失败。 为什么iPhone 4中的摄像机放大图像(通过查看AVCaptureVideoPreviewLayer)?