0

I am using to record live video on iOS using AVAssetWriter as demonstrated in RosyWriter. The problem I have is if I set AVAudioSession preferredSampleRate to 48000 Hz, it gives lot of troubles such as audio out of sync with video. Is there a way to use the default sample rate(44100 Hz)on AVAudioSession but when recording with AVAssetWriter use 48000 Hz without causing any sync issues?

EDIT : I found the problem is the number of frames returned in render callback of RIO unit multiplied by 1/48000 is NOT equal to ioduration of AVAudioSession. This is not the case otherwise with 44100 KHz.I rely on this code for timing. This is the cause for out of sync audio with video.

    CMSampleTimingInfo timing = { CMTimeMake(1, sampleRate), presentationTime, kCMTimeInvalid };

        OSStatus error = CMSampleBufferCreate(kCFAllocatorDefault, NULL, false, NULL, NULL, controller->mFormatDesc, inNumberOfFrames, 1, &timing, 0, NULL, &buff);


        CMSampleBufferSetDataBufferFromAudioBufferList(buff, kCFAllocatorDefault, kCFAllocatorDefault, 0, audioBufferList);
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

0 Answers0