Hi,
Thanks for the detailed report and the sample video.
We have analyzed the CameraX Recorder codebase to trace how numBytesRecorded is tracked and finalized.
We confirmed that a CameraX-side race condition is highly unlikely:
Durable Tracking: numBytesRecorded is strictly accumulated after `mMuxer.writeSampleData(...)` returns successfully.
Robust Teardown: CameraX fully drains both encoders and ensures all data is passed to the muxer before `mMuxer.stop()` is called.
As far as CameraX is concerned, all counted bytes were successfully handed over to the system `MediaMuxer` API.
Since this only occurs on specific devices (Fairphone 4 and Samsung A23), this may point to a bug in the platform's system MediaMuxer on those devices.
During `MediaMuxer.stop()`, the system muxer is likely silently discarding the last audio frame, even though `writeSampleData` returned success. The 395-byte delta is extremely consistent with exactly one missing AAC audio frame.
Suggested Workaround: To bypass platform-specific bugs, CameraX 1.6.X (from 1.6.0-beta02) has migrated to Media3's MediaMuxerCompat. This uses a robust, pure-Java muxer, ensuring consistent behavior across all devices.
Hope this helps clarify the behavior!
CONFIDENTIAL
This e-mail and any attachments are confidential and intended solely for the addressee and may also be privileged or exempt from disclosure under applicable law. If you are not the addressee, or have received this e-mail in error, please notify the sender immediately, delete it from your system and do not copy, disclose or otherwise act upon any part of this e-mail or its attachments. Internet communications are not guaranteed to be secure or virus-free. Revolut does not accept responsibility for any loss arising from unauthorised access to, or interference with, any Internet communications by any third party, or from the transmission of any viruses. Replies to this e-mail may be monitored by Revolut for operational or business reasons. Any opinion or other information in this e-mail or its attachments that does not relate to the business of Revolut is personal to the sender and is not given or endorsed by Revolut. Registered Office: 30 South Colonnade, London E14 5HX, United Kingdom. Main Office: 30 South Colonnade, London E14 5HX, United Kingdom. Revolut Ltd is authorised and regulated by the Financial Conduct Authority under the Electronic Money Regulations 2011, Firm Reference 900562.
Hi,
After a thorough investigation, I have a suggestion how to handle it.
In CameraX, `recordingStats.numBytesRecorded` represents the sum of all raw, encoded audio and video frame sizes before they are handed over to the muxer. However, once CameraX passes these frames to the muxer, the muxer may perform containerization steps that alter the final physical byte count. Because these operations are handled privately inside the muxer, CameraX cannot know the exact, byte-level layout of the final MP4 file during recording. If your application requires a byte-exact payload size, you should not rely on `numBytesRecorded` as a source of truth, as it is designed to be an approximation. Instead, it is recommended querying the physical file once you receive the VideoRecordEvent.Finalize event. Since the muxer is fully closed and flushed at this point, the file on disk represents the absolute source of truth.