Repository navigation
fix(media): decode inline video without plaintext temp files - #105
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a12498dcb3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for image in images { | ||
| try Task.checkCancellation() |
There was a problem hiding this comment.
Check cancellation when no images were produced
When cancellation causes AVAssetImageGenerator.images(for:) to terminate before yielding its first frame, images is empty and this loop executes zero times, so none of its cancellation checks run. The caller can consequently return an empty ProcessedFrames successfully from a cancelled operation; perform an unconditional cancellation check before or after the loop.
Useful? React with 👍 / 👎.
a12498d to
99bdf73
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99bdf73617
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| domain: "MediaProcessing", code: -1, | ||
| userInfo: [NSLocalizedDescriptionKey: "Failed to load the asset's duration"]) | ||
| } | ||
| try Task.checkCancellation() |
There was a problem hiding this comment.
Preserve cancellation errors from duration loading
When a memory-backed decode is cancelled while the preceding asset.load(.duration) is suspended, that load can throw for cancellation, but try? converts the error to nil and the guard throws the generic MediaProcessing NSError; this cancellation check is therefore never reached. Callers awaiting the new .memoryBacked path cannot reliably detect cancellation, so preserve the load error or check cancellation inside the guard's failure path.
Useful? React with 👍 / 👎.
| guard prefix[4] == 0x66, prefix[5] == 0x74, prefix[6] == 0x79, prefix[7] == 0x70 | ||
| else { | ||
| throw MemoryBackedVideoAssetError.invalidContainer |
There was a problem hiding this comment.
Accept QuickTime files without a leading ftyp atom
Valid QuickTime movie files do not require an ftyp atom, and their first atom may instead be moov, mdat, or another QuickTime atom. This unconditional leading-ftyp check therefore rejects a supported class of .mov/video/quicktime inputs before AVFoundation can inspect them, despite the initializer's stated QuickTime support; recognize the legacy QuickTime layout or narrow the API contract to only QuickTime files with a leading ftyp.
Useful? React with 👍 / 👎.
Changes
MemoryBackedVideoAsset, an owned AVFoundation resource loader that serves bounded byte ranges directly from immutableData.UserInput.Video.memoryBackedso the asset owner survives metadata probing and frame sampling.flowchart LR subgraph Before A1[data:video URI] --> B1[write vlm-UUID.mp4] B1 --> C1[AVURLAsset file URL] C1 --> D1[metadata and frame sampling] D1 --> E1[deferred file removal] end subgraph After A2[data:video MP4 or QuickTime URI] --> B2[MemoryBackedVideoAsset] B2 --> C2[bounded AVAssetResourceLoader ranges] C2 --> D2[metadata and frame sampling] D2 --> E2[owner retained; no plaintext file] endflowchart LR subgraph Before_Code F1[UserInput.Video.url] --> G1[AVAsset URL] G1 --> H1[MediaProcessing frame APIs] end subgraph After_Code F2[MemoryBackedVideoAsset] --> G2[UserInput.Video.memoryBacked] G2 --> H2[MediaProcessing.metadata] G2 --> I2[MediaProcessing frame APIs] H2 --> J2[retained asset owner] I2 --> J2 endVerification
swift-format lint --strict --configuration .swift-format Libraries/MLXLMCommon/MemoryBackedVideoAsset.swift Libraries/MLXLMCommon/UserInput.swift Libraries/MLXVLM/MediaProcessing.swift Tests/MLXLMTests/MediaProcessingTests.swiftswift build --build-testsswift test --skip-build --filter MLXLMTests.MediaProcesingTests— 13 tests passed after installing the source-matchedmlx.metallibin the test bundle.Checklist
pre-commit run --all-filesand retained formatting changes only in this PR's files; all four changed files pass strictswift-formatlint