我有一个课程将视频和音频录制到.mp4文件中。我使用php artisan migrate
,AVAssetWriter
来执行此类任务
如何在使用此类方法(AVAssetWriterInput
)录制视频时获取视频的持续时间?
答案 0 :(得分:1)
您可以在开始startSession时保存开始时间
let startTimeStamp = CMSampleBufferGetPresentationTimeStamp(sample)
fileWriter.startSession(atSourceTime: startTimeStamp)
startTime = Double(startTimeStamp.value) / Double(startTimeStamp.timescale)
比你得到的每个缓冲区都要这样做:
let currentTimeStamp = CMSampleBufferGetPresentationTimeStamp(sample)
let currentTime = Double(currentTimeStamp.value) / Double(currentTimeStamp.timescale)
print("Duration - \(currentTime - startTime)")