18.9 · Reading an asset, grabbing frames, reading samples, frame-exact time, and pixel buffers
AVFoundation problems are about time and memory: frames that are not where you asked, rounding that drifts, and buffers whose rows are not what you assume.
Mental model. Media is a timeline of samples. Ask the right question about time (exact or nearby?) and about layout (what is in a row?).
Assets and frames
Asset metadata, image generation tolerance, and reading decoded samples.
- How do you read what is in a media file, and why are the loads async and throwing?
An AVURLAsset is a lazy description: you ask for properties with try await asset.load(.duration, .isPlayable, .tracks), and for per-track facts with… - Why does AVAssetImageGenerator return a frame at a different time than you asked for, and how do you get the exact one?
Video is stored as keyframes plus differences, so decoding an arbitrary time is expensive. AVAssetImageGenerator therefore defaults to infinite tolerance: it… - When do you use AVAssetReader instead of a player, and what do the output settings change?
A player renders in real time for display; AVAssetReader pulls samples as fast as you ask for processing, analysis or transcoding. Add an…
Time and buffers
CMTime arithmetic and pixel-buffer layout and pools.
- How does CMTime avoid rounding errors, and how can sloppy conversion make audio and video drift?
CMTime is a rational number (value ÷ timescale), so 29.97 fps video is exactly 1001/30000 s per frame and 30 frames are exactly 30030/30000 = 1.001 s. The… - How is a CVPixelBuffer laid out, why are rows padded, and how do pools limit memory?
A CVPixelBuffer is a pixel format plus rows with a bytesPerRow that may be bigger than the data. A 100×50 BGRA buffer needs 400 bytes a row but had 448 in the…
More in Media & graphics
- 18.1 · AVPlayer, time, and editing with compositions
- 18.2 · The audio session, interruptions, routes and AVAudioEngine
- 18.3 · AVCaptureSession, and zero-copy pixel buffers
- 18.4 · HLS, buffering, Now Playing, remote commands, Picture in Picture and AirPlay
- 18.5 · ImageIO formats, Core Image, Metal, and SceneKit versus RealityKit
- 18.6 · VideoToolbox, tvOS focus and media, and building a playback platform
- 18.7 · Thumbnails and orientation, GIF timing, bitmap layout, and colour spaces
- 18.8 · Extents, working colour space, and a compute pass from start to finish