title: Exporting CALayer with implicit animation via AVExportSession
body: <p>I'm trying to export an animation for my custom CALayer with a custom property via AVExportSession, please find the setup below:</p>
  
  <pre><code>class CustomAnimatable: CALayer
  {
      @NSManaged var brightness: CGFloat
  
      override init(layer: Any) {
          super.init(layer: layer);
  
          if let l = layer as? CustomAnimatable {
              self.brightness = l.brightness;
          }
      }
  
      override func action(forKey event: String) -&gt; CAAction?
      {
          if event == "brightness" {
              let animation = CABasicAnimation(keyPath: event);
              animation.fromValue = presentation()?.brightness ?? self.brightness;
              return animation;
          }
  
          return super.action(forKey: event);
      }
  
      override class func needsDisplay(forKey key: String) -&gt; Bool
      {
          if key == "brightness" {
              return true;
          }
  
          return super.needsDisplay(forKey: key);
      }
  
      override func display()
      {
          print("\(self) \(presentation()?.brightness) \(self.brightness)")
      }
  }
  </code></pre>
  
  <p>Here's the export session pre-setup:</p>
  
  <pre><code>func render()
  {
       ......
  
      let parentLayer = CALayer();
      let videoLayer = CALayer();
      let animationLayer = CustomAnimatable()
  
      parentLayer.frame = frame;
      videoLayer.frame = frame;
      animationLayer.frame = frame;
  
      parentLayer.addSublayer(videoLayer);
      parentLayer.addSublayer(animationLayer);
  
      CATransaction.begin()
      CATransaction.setAnimationDuration(2.2);
      CATransaction.setDisableActions(true);
      CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear))
  
      let anim = CABasicAnimation(keyPath: "brightness");
  
      anim.fromValue = 1.0;
      anim.fillMode = kCAFillModeBoth;
      anim.beginTime = AVCoreAnimationBeginTimeAtZero;
      anim.repeatCount = 1;
      anim.toValue = 0.0;
      anim.isRemovedOnCompletion = false;
  
      animationLayer.add(anim, forKey: "anim")
  
      CATransaction.commit()
  
  
      let videoComposition = AVMutableVideoComposition();
  
      videoComposition.renderSize = CGSize(width: width, height: height);
      videoComposition.instructions = [mainInstruction];
      videoComposition.frameDuration = CMTimeMake(1, 30);
      videoComposition.animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, in: parentLayer);
  
       ....
  }
  </code></pre>
  
  <p>The issue is that the <code>brightness</code> value in the resulting video goes from 1 to 0 without animation. If I attempt to animate <code>CALayer</code>'s native properties, e.g. <code>opacity</code> - the exported animation video is totally fine, the opacity smoothly fades from 1 to 0. </p>
  
  <p>Am I doing it wrong for custom property?</p>
  
  <p>Things I've considered:</p>
  
  <ul>
  <li>wrapping the explicit animation into <code>CATransaction</code> to disable implicit actions</li>
  <li>setting animation begin time to <code>AVCoreAnimationBeginTimeAtZero</code> and <code>isRemovedOnCompletion</code> to false as per "<a href="http://docs.huihoo.com/apple/wwdc/2010/session_407__editing_media_with_av_foundation.pdf" rel="nofollow noreferrer">Editing Media with AV Foundation</a>" session (Core Animation Gotchas section)</li>
  </ul>
  
  <p>I'm a bit confused by the fact that native CALayer properties animate fine, thus the export session setup seems to be correct. </p>
  
  <p>Besides that, if I add the custom layer to a view and animate the <code>brightness</code> property - it also animates fine. So the issue seems to be specific to rendering custom property animation w/ AVExportSession.</p>