Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

ios - 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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...