I wish to improve the video body price utilizing AVFoundation.
My method is straightforward: I plan to duplicate every body and cut back its length.
For instance, If I wish to double my body price, I’ll duplicate every body and half every of its length.
What I’ve tried:
I begin with a easy code to learn every body of video.
let asset = AVURLAsset(url: url, choices: nil)
do {
let reader = strive AVAssetReader(asset: asset)
let videoTrack = asset.tracks(withMediaType: AVMediaType.video)[0]
let readerOutput = AVAssetReaderTrackOutput(monitor: videoTrack, outputSettings: nil)
reader.add(readerOutput)
reader.startReading()
var nFrames = 0
whereas true {
let sampleBuffer = readerOutput.copyNextSampleBuffer()
if let sampleBuffer {
let timingInfo = UnsafeMutablePointer<CMSampleTimingInfo>.allocate(capability: 1)
let newSample = UnsafeMutablePointer<CMSampleBuffer?>.allocate(capability: 1)
CMSampleBufferGetSampleTimingInfo(sampleBuffer, at: 0, timingInfoOut: timingInfo)
print("(nFrames):")
print(timingInfo.pointee.length)
print(timingInfo.pointee.presentationTimeStamp)
nFrames = nFrames+1
} else {
break
}
}
print("Num frames: (nFrames)")
return nFrames
}catch {
print("Error: (error)")
}
However the timing information is not what I anticipated. Most of them are zero.
0:
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
1:
CMTime(worth: 413, timescale: 600, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
CMTime(worth: 0, timescale: 600, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
2:
CMTime(worth: 413, timescale: 600, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
CMTime(worth: 413, timescale: 600, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
3:
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
4:
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
5:
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
CMTime(worth: 0, timescale: 0, flags: __C.CMTimeFlags(rawValue: 0), epoch: 0)
Query:
Is that this a doable and proper method? Why does the timing of every body are zero?
Can anybody direct me to the suitable assets or options for this?
Right here is the file I wish to improve fps https://www.dropbox.com/scl/fi/nl6yabgl9yzikx12mkvnu/sample2.mp4?rlkey=wk4fsu2vvkcui31cneq8vruik&e=1&dl=0