Using HEVC video with alpha
At a glance
| Item | Summary |
|---|---|
| Purpose | Play, write, and export HEVC video with an alpha channel to add overlay effects to your video processing. |
| App architecture | A Swift sample bundle with entry-bearing project variants HEVC-Videos-With-Alpha-AssetWriting, HEVC-Videos-With-Alpha-Playback, each leading to AVFoundation APIs. |
| Main patterns | View-controller organization, Delegate or data-source callbacks |
| Project style | 4 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue(label:), DispatchSemaphore, DispatchQueue.global.async, DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | No structured observation or publisher-scheduling marker indexed. |
| Key frameworks/packages | AVFoundation, Cocoa, VideoToolbox, AppKit, CoreImage; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── HEVC-Videos-With-Alpha-AssetWriting/
│ ├── HEVC-Videos-With-Alpha-AssetWriting/
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj/
│ │ │ └── MainMenu.xib
│ │ └── Info.plist
│ └── HEVC-Videos-With-Alpha-AssetWriting.xcodeproj/
│ ├── .xcodesamplecode.plist
│ └── project.pbxproj
├── HEVC-Videos-With-Alpha-Exports/
│ ├── HEVC-Videos-With-Alpha-Exports/
│ │ └── main.swift
│ └── HEVC-Videos-With-Alpha-Exports.xcodeproj/
│ ├── .xcodesamplecode.plist
│ └── project.pbxproj
├── HEVC-Videos-With-Alpha-Playback/
│ ├── HEVC-Videos-With-Alpha-Playback/
│ │ ├── AppDelegate.swift
│ │ └── ViewController.swift
│ └── HEVC-Videos-With-Alpha-Playback.xcodeproj/
│ └── .xcodesamplecode.plist
└── Configuration/
└── SampleCode.xcconfig
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 14 project/configuration file(s) and 4 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["HEVC-Videos-With-Alpha-AssetWriting"]
V2["HEVC-Videos-With-Alpha-Playback"]
Boundary["AVFoundation APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Reference code
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:21 — architecture anchor
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, SCNSceneRendererDelegate {
@IBOutlet weak var sceneKitView: SCNView!
// ...
}Interpretation
The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.
Ownership and state
classDiagram
ExportSettings *-- CMTime : duration
ExportSettings *-- CMTimeScale : frameRate
ExportSettings *-- CGRect : viewport
AppDelegate o-- SCNView : sceneKitView
Ownership evidence
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:14 — stored dependency or nearest verified ownership anchor
struct ExportSettings {
static let duration = CMTime(value: 5, timescale: 1)
static let frameRate = CMTimeScale(60)
static let height = 720
static let width = 1280
static let viewport = CGRect(x: 0, y: 0, width: width, height: height)
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ExportSettings |
CMTime (duration) |
creates and retains | Initialized by the owner; the binding is immutable |
ExportSettings |
CMTimeScale (frameRate) |
creates and retains | Initialized by the owner; the binding is immutable |
ExportSettings |
CGRect (viewport) |
owns value state | Initialized by the owner; the binding is immutable |
AppDelegate |
SCNView (sceneKitView) |
holds a non-owning reference | The referenced object’s lifecycle is owned elsewhere |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Queue scheduling | DispatchQueue(label:) |
The source constructs a dispatch queue; its label alone does not prove a thread. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:177 |
| Synchronization | DispatchSemaphore |
The source references a synchronization primitive; the protected state requires surrounding review. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:181 |
| Queue scheduling | DispatchQueue.global.async |
The source addresses a global dispatch queue; no stable thread identity is implied. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:221 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:224 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:177 — representative execution boundary
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, SCNSceneRendererDelegate {
// ...
let mediaDataRequestQueue = DispatchQueue(label: "com.apple.apple-samplecode.HEVC-Videos-With-Alpha-AssetWriting.mediaDataRequestQueue")
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:10 |
| Source import | Cocoa |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:8 |
| Source import | VideoToolbox |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:11 |
| Source import | AppKit |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift:8 |
| Source import | CoreImage |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift:12 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift:9 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:22 — representative type boundary
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, SCNSceneRendererDelegate {
@IBOutlet weak var sceneKitView: SCNView!
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate, SCNSceneRendererDelegate |
AppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate |
ViewController |
View lifecycle, callbacks, and feature coordination | NSViewController |
ExportSettings |
Carries feature or framework configuration | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
description (HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift:16) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
AppDelegate (HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/AppDelegate.swift:10) |
implicit internal |
No explicit modifier means the Swift declaration is internal to the module. | Inference: app-target collaboration needs no exported library surface. |
Reference code
HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift:16 — representative boundary
public var description: String {
// ...
case .unknown: return "unknown"
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | ViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate |
The source’s Delegate suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/ViewController.swift:12 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Delegate or data-source callbacks | HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift:22 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: Controller: ViewController; Delegate: AppDelegate.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
applicationDidFinishLaunching,renderNextFrameAsynchronously,renderer,makeAssetWriter,exportToHEVCMovieWithAlphaAsynchronously,pressedRecord,applicationWillTerminate,exportToHEVCWithAlphaAsynchronously. - Files:
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift,HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/AppDelegate.swift,HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/ViewController.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches AVFoundation, Cocoa, VideoToolbox, AppKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
HEVC-Videos-With-Alpha-AssetWriting/HEVC-Videos-With-Alpha-AssetWriting/AppDelegate.swift |
Cited implementation, AppDelegate, DispatchQueue(label:), DispatchSemaphore, DispatchQueue.global.async, DispatchQueue.main.async, AVFoundation, Cocoa, VideoToolbox, ExportSettings |
HEVC-Videos-With-Alpha-Exports/HEVC-Videos-With-Alpha-Exports/main.swift |
Cited implementation, AppKit, CoreImage, Foundation, Feature implementation |
HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/AppDelegate.swift |
Cited implementation, AppDelegate |
HEVC-Videos-With-Alpha-Playback/HEVC-Videos-With-Alpha-Playback/ViewController.swift |
ViewController |