iOS Development

ios – Methods to improve a video body charge utilizing AVFoundation

Spread the love


I need to improve the video body charge utilizing AVFoundation.

My method is straightforward: I plan to duplicate every body and cut back its period.

For instance, If I need to double my body charge, I’ll duplicate every body and half every of its period.

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(observe: 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.period)
                print(timingInfo.pointee.presentationTimeStamp)
                
                nFrames = nFrames+1
            } else {
                break
            }
        }
        print("Num frames: (nFrames)")
        return nFrames
    }catch {
        print("Error: (error)")
    }

However the timing data 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 appropriate sources or options for this?

Right here is the file I need to improve fps https://www.dropbox.com/scl/fi/nl6yabgl9yzikx12mkvnu/sample2.mp4?rlkey=wk4fsu2vvkcui31cneq8vruik&e=1&dl=0

Leave a Reply

Your email address will not be published. Required fields are marked *