AVVideoComposition instructions with CIFilter

I am creating an AVVideoComposition with CIFilter this way:




videoComposition = AVMutableVideoComposition(asset: asset, applyingCIFiltersWithHandler: {[weak self] request in
               
                // Clamp to avoid blurring transparent pixels at the image edges
                let source = request.sourceImage.clampedToExtent()
                let output:CIImage
               
                if let filteredOutput = self?.runFilters(source, filters: filters)?.cropped(to: request.sourceImage.extent) {
                    output = filteredOutput
                } else {
                    output = source
                }
           
                // Provide the filter output to the composition
                request.finish(with: output, context: nil)
            })


And then to correctly handle rotation, I create a passthrough instruction which sets identity transform on passthrough layer.


let passThroughInstruction = AVMutableVideoCompositionInstruction()
                passThroughInstruction.timeRange = CMTimeRangeMake(start: CMTime.zero, duration: asset.duration)
                let passThroughLayer = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack)
                passThroughLayer.setTransform(CGAffineTransform.identity, at: CMTime.zero) 
                passThroughInstruction.layerInstructions = [passThroughLayer]
                videoComposition.instructions = [passThroughInstruction]


The problem is it crashes with the error:


reason: '*** -[AVCoreImageFilterCustomVideoCompositor startVideoCompositionRequest:] Expecting video composition to contain only AVCoreImageFilterVideoCompositionInstruction'

My issue is that if I do not specify this passThroughInstruction, output is incorrect if input asset's videotrack contains a preferredTransform which specifies rotation by 90 degrees. How do I use video composition with Core Image filters that correctly handles preferredTransform of video track?

Replies

i have the same issue 😟 , only black video exported if did not put the instructions