FAQ Database Discussion Community


iOS: error in __connection_block_invoke_2: Connection interrupted

ios,xcode,multithreading,avfoundation,avcaptureoutput
Xcode/iOS 8/AVFoundation related error in console: error in __connection_block_invoke_2: Connection interrupted I am just adding AVCaptureVideoDataOutput to Apple's sample app 'AVCamManualUsingtheManualCaptureAPI' What I added was: // CoreImage wants BGRA pixel format NSDictionary *outputSettings = @{ (id)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInteger:kCVPixelFormatType_32BGRA]}; // create and configure video data output AVCaptureVideoDataOutput *videoDataOutput = [[AVCaptureVideoDataOutput...

Dynamically including Subtitles to video files in iOS?

ios,avfoundation
In AVFoundation we can split and merge tracks of any media files. I assume a subtitle to be another track and I want to include this track based on the language the user chooses. My Idea is to include the hardcoded subtitles files as per languages I support in the...

Capture iOS microphone audio in ulaw format

ios,avfoundation,core-audio
I need to capture microphone voice input in real time and stream upstream via RTSP. The audio format needs to be in ulaw. I need to obtain the raw bytes so I can feed it to the Live 555 RTSP library. Given various stuffs in Core Audio and AV Foundation...

captureStillImageAsyncronouslyFromConnection - Cannot convert the expression's type

ios,swift,closures,avfoundation
I'm fresh to Swift so I'm still ironing out some of the finer details; I apologize if I'm missing something obvious. I've browsed around and found solutions to similar errors in different method calls, but those answers haven't helped me in figuring out my issue. I make this call captureOutput.captureStillImageAsynchronouslyFromConnection(port)...

ios 8 swift - doing stuff after displaying a view

ios,swift,avfoundation
I'm working on a app which has a button to open a view that access the camera. So, I have a button to trigger a segue (using the storyboard) and in my other view, inside viewDidLoad(), I'm doing all I need to start the video capture. The problem is that...

AVFoundation video preview is darker than the native Camera app

ios,camera,avfoundation
I am using AVFoundation to produce video frames. The problem is that the frames look darker than in the native camera app, especially in dark areas. As I see, the native camera app (iOS 8) makes some adjustments (ISO, shutter speed) all the time and continuously adopts itself to the...

Need An Explanation of Steps to Rotate AV Camera

swift,ios8,avfoundation
So I am having an issue with rotations. I have an AV Camera set up to display in a view controller. Now I know there are a lot of components that went into this, that is why I am simply saying AV Camera. My problem is, that when I rotate...

How to detect privacy permission changes (Camera access for example)

ios,avfoundation,uiimagepickercontroller,eventkit,photokit
We've all been there. You want to take photos within your app, or access photos, microphone, contacts, etc... But first iOS must prompt the user for permission. In many cases the user will deny access. If your app detects that the user has denied access, you can navigate the user...

I want to set the volume while append an audio samplebuffer to a new file with AVAssetWriter

ios,audio,avfoundation
I need to copy an audio track from an asset to append to a new file. And for some reason I need use AVAssetWriter instead of AVExportSession. So can't use AVAudioMix to do that. So can I do that with AVAssetWriter?

Changing Max Duration of Video while Recording iOS

ios,avfoundation,video-capture,avcapturesession
I am initially starting recording with a specified Maximum Time Threshold. AVCaptureMovieFileOutput* output; //initialisations, other configurations... //Here i am setting up my MaxDuration before starting recording. [output setMaxRecordedDuration:CMTimeMakeWithSeconds(MY_MAX_LENGTH, 600)]; //Starting recording here [output startRecordingToOutputFileURL:MY_FILE_URL recordingDelegate:self]; I need to change the Maximum Recording Time Threshold while recording is going on. What...

passing video frame to Core Image on osx

osx,avfoundation,core-image
Hi all you awesome coders! I've put together this thing from various helpful sources over the last couple of weeks (including a lot of posts from stackoverflow), trying to create something that will take a webcam feed and detect smiles when they occur (might as well draw boxes around the...

Crash when toggling access to Camera and Photos [duplicate]

ios,avfoundation,photosframework
This question already has an answer here: App crashed in iOS 6 when user changes Contacts access permissions 2 answers I have a collection view (standard flow layout) where the first cell is displaying a live camera feed, and the rest of the cells are displaying photos from the...

Audio equivalent of SPS and PPS when muxing Annex B MPEG-TS? What is “DecoderInfo”?

ios,audio,avfoundation,mpeg,hls
I'm using the Bento4 library to mux an Annex B TS (MPEG-2 transport stream) file with my h264 video and AAC audio streams that are being generated from VideoToolbox and AVFoundation respectively, as source data for a HLS (HTTP Live Streaming) stream. This question is not necessarily Bento4-specific: I'm trying...

can AVAudioPlayer trigger events on predefined intervals?

swift,ipad,avfoundation,avaudioplayer
I need to make views visible at fixed time while running a MP3 audio. I am using Swift. Any suggestions?

Cant Figure Out Why VideoDeviceInput Isn't Being Added To My AVCaptureSession

ios,swift,avfoundation
Everything is working just fine. Outputs are added correctly, everything is initialized correctly, camera pops up, etc. The ONLY thing that is not working is adding the video device as an input to the capture session or this camera and I cannot gather why this is happening. Maybe a different...

XPC Service and AVFoundation

osx,cocoa,opencv,avfoundation,osx-yosemite
Is it possible to use AVFoundation and OpenCV inside an XPC service? I have such a simple code #include <opencv2/opencv.hpp> #import <AVFoundation/AVFoundation.h> @interface AppDelegate(){ cv::VideoCapture m_vidCap; } ... //Hacky way of forcing OpenCV to call AVFoundation for the first time //before the camera arrives //OpenCV should add a better way...

Play sound from AppDelegate [duplicate]

ios,swift,avfoundation
This question already has an answer here: Playing back audio using AVAudioPlayer iOS 7 3 answers I'm working on an app for iPhone that uses a webview and lots of deeplinks because I'm lazy. I've configured the deeplink listening part of the app and that works great, but that...

iOS - Object recognition in images

opencv,avfoundation
This is a known area and OpenCV might well be involved, but still to start from the scratch. How has something like Evernote's scannable app been developed. I mean, how does it automatically recognize a document using a camera and then extract it. What are the UIKit frameworks involved here...

iOS Apply CATransform3D on every frame

ios,core-animation,avfoundation,calayer
I am capturing every frame of vide output and by processing it, I add a CALayer to an overlay which should be transformed according to the results from processing the frame. That CALayer basically knows how to draw an arrow. If I just add the CALayer on every frame it...

AVFoundation I use setActiveVideoMinFrameDuration didn't work

ios,avfoundation,avcapture
I use AVCaptureVideoDataOutput in my demo ,for take photos in loop (like scanner) without sound, so i set fps to low Level [device setActiveVideoMinFrameDuration:CMTimeMake(1, 1)]; [device setActiveVideoMaxFrameDuration:CMTimeMake(1, 1)]; In my code, then do this - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { NSLog(@"date"); } for check is it work, I found...

AVAssetExportSession combine video files and freeze frame between videos

ios,video,avfoundation,avassetexportsession,avmutablecomposition
I have an app which combines video files together to make a long video. There could be a delay between videos (e.g. V1 starts at t=0s and runs for 5 seconds, V1 starts at t=10s). In this case, I want the video to freeze the last frame of V1 until...

AVFoundation concatenating videos

avfoundation,avmutablecomposition
I am pulling my hair out over this. I try to concatenate videos and it just won't do what I want it to do. Specifically, I have videos that have a different orientation and I try to set it right with a Layer instruction. Alas, not matter what I try,...

iOS 8 & AVFoundation: How To Dim Background Audio?

ios,objective-c,swift,audio,avfoundation
I've googled around and looked through SO but I cannot find a solid answer on how to do something that seems very simple. Do you know how I can dim the background audio programmatically with iOS 8 and AVFoundation? My app will let users play audio (from another app) but...

Swift - AVFoundation on OS X adding sublayer issue

osx,swift,avfoundation,nsview
I am trying to get a preview of my video device in a custom view. But all I get is an empty window. I see that I have no problem accessing my camera. As soon as the app fires up i see my logitech cameras led turn on. I assume...

How to Repeat Music in Swift

swift,avfoundation,music
I would like to know how can I replay my background music forever, right now when the app loads the music begins but when it ends all is quiet, how can I make it to replay all the time. I am using AVFoundation Framework. Declaration: var BackgroundMusic = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath:...

Use long press gesture with AVFoundation to start stop recording

ios,objective-c,avfoundation,long-press
Hi I would like to start stop a recording with AVFoundation coding in Objective-C with long press gesture. I know how to start a recording and stop it with another button, but not doing it all with the same one. Thanks!...

Set AVAudioEngine Input and Output Devices

objective-c,avfoundation,avaudioengine
I've been playing around with Apple's shiny new AVFoundation library, but so far I've unable to set the input or output devices (e.g. a USB sound card) used by an AVAudioEngine, and I can't seem to find anything in the documentation to say it's even possible. Does anyone have any...

create movie from [UIImage], Swift

ios,swift,video,avfoundation
I've been scouring the internet for hours to find a Swift solution. I've found export [UIImage] as movie, but its all in ObjectiveC and I can't figure it out for Swift. I really need to create a video from [UIImage] Working on Zoul's answer from above link. part 1) Wire...

How to create grayscale CGImage from iPhone Camera?

ios,swift,core-graphics,avfoundation
I want to create grayscale CGImage from iPhones camera data. I'm using AVFoundation and set pixel format type to kCVPixelFormatType_420YpCbCr8BiPlanarFullRange If I understand correctly I should be able to create grayscale image from Y component so I have implemented delegate method like this: func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection...

Incorrect playing audio files in UITableView

ios,uitableview,swift,audio,avfoundation
I am making an app with the function of playing audio in Swift. All audio files are showed in UITableView, when I click the row an appropriate audio files must be played. The problem is that, for example, when I click the first row it doesn't play the audio, but...

Screen capture during video preview fails

ios,swift,avfoundation
I'm trying to capture the screen while doing a video preview with AVFoundation (AVCaptureDeviceInput and AVCaptureVideoDataOutput) Initiate preview: func startCamera(){ var screenSize = UIScreen.mainScreen().bounds.size; self.previewView = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height)); self.previewView.contentMode = UIViewContentMode.ScaleAspectFit self.view.addSubview(previewView); session.sessionPreset = AVCaptureSessionPresetHigh let devices =...

AVFoundation CaptureStillImage issue with orientation of result image

ios,swift,avfoundation
I have a custom camera view controller that uses AVFoundation to capture a still image which you can see here: My issue is that once I capture an image, the orientation is always sideways which you can see here My code is as follows: var captureInput: AVCaptureInput? var stillImageOutput: AVCaptureStillImageOutput?...

[AVFoundation]: Thumbnail generation hangs after some time

objective-c,image,avfoundation,video-processing,avassetimagegenerator
I have server application which serves informations about the videos on server. One of the requests is URL:PORT/video/:id/:time ... which I parse and get the video file, prepare the time and ask method to generate the thumbnail. It works for first 5 minutes really fast (generates image under 200ms), then...

Convert .caf file to normalised floating point array Objective-C/C

ios,objective-c,avfoundation
I've managed to record audio using the AVAudioRecorder in Linear PCM format which is written to disk in .caf format. Not a problem. I would now like to read the file and convert it into a normalised array of floats (i.e. each float between -1 and 1). I've tried the...

AVFoundation - Reverse an AVAsset and output video file

ios,objective-c,osx,avfoundation
I've seen this question asked a few times, but none of them seem to have any working answers. The requirement is to reverse and output a video file (not just play it in reverse) keeping the same compression, format, and frame rate as the source video. Ideally, the solution would...

Recording an iOS device's screen from an OSX cocoa app with a lightning cable

ios,osx,cocoa,avfoundation,quicktime
It's possible in Quicktime, with New Movie Recording > Camera dropdown > select iOS device. AppShow and Screenflow both do it. I've tried this Applescript tell application "QuickTime Player" set myrec to new movie recording tell myrec set current camera to video recording device named "Morten's iPod touch" end tell...

AVFoundation: prevent background music playing twice when returning to first screen

ios,swift,avfoundation
At the moment I have a home screen which plays background music using AVFoundation. If you click play the music stops (which is what I want). If you move to the instructions screen the music continues (which I want), however when you click to return to home screen the background...

File Format for Saving Video with alpha channel in iOS

ios,avfoundation,video-processing,alpha
I am using AVFoundation to create a video and have added in an effect to clip the video so there is a clear background. What file format should I save this as to preserve the transparency in my iOS app.

Unable to display thumbnail in another view controller

ios,objective-c,avfoundation,thumbnails,cgimageref
- (void)displayThumbnail { AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[self outputURL] options:nil]; AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset]; gen.appliesPreferredTrackTransform = YES; CMTime time = CMTimeMakeWithSeconds(1, 30); NSError *error = nil; CMTime actualTime; CGImageRef imageref = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error]; UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imageref]; CGImageRelease(imageref); UIStoryboard *mainStoryboard =...

requestAccessForMediaType doesn't ask for permission

swift,avfoundation,grand-central-dispatch
I noticed that my app doesn't request permission to use the camera. After some experimentation I figured out that the piece of code used to check permission takes a very long time to complete. So I thought of letting that part of my viewdidload run on a serial queue (sync)....

How to Play Audio in Background Swift?

ios,swift,audio,avfoundation
as you see I'm streaming something. But when I press the home button and exit the app streaming stops or I cannot hear. How can I continue streaming in background and listen it from lock screen? ViewController.Swift import UIKit import AVFoundation import MediaPlayer import GoogleMobileAds class ViewController: UIViewController, GADInterstitialDelegate {...

Playing CMSampleBufferRef's with AVPlayer

ios,osx,avfoundation,avplayer
I am working on an OSX video editing app and have a set of CMSampleBufferRef's in an array representing each frame of the video. I want to render a preview of the video using AVPlayer - is it possible feed in these samples directly into AVPlayer? I've looked at most...

Preventing AVCaptureVideoPreviewLayer from rotating, but allow UI layer to rotate with orientation

ios,swift,avfoundation,avcapturesession,avcapturedevice
I have a two view controllers. One is the root VC and contains my UI interface such as the record button. On this view controller, I also display the view of another VC at index 0. This view contains a AVCaptureVideoPreviewLayer. I would like my video camera to mimic the...

mp4 video starts at different time on Quicktime/AVplayer vs Chrome/Firefox

video,avfoundation,mp4,avplayer,quicktime
I have a very strange issue. My OSX app is generating an mp4 video based on a screen cast. For some reason, if I open this video in Quicktime or any OSX-based AVPlayer, it will start about 14-15 frames in advance of frame 0. If I open the mp4 with...

How to focus the near by objects in iOS 8?

ios,iphone,ios8,avfoundation
I'm developing a QR code reader. My Codes are 1cm long and width. I'm using AVFoundation metadata to capture the machine readable codes and it works fine. But at the same time i need to take a picture of the QR code with the logo (Which is located in mid...

AVFoundation: toggle camera fails at CanAddInput

ios,swift,camera,toggle,avfoundation
I am trying to add a rotate camera function with AVFoundation to allow the user to toggle between the front-facing and back-facing cameras. As shown in the code below, I've put in some println() statements and all the values seem legit but the code always drops to the failed else-clause...

Why would AVPlayerItem not honor AVAudioTimePitchAlgorithmVarispeed setting?

cocoa,avfoundation,avplayer,avplayeritem
I am trying to change the audio pitch of an AVPlayerItem depending on the rate I send to an AVPlayer. To do this, I am initializing an AVPlayerItem with an AVAsset specifying the 'AVAudioTimePitchAlgorithmVarispeed', like such: AVPlayerItem *nPlayerItem = [AVPlayerItem playerItemWithAsset:asset]; [nPlayerItem setAudioTimePitchAlgorithm:AVAudioTimePitchAlgorithmVarispeed]; I then attach the playerItem to an...

AVMutableComposition missing frames recorder with difference cameras of iPad

ios,camera,avfoundation,avmutablecomposition
I use the well known PBJVision to record videos which then must be combined together. I use AVMutableComposition to combine videos using insertTimeRange(_:ofAsset:atTime:error:). It works well if the videos have been taken with the same camera. But for example if one is taken with back camera then take another using...

AVCaptureOutput didOutputSampleBuffer stops getting called

ios,objective-c,avfoundation,avcapturesession
I have an issue with the delegate method didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection of AVCaptureOutput. It stops getting called within a second or two when I'm adding the sampleBuffer to a CFArray. If I remove the CFArray code, the delegate method continues to get called so I have no idea why the...

No known class method for selector 'URLAssetWithURL'

ios,objective-c,avfoundation,nsurl,avurlasset
I have an iOS app which uses a lot of different audio files recorded in the app and saved. I have imported AVFoundation framework, however I still get the error: No known class method for selector 'URLAssetWithURL' Here is my code: AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:audioFiles[indexPath.row]]]; waveformView.asset = asset;...

Make a playlist (start next song) in swift

ios,swift,avfoundation,avaudioplayer,playlist
I have created a sound player in swift with AVFoundation. I am trying to start the next song in array when the playing song is finished. I was trying to implement this code if (audioPlayer.currentTime >= audioPlayer.duration){ var recentSong = songPlaylist[selectedSongNumber + 1] audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(recentSong, ofType: "mp3")!),...

xcode - AUiPodEQ AUGraph

xcode,avfoundation,core-audio,equalizer
I'm developing a music application for iOS using the AVAudioplayer, in which I want to implement an equalizer. I searched the internet for a good solution, and ended up with and AUGraph configuration like this: // multichannel mixer unit AudioComponentDescription mixer_desc; mixer_desc.componentType = kAudioUnitType_Mixer; mixer_desc.componentSubType = kAudioUnitSubType_MultiChannelMixer; mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple;...

How to crop video from top?

ios,iphone,avfoundation
I am trying to create square video and for that I am using 640*480 camera view but not able to crop video from top? I have tried many thing but no success. so please suggest how to do it, What transform is helpful?

A Bit of Confusion With AVFoundation

ios,swift,ios8,avfoundation
So I have been working with AVFoundation for a few weeks now, what a pain! I have gotten to the point in my camera application where I am trying to save a video being recorded to the photo albums. I have looked around here on google and as it is...

How to have current [indexPath.row +1]?

ios,streaming,avfoundation,spotify,music-player
I'm building a Spotify iOS SDK music client and am stuck at how to get it to play the next track. The SDK comes with a SPTAudioStreamingPlayer takes in the URI of a track. I have an array of Spotify SPTSavedTracks and would like to be able queue/skip to next...

AVPlayer not working with AirPlay

ios,avfoundation,avplayer,airplay,avmutablecomposition
I have a sequence of AVMutableCompositions that I am playing with AVPlayer. Everything works great when I am playing via speaker, headphones, or bluetooth. However, as soon as I connect to AirPlay, everything falls apart. I can play one asset, and I try to switch to a new asset, I...

Swift record video using same method as taking photo

ios,swift,avfoundation
I'm currently using the following code to allow users to take photos: private func configurePhotoView() { capturedPhoto.contentMode = .ScaleAspectFill capturedPhoto.clipsToBounds = true capturedPhoto.hidden = true captureSession = AVCaptureSession() captureSession!.sessionPreset = AVCaptureSessionPresetPhoto photoCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) var error: NSError? photoDeviceInput = AVCaptureDeviceInput(device: photoCaptureDevice, error: &error) if error == nil &&...

Getting YUV from CMSampleBufferRef for video streaming

ios,objective-c,video,video-streaming,avfoundation
I am building an iOS video streaming chat application and the library I am working with requires that I send the video data passing it the YUV (or I guess YCbCr) data individually. I have the delegate set up, but I'm not sure how to extra the individual YUV elements...

'Cannot Decode' error when trying to save file using AVAssetExportSession when using Xamarin

monotouch,xamarin,avfoundation,avassetexportsession
I ported this example: of overlaping video to Xamarin. When i use this AVMutableComposition in AVPlayer i can watch edited video. But when i try to save it using AVAssetExportSession i always get 'Cannot Decode' error. I tried every preset and every file type and it doesn't help. I also...

Apply Core Image Filter to Video on OS X using Swift

swift,cocoa,avfoundation,core-image,core-video
I am planning to build an NSOpenGLView for an OS X app using SWIFT which can be used to apply Core Image Filter and effects to a video, so far I have worked on the code for the video Controller to add video playback, but I am not sure how...

How to crop a video to a circle in iOS?

ios,avfoundation,crop,video-processing
I am trying to crop an already taken video into a circle in iOS. How might I go about doing this. I know how I would do it with AVCaptureSession but I don't know to pass in an already taken video as an AVCaptureDevice? Is there a way to crop...