fix: enforce bitrate as a real maximum on Android and iOS/macOS#173
Merged
Conversation
- Added `getVideoBitrate` method in `MediaInfoExtractor` to probe video bitrate. - Updated integration tests to verify bitrate cap enforcement for compliant and over-cap sources. - Introduced `BitrateCapPolicy` to determine when to force re-encoding based on requested bitrate cap. - Created `BitrateCappedExporter` to handle video rendering with enforced bitrate limits. - Enhanced documentation to clarify bitrate cap behavior and verification steps. - Updated version to 2.4.0 to reflect new features and improvements.
…arity and functionality
…e across platforms
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.
Description
VideoQualityConfig.bitratewas documented as a quality setting but was silently ignored on a no-edit export: Android transmuxed the source untouched (an ~18 Mbit/s camera clip stayed ~18 Mbit/s despite an 8 Mbit/s request), and iOS/macOS mapped the value to the nearestAVAssetExportSessionpreset, which chooses its own bitrate (10–16 Mbit/s at 1080p). This makesbitratea guaranteed maximum on all three platforms.cap × 1.2(tolerance) and nothing else forces a re-encode, keep the lossless transmux fast path; otherwise force the Media3 video track throughResilientVideoEncoderFactoryso the bitrate is actually applied. The decision is factored into a unit-testedBitrateCapPolicyand evaluated against the final (post pre-transcode/reverse/transition) clip paths.AVAssetExportSessionrender with anAVAssetReader→AVAssetWriterpipeline that setsAVVideoAverageBitRateKey(reusing theStopMotionGeneratorpattern), preserving the video composition (filters/blur/layers/transitions), audio mix, global trim, frame-rate cap, progress and cancellation. A compliant no-edit source is remuxed losslessly viaAVAssetExportPresetPassthrough.bitrate == null: behavior unchanged.shouldOptimizeForNetworkUse(moov-at-front) works on both the fast and re-encode paths.Note: an over-cap source that used to export losslessly is now re-encoded down to the cap.
Verification
moov-at-front honored on both paths.bitrate_cap_test.dartpasses on macOS and a Galaxy S942B (Android 16); the fullvideo_render_test.dartregression suite passes on both (macOS 78, Android 71 + 8 platform-skipped).BitrateCapPolicytests; iOS builds clean;flutter analyze+ 251 Dart unit tests pass.example/docs/bitrate_cap_verification.md.Related Issue: Closes #
Type of Change