SKVideoNode with color blend using SKEffectNode crashes

218 views Asked by At

I need to blend a color to the video as it done with textures in SKSpriteNode. The video has transparency (HEVC), you can download it here. Doc says that a video can be color-blended and I'm writing the correct code, but it crashes.

Quote:

A video node cannot be colorized. However, it can be added as a child of a SKEffectNode to add Core Image filters for color treatments and other effects.

The code I use:

    let videoEffect = SKEffectNode()
    videoEffect.name = "videoEffect"
    videoEffect.filter = CIFilter(name: "CIColorBlendMode")
    let colorImg = CIImage(color: CIColor(color: .red))
    videoEffect.filter?.setValue(colorImg, forKey: "inputBackgroundImage")
    videoEffect.shouldEnableEffects = true
    addChild(videoEffect)

    let videoNode = SKVideoNode(fileNamed: "puppets_with_alpha_hevc.mov")
    videoNode.name = "video"
    videoNode.zPosition = ZPosition.aiBot - 0.5
    videoEffect.addChild(videoNode)

Running on a simulator iOS 15.2, getting crash and this output:

-[MTLTextureDescriptorInternal validateWithDevice:]:1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width of zero. MTLTextureDescriptor has height of zero.

May be the filter setup is incorrect? Well, just comment out the filter, like this:

    //videoEffect.filter = CIFilter(name: "CIColorBlendMode")
    //let colorImg = CIImage(color: CIColor(color: .red))
    //videoEffect.filter?.setValue(colorImg, forKey: "inputBackgroundImage")

Now we have just an Effect Node without effects. This should work. But...

-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5252: failed assertion `Draw Errors Validation Fragment Function(FastSingle_FragFunc): missing sampler binding at index 0 for u_texture_sampler[0].

0

There are 0 answers