title: How do you write only certain CMSampleBuffer frames to a new movie file in AVFoundation?
body: <p>I'd like to perform pose analysis on user imported video, automatically producing an <code>AVFoundation</code> video output where only frames with <a href="https://developer.apple.com/documentation/createml/detecting_human_actions_in_a_live_video_feed" rel="nofollow noreferrer">a detected pose</a> are a part of the result. In the <a href="https://developer.apple.com/documentation/vision/building_a_feature-rich_app_for_sports_analysis" rel="nofollow noreferrer">Building a Feature-Rich App for Sports Analysis</a> sample code, analysis happens by implementing the <code>func cameraViewController(_ controller: CameraViewController, didReceiveBuffer buffer: CMSampleBuffer, orientation: CGImagePropertyOrientation)</code> delegate callback, such as in line 326 of <code>GameViewController.swift</code>.</p>
  <p>Where I'm stuck is using this analysis to only keep particular frames with a pose detected. Say I've analyzed all <code>CMSampleBuffer</code> frames and classified which ones have the pose I want. How would I only those specific frames for the new video output?</p>
  <p>The &quot;AVFoundation Programming Guide&quot; link is broken in Apple's documentation archive, so conceptual explanations are hard to find. Preference is for answers in Swift, though Objective-C would still be helpful.</p>