Repository navigation
fix(ios): honor explicit bitrate in compressVideo - #4
Merged
Merged
Conversation
The bitrate parameter was declared but never used in VideoProcessor.swift compressVideo(). AVAssetExportSession does not support custom bitrate, so this adds an AVAssetWriter/AVAssetReader pipeline that activates when bitrate > 0 (and targetSizeInMB is not set). - Encodes H.264 with AVVideoAverageBitRateKey for precise bitrate control - Audio passthrough (no re-encode) unless muteAudio is true - Supports maxWidth scaling via CIImage GPU-accelerated resize - Preserves rotation metadata via preferredTransform - Includes anti-inflation fallback (reverts if output > original size) - Existing quality preset and targetSizeInMB paths are unchanged Fixes #3
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3 - the
bitrateparameter incompressVideowas declared but completely unused on iOS.Root Cause
iOS used
AVAssetExportSessionfor all compression paths, which only supports Apple's built-in quality presets (Low/Medium/High/1080p/720p etc.) and does not accept custom bitrate values. Thebitrateparameter was accepted in the function signature but never referenced in the function body.Solution
Added a new
AVAssetWriter+AVAssetReaderpipeline (compressWithBitrate) that activates when:bitrate > 0ANDtargetSizeInMBis not set (<= 0)This mirrors how Android handles explicit bitrate via
Transformer'sVideoEncoderSettings.setBitrate().Key implementation details:
AVVideoAverageBitRateKeyfor precise bitrate controlmuteAudio: truepreferredTransformon the writer inputqualitypreset andtargetSizeInMBsmart compress are not affectedBehavior matrix:
{ bitrate: 4000000 }{ quality: "low" }{ targetSizeInMB: 5 }{ bitrate: 4000000, muteAudio: true }Testing
Needs macOS build + device testing with the test cases above.