質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,14 +2,56 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
静止画に関しては、CIfilterを用いてフィルターをかけることができたのですが、動画については調べたところ、
|
5
|
+
静止画に関しては、CIfilterを用いてフィルターをかけることができたのですが、動画については調べたところ、'AVAsynchronousCIImageFilteringRequest'というクラスを用いてCIFilterをかける方法が公式サイトにありました。
|
6
|
+
|
7
|
+
[Apple Developer](https://developer.apple.com/documentation/avfoundation/avasynchronousciimagefilteringrequest)
|
6
8
|
|
7
9
|
|
8
10
|
|
9
|
-
|
11
|
+
```swift
|
10
12
|
|
13
|
+
let filter = CIFilter(name: "CIGaussianBlur")!
|
14
|
+
|
15
|
+
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// Clamp to avoid blurring transparent pixels at the image edges
|
20
|
+
|
21
|
+
let source = request.sourceImage.imageByClampingToExtent()
|
22
|
+
|
23
|
+
filter.setValue(source, forKey: kCIInputImageKey)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
// Vary filter parameters based on video timing
|
28
|
+
|
29
|
+
let seconds = CMTimeGetSeconds(request.compositionTime)
|
30
|
+
|
31
|
+
filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
// Crop the blurred output to the bounds of the original image
|
36
|
+
|
37
|
+
let output = filter.outputImage!.imageByCroppingToRect(request.sourceImage.extent)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// Provide the filter output to the composition
|
42
|
+
|
11
|
-
|
43
|
+
request.finishWithImage(output, context: nil)
|
44
|
+
|
45
|
+
})
|
46
|
+
|
47
|
+
```
|
12
48
|
|
13
49
|
|
14
50
|
|
51
|
+
AppleDeveloperでは上記を例にAVAssetにCIFilterをかける方法が載っていたのですが、ここからこのAVVideoCompositionを再びAVAssetに変換する方法がわかりません。
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
どなたかわかる方がいらっしゃれば是非教えて頂きたいです。
|
56
|
+
|
15
|
-
よろしくお願いします。
|
57
|
+
よろしくお願いいたします。
|