質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

955閲覧

applyingCIFiltersWithHandlerが呼ばれず動画にCIFilterが適用されてエクスポートできない

sacakoro

総合スコア35

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2021/10/19 00:14

こちらのドキュメントを参考に
https://developer.apple.com/documentation/avfoundation/avasynchronousciimagefilteringrequest

動画にCIFilterを適用させてエクスポートさせようとしたのですが、applyingCIFiltersWithHandlerが実行されてなく、動画にフィルターが適用されずエクスポートされました。

Swift

1 private func zoomBlur(url: URL, completion: @escaping (URL) -> Void) { 2 let filter = CIFilter(name: "CIZoomBlur")! 3 let avAsset = AVURLAsset(url: url) 4 let avComposition = AVComposition(url: url) 5 let composition = AVVideoComposition(asset: avComposition, applyingCIFiltersWithHandler: { request in 6 // Clamp to avoid blurring transparent pixels at the image edges 7 // 画像の端の透明なピクセルをぼかさないためのクランプ 8 let source = request.sourceImage.clampedToExtent() 9 filter.setValue(source, forKey: kCIInputImageKey) 10 11 // Vary filter parameters based on video timing 12 // 映像のタイミングに合わせてフィルターのパラメーターを変化させる 13 let seconds = CMTimeGetSeconds(request.compositionTime) 14 filter.setValue(seconds * 10.0, forKey: kCIInputAmountKey) 15 print("seconds = (seconds)") 16 17 // Crop the blurred output to the bounds of the original image 18 // ぼかした出力を元の画像の範囲内にトリミングする 19 let output = filter.outputImage!.cropped(to: request.sourceImage.extent) 20 21 // Provide the filter output to the composition 22 // フィルター出力をコンポジションに提供・ 23 request.finish(with: output, context: nil) 24 }) 25 guard let session = AVAssetExportSession(asset: avComposition, presetName: AVAssetExportPresetPassthrough) else { 26 // guard let session = AVAssetExportSession(asset: AVURLAsset(url: url), presetName: AVAssetExportPresetPassthrough) else { 27 debugPrint("Failed to prepare session") 28 return 29 } 30 let url2 = Utils.getMP4Path() 31 session.outputURL = url2 32 session.outputFileType = .mov 33 session.videoComposition = composition 34 self.session = session 35 self.session!.exportAsynchronously { 36 switch session.status { 37 case .completed: 38 debugPrint("completed") 39 completion(url2) 40 case .failed: 41 debugPrint("error: (session.error!.localizedDescription)") 42 default: 43 break 44 } 45 } 46 }

わからないこと

  • AVVideoComposition生成時にassetに指定するべきなのはAVURLAssetで指定した動画オブジェクトなのかAVCompositionで指定した動画オブジェクトなのでしょうか
  • AVAssetExportSession生成時に指定するassetはやはりAVURLAssetなのでしょうかAVCompositionなのでしょうか。
  • applyingCIFiltersWithHandlerが呼ばれないのは何が原因なのでしょうか。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

以下で自己解決しました。理由はよくわかってません。

  • AVVideoComposition, AVAssetExportSessionに与えるassetはAVURLAsset。
  • AVAssetExportSessionのpresentNameをAVAssetExportPresetPassthroughからAVAssetExportPreset1280x720(ここが根本原因?)

投稿2021/10/19 00:48

sacakoro

総合スコア35

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問