Split CMSampleBufferRef containing Audio

大兔子大兔子 提交于 2019-12-03 22:25:03

问题


I'am splitting the recording into different files while recording...

The problem is, captureOutput video and audio sample buffers doesn't correspond 1:1 (which is logical)

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

AUDIO START: 36796.833236847        | DURATION: 0.02321995464852608         | END: 36796.856456802
VIDEO START: 36796.842089239        | DURATION: nan         | END: nan
AUDIO START: 36796.856456805        | DURATION: 0.02321995464852608         | END: 36796.87967676
AUDIO START: 36796.879676764        | DURATION: 0.02321995464852608         | END: 36796.902896719
VIDEO START: 36796.875447239        | DURATION: nan         | END: nan
...

so i need to split the audio CMSampleBufferRef based on time and use the first segment for the first video and the second part of the buffer for the second video

It is possible to do things also with AVMutableComposition and AVAssetExportSession while exporting but the question is about the buffer level in captureOutput:, so the recorder file doesn't need more processing


Update:

Looks like 3 options, not successfully implemented yet

1) CMSampleBufferCopySampleBufferForRange

looks like CMSampleBufferCopySampleBufferForRange is the way to go, but i'am struggling to compute the last argument sampleRange...

2) CMSampleBufferCreateCopyWithNewTiming

quite lost using this one

3) looks like there is a way to trim the buffer by providing kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMSampleBufferAttachmentKey_TrimDurationAtEnd using the CMSetAttachment

来源:https://stackoverflow.com/questions/43322157/split-cmsamplebufferref-containing-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!