Is it possible to find IDR frame (CMSampleBuffer) in AVAsset h264 video file?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm doing random access sampling from AVAsset of local h264 video file
let track = asset.tracks(withMediaType: .video)[0]
let assetReader = try! AVAssetReader(asset: asset)
let trackOutput = AVAssetReaderTrackOutput(track: track, outputSettings: nil)
trackOutput.supportsRandomAccess = true
assetReader.add(trackOutput)
assetReader.startReading()
...
let targetFrameDTS = CMTime(value: 56, timescale: 30)
let timeRange = CMTimeRange(
start: CMTimeAdd(time, CMTime(value: -1, timescale: 30)),
duration: CMTime(value: 2, timescale: 30)
)
// reset output to be near target frame decoding time
trackOutput.reset(forReadingTimeRanges: [NSValue(timeRange: timeRange)])
while assetReader.status == .reading {
guard let sample = trackOutput.copyNextSampleBuffer() else { break }
let dts = CMSampleBufferGetDecodeTimeStamp(sample)
print("\(dts.value)/\(dts.timescale)")
}
for some reason with some targetFrameDTS assetReader copyNextSampleBuffer will skip samples.
in my particular case the output is
...
47/30
48/30
50/30
51/30
54/30
55/30
57/30
why is it so?