AVFoundation: How to write video to file in real time instead of using exportAsync? - swift

AVFoundation has been quite a struggle for me because most of the examples and documentation out there are in Obj-c.. As my title states, I would like to write to file in real time instead of calling exportAsync once the user has finished recording their video.
If anyone can offer some advice or documentation on how to do this it would be greatly appreciated!

It's not clear where your video is coming from, butexportAsync makes it sound like you're using AVAssetExportSession with an existing file or composition.
capture your video (and audio?) frames
a. if from an existing composition or file, with AVAssetReader
b. if from the camera, with AVCaptureSession etc
progressively write the frames to file using AVAssetWriter & AVAssetWriterInput
If you're expecting the writing to file to be interrupted for some reason,
consider setting the AVAssetWriter's movieFragmentInterval property to something small .

Related

iOS Capturing Video

I want to make an app for the iPhone with the ability to record video. One thing I want to do with the video once it's recorded, is to take the audio from it and alter it, such as make it sound feminine or masculine etc. I've never done this before but is it better to use AVFoundation or UIImagePickerController. I've read that the UIImagePickerController is easier to use but will it allow be to extract and edit the audio of the recorded video and put it back in?
Any help or suggestions as to how to approach this are appreciated.
Thanks
It is easiest to capture with UIImagePickerController if you do not need to alter it live. Once the video is captured and you have altered the audio track somehow, write it again using AVFoundation's AVMutableComposition and an audio mix.

Playing a movie file and then various audio files while movie is playing back. (iOS)

Is it possible to play some audio files while my movie is playing. I don't want it to interrupt or pause he movie. Just the audio to play at same time at various predetermined points.
Many Thanks,
-Code
You shouldn't have any problems with it.
If you want to synchronize or delay these players you should use
the code they provide in AvAudioPlayer Class Reference using
playAtTime: method.
Sadly MPMediaPlayback protocol doesn't provide the same method
so exact synchronizing with video is a bit harder task.
EDIT: RoLYroLLs mentions using MPMoviePlayerLoadStateDidChangeNotification to achieve this here and this approach seems promising.
Use two or three Audioplayer at same time . Play that audio when u need it

Recording Audio and Video using AVFoundation frame by frame

How to record audio and video using AVFoundation frame by frame in iOS4?
The AVCamDemo you mention is close to what you need to do and should be able to use that as reference, among those these are the following classes you need to use in order to achive what you are trying... All the classes are part of AVFoundation, you need
AVCaptureVideoDataOutput and AVCaptutureAudioDataOutput - use these classes to get raw samples from the video camera and the microphone
Use AVAssetWriter and AVAssetWriterInput in order to encode the raw samples into a file - the following sample mac OS X project shows how to use these classes (the sample should work for ios too), however they use an AVAssetReader for input (it reencodes a movie file) instead of the Camera and microphone... You can use the outputs mentioned above as the input in your case to write what you want
That should be all you need in order to achieve what you want to do...
Heres a link showing how to use VideoDataOutput
Hope it helps
If you are a registered developer, look at the videos from the 2011 WWDC (which you can find by searching in the developer portal). There are two sessions relating to AVFoundation. There was also some sample code from one of the WWDC sessions, which was extremely useful.

Converting a sample rate of audio file iPhone

I'd like to change the pitch of an audio file by changing the sample rate programmatically. I am recording the file using AVAudioRecorder. I have noticed a settings parameter within AVAudioPlayer, however, it is read only. Can anyone lend a helping hand? :)
You could manipulate the data the recording process returns, this is generally the way to go for DSP.
A simple change in sound's speed can be done with a resampling.
Take a look here

Play audio and video at a same time in iPhone application

Is it possible to play audio and video file at a same time? I want to play different audio file and video file at a same time and also want control for both, so is it possible?
Sorry, not that I know of. The movie view automatically stops all audio files and takes up the whole screen, so you are forced to listen to the audio for the video.
If the audio is part of the video file, yes.
If it's an MP3 file or some other external type how are you planning on playing it? The phone might allow this to happen depending on what you're up too.
You might be in luck soon though...
Another helpful link is here.