Create an application that creates video from the iphone screen and adds sound from headphones / audio input

I am trying to create a training video from the ipad screen as it is done in this application (ShowME) Using AVAssetWriter I can capture the screen video.

I tried to use AVCaptureDevice but did not work. I do not know what is going wrong. I learned how to capture iphone screen video from this link - A very beautiful tour. But it does not capture the sound with the video image. So I tried 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 a delegate method

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

It is never called. Hope someone can help me with this. I have never used AVFoundation for video and audio purposes, so this may be a beginner's question. I read other posts regarding this, and found that merging audio with video. I think we can go this way. Please tell me if this is not possible.

Thank you in advance:)

+4
source share
1 answer

I finally record audio as another file and then combine them to create video with audio and video. I used AVMutableComposition to create the final video. If someone knows how to record it using assets when creating a video using AVAssetWriter, then please help me. I can change my code :)

+2
source

Source: https://habr.com/ru/post/1384472/


All Articles