sunlubo / SwiftFFmpeg

A Swift wrapper for the FFmpeg API
Apache License 2.0
511 stars 83 forks source link

How to get the duration and convert it to hh:mm:ss format? #59

Closed iT-Boyer closed 2 years ago

iT-Boyer commented 2 years ago
let duration = fmtCtx.duration/1000000
duration.secondsToTime()
extension Int64 {

    func secondsToTime() -> String {

        let (h,m,s) = (self / 3600, (self % 3600) / 60, (self % 3600) % 60)

        let h_string = h < 10 ? "0\(h)" : "\(h)"
        let m_string =  m < 10 ? "0\(m)" : "\(m)"
        let s_string =  s < 10 ? "0\(s)" : "\(s)"

        return "\(h_string):\(m_string):\(s_string)"
    }
}