简体   繁体   中英

Create an application that creates a video from iphone screen and add audio from headphones / audio input

I m trying to create a tutorial video from ipad screen as done in this application (ShowME) Using AVAssetWriter I am able to capture a video of the screen.

I tried using AVCaptureDevice, but Its not working. I dont know what is going wrong. I learned capturing video from iphone screen from this link - A very nice turorial. But it does not captures any audio along with screen video. So I gave a try like this:

 -(void)setUpMike{
    NSError* error = nil;
// Setup the audio input
AVCaptureDevice *audioDevice     = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ];     
// Setup the audio output
_audioOutput = [[AVCaptureAudioDataOutput alloc] init];

// Create the session
_capSession = [[AVCaptureSession alloc] init];

[_capSession addInput:audioInput];

[_capSession addOutput:_audioOutput];

_capSession.sessionPreset = AVCaptureSessionPresetLow;     

// Setup the queue
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
//    [_videoOutput setSampleBufferDelegate:self queue:queue];
[_audioOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
}

I added the delegate method

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection

This is never called. Hope any one can help me around for this. I have never used AVFoundation for video and audio purpose, So may be a newbie Question. I read other posts relating this and found that the are merging audio with video. I think we can go through this way. Please inform me if this is not possible.

Thanks in advance :)

I finally recorder audio as different file and then merged them to create a video with audio and video. I used AVMutableComposition to create a final video. If any one know how to record it with assets as you are creating video with AVAssetWriter, then please help me out. I might change my code :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM