Record a video while playing another video

I use UIImagePickerControllerto record videos. and I use AVPlayerto play the video. and adding AVPlayerLayerin UIImagePickerController's cameraOverlayViewso that I can see the video while recording. My requirement

  • I need to watch a video while recording a video using UIImagePickerController
  • using a headset I need to listen to audio from video playback.
  • I need to record my voice to record a video.
  • only my voice should be recorded, but no video played.

everything works, but 4. the sound from playing the video also mixes with my voice. how to handle this business? My ultimate goal is

  • Output for video playback - headset.
  • The input for recording is the headset microphone.

Please help me do this.

+4
2

. , ? , AVAudioSessionCategoryPlayAndRecord.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

UIImagePickerController , . , .

, AVCaptureSession . , record-video-with-avcapturesession-2.

UPDATE: VOIP AVAudioUnit . , - , AVComposition . AVCaptureSession EZAudio . EZAudio AVAudioUnit , . , , . ,

UPDATE: , , . :

    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"videoviewdemo" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:moviePath];
    // You may find a test stream at <http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8>.
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];

    AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
    AVPlayerLayer *layer = [[AVPlayerLayer alloc] init];
    [layer setPlayer:player];
    [layer setFrame:CGRectMake(0, 0, 100, 100)];
    [self.view.layer addSublayer:layer];

    [player play];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //
        // Setup the AVAudioSession. EZMicrophone will not work properly on iOS
        // if you don't do this!
        //
        AVAudioSession *session = [AVAudioSession sharedInstance];
        NSError *error;
        [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
        if (error)
        {
            NSLog(@"Error setting up audio session category: %@", error.localizedDescription);
        }
        [session setActive:YES error:&error];
        if (error)
        {
            NSLog(@"Error setting up audio session active: %@", error.localizedDescription);
        }

        //
        // Customizing the audio plot look
        //
        // Background color
        self.audioPlot.backgroundColor = [UIColor colorWithRed:0.984 green:0.471 blue:0.525 alpha:1.0];

        // Waveform color
        self.audioPlot.color = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

        // Plot type
        self.audioPlot.plotType = EZPlotTypeBuffer;

        //
        // Create the microphone
        //
        self.microphone = [EZMicrophone microphoneWithDelegate:self];

        //
        // Set up the microphone input UIPickerView items to select
        // between different microphone inputs. Here what we're doing behind the hood
        // is enumerating the available inputs provided by the AVAudioSession.
        //
        self.inputs = [EZAudioDevice inputDevices];
        self.microphoneInputPickerView.dataSource = self;
        self.microphoneInputPickerView.delegate = self;

        //
        // Start the microphone
        //
        [self.microphone startFetchingAudio];
        self.microphoneTextLabel.text = @"Microphone On";

        [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
    });
+3

PBJVision. , , , .

0

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


All Articles