How to set timestamp of CMSampleBuffer for AVWriter writing

前端 未结 2 1612
心在旅途
心在旅途 2021-02-06 03:08

I\'m working with AVFoundation for capturing and recording audio. There are some issues I don\'t quite understand.

Basically I want to capture audio from AVCaptureSessio

2条回答
  •  野的像风
    2021-02-06 03:28

    Chunk of sample code from here: http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html CMSampleBufferRef sample - is your sampleBuffer, CMSampleBufferRef sout your output. NewTimeStamp is your time stamp.

    CMItemCount count;
    CMTime newTimeStamp = CMTimeMake(YOURTIME_GOES_HERE);
    CMSampleBufferGetSampleTimingInfoArray(sample, 0, nil, &count);
    CMSampleTimingInfo* pInfo = malloc(sizeof(CMSampleTimingInfo) * count);
    CMSampleBufferGetSampleTimingInfoArray(sample, count, pInfo, &count);
    for (CMItemCount i = 0; i < count; i++)
    {
        pInfo[i].decodeTimeStamp = newTimeStamp; // kCMTimeInvalid if in sequence
        pInfo[i].presentationTimeStamp = newTimeStamp;
    
    }
    CMSampleBufferRef sout;
    CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, sample, count, pInfo, &sout);
    free(pInfo);
    

提交回复
热议问题