0

ビデオ(60fps)を画像シーケンスにエクスポートするための以下のコードがあります。ただし、スタックオーバーフローの例がたくさんあるにもかかわらず、CMTime を適切にマスターしていないようです。画像 1 ~ 30 は同じで、31 ~ 90 は同じで、91 ~ 130、131 ~ 150 は同じです...生成されたシーケンスの場合のようにストップモーションでしょう。

var seq=0
let duration:Float64 = CMTimeGetSeconds(asset.duration)
let fps = tracks.first!.nominalFrameRate

for index:Float64 in stride(from: 0, to: duration, by: Double(1/fps)) {
    let time:CMTime = CMTimeMakeWithSeconds(index, preferredTimescale:Int32(NSEC_PER_SEC))
    var image:CGImage
    do {
        try image = generator.copyCGImage(at:time, actualTime:nil)
        let bitmapRep = NSBitmapImageRep(cgImage: image)
        let data = bitmapRep.representation(using: .jpeg, properties: [:])
        let oneimagepath=newpath.appendingPathComponent("Sequence.\(String(format: "%04d", seq)).jpg")
        seq = seq+1
        try data?.write(to: oneimagepath, options: .atomicWrite)
    } catch {
        print(error.localizedDescription)
    }
}

問題は私の CMTime にありますか、それとも別の場所にありますか? 10 進数の時間を int に変換するようなものです。

4

0 に答える 0