Silence-GitHub / BBMetalImage

A high performance Swift library for GPU-accelerated image/video processing based on Metal.
MIT License
988 stars 126 forks source link

How to track recording duration? #11

Closed hoangdado closed 5 years ago

hoangdado commented 5 years ago

Hi @Silence-GitHub, could you please add a way to track video recording duration to BBMetalVideoWriter?

Silence-GitHub commented 5 years ago

Do you mean calculating the whole duration of writing a video? If so, keep the start time and the end time to calculate.

Or do you mean calculating the duration of writing one frame? How about adding a progress callback after writing a frame? So you can do whatever you want after writing each frame.

hoangdado commented 5 years ago

Thanks @Silence-GitHub, What I want is a progress callback.

Silence-GitHub commented 5 years ago

Version 1.0.7 adds video writer progress callback.

videoWriter.start { (type) in
    switch type {
        case let .video(time, success): print("Video time = \(time), success = \(success)")
        case let .audio(time, success): print("Audio time = \(time), success = \(success)")
    }
}
hoangdado commented 5 years ago

Hi @Silence-GitHub, thanks for your quick response, but what I mean is the elapsed time (may be CMTime or CGFloat seconds value) from videoWriter.start()

Silence-GitHub commented 5 years ago

I think providing the video time in progress callback is more reasonable. You can track the elapsed time like this.

let startTime = CACurrentMediaTime()
videoWriter.start { (type) in
    let duration = CACurrentMediaTime() - startTime
}
hoangdado commented 5 years ago

@Silence-GitHub, thank you so much!