AVAssetWritingPlanner
AVAssetWritingPlanner orchestrates incremental writing of media files.
Declaration
class AVAssetWritingPlannerOverview
AVAssetWritingPlanner orchestrates an incremental and resumable asset file writing session. It keeps track of the progress of the incremental segments, and can resume the writing from the last checkpoint. This is NOT intended for any real time applications. Also, not all tracks can be written incrementally. The workflow is as follows:
The client creates the planner with a unique directoryForTemporaryFiles.
The client tells the planner which tracks are to be written incrementally by calling the “planTrack:withSegmentsGeneratedBy:” method, providing a callback block that writes one segment per block invocation.
The client kicks off the incremental writing session by calling the “executePlanWithCompletionHandler” method.
The planner will call the writingSegmentCallbackBlock to ask the client to write one incremental segment of one track at a time. The client code should write one incremental segment according to the “AVPlannedSegmentWritingRequest” object passed in to the callback block. Clients must call “finish” or “finishWithError” or “finishWithClientState” or “cancel” methods on the request object when it finishes the segment successfully, or encountered an error, or wants to cancel the writing of the segment.
At the end of the writing, after all incremental segments are finished, the planner calls the completionHandler. The client can use the “assemblyComposition” object passed in to the completionHandler to assemble the incremental segments into full tracks and export it to a final output file. The completionHandler will also be called when there is any irrecoverable error.
The client is responsible for cleaning all files in the directoryForTemporaryFiles after the incremental session is done and the final output file is written.
AVAssetWritingPlanner is able to recognize when a plan-in-progress matching the plan was already saved at directoryForTemporaryFiles, presumably by a previous invocation of the client, and possibly aborted due to that client being terminated abruptly, and will assist by resuming the plan at the first step that wasn’t previously completed.
Topics
Creating a planner
Planning tracks
Executing the plan
Getting segment boundary guidance
segmentBoundaryGuidelinesForVideo(codecType:encoderSpecification:)segmentBoundaryRecommendations(forVideoTrack:minimumSegmentDuration:minimumSegmentFrameCount:)