不親切で判りにくいAppleドキュメントを読んでAVVideoCompositionを使えるようにした

https://developer.apple.com/documentation/avfoundation/avasynchronousciimagefilteringrequest

ViewController.swift
import Cocoa
import AVKit
import Foundation
import AVFoundation

class ViewController: NSViewController {

    @IBOutlet weak var playerView: AVPlayerView!

    var videoPlayer:AVPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // パスからassetを生成.
        let fileURL = URL(fileURLWithPath: "/Users/xxx/Sample.mov")
        let avAsset = AVURLAsset(url: fileURL)

        let filter = CIFilter(name: "CIGaussianBlur")!
        let composition = AVVideoComposition(asset: avAsset, applyingCIFiltersWithHandler: { request in

            // Clamp to avoid blurring transparent pixels at the image edges
            let source = request.sourceImage.clampedToExtent()
            filter.setValue(source, forKey: kCIInputImageKey)

            // Vary filter parameters based on video timing
            let seconds = CMTimeGetSeconds(request.compositionTime)
            filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey)

            // Crop the blurred output to the bounds of the original image
            let output = filter.outputImage!.cropped(to: request.sourceImage.extent)

            // Provide the filter output to the composition
            request.finish(with: output, context: nil)
        })

        // AVPlayerに再生させるアイテムを生成.
        let playerItem = AVPlayerItem(asset: avAsset)

        playerItem.videoComposition = composition

        // AVPlayerを生成.
        videoPlayer = AVPlayer(playerItem: playerItem)

        playerView.player = videoPlayer

        videoPlayer.play()
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.