Commit Graph

58 Commits

Author SHA1 Message Date
Milan Stevanovic
90a356b29d Fix incorrect embedded druation in certain MP4 files.
The root cause:
- some MP4 files come with H.264/H.265 streams which explicitly
  state their timescale. In such cases, it is wise that MP4 muxer
  adopts these values
- unfortunately, the recent trend has been that such values coming
  from video stream SPS (vui_parameters/timing info) are exorbitantly
  high - instead of being FPS *1000, they tend to be FPS * 100,000,000
- when trying to express the duration of the movie, the MP4 muxer
  normally tries to find the adequate timescale value which will
  fit both audio and video timescaling domains. The most suitable
  approach is that the LCM (least common multiplier) value is taken
  which mathematically will be the least disruptive.

HOWEVER:
- in cases when video and timescale numeric values are mutually 'odd',
  say 30*100,000,000 and 44100, the LCM ends up being a huge number,
  which outgrows the 32-bit storage capacity granted by the ISO MP4
  spec (MVHD box).

Problem solution:
1) identifying when the LCM timescale exceeds 32-bit storage space
2) scaling down its value by nearest larger 10X factor, which will
   guarantee its value fitting the 32-bit space. Given the afore
   mentioned video timescale factors, dividing by 10X is harmless
3) rescaling the duration 64-bit value based on the new timescale
2025-04-16 11:22:23 -03:00
Sagar
de54ff304d Improve byteCountEstimate calculation for videos. 2025-03-26 13:59:12 -04:00
Milan Stevanovic
f0e6b2944a Eliminate zero-sized samples from contributing to the audio track.
Eliminating unnecessary and potentially counter-productive zero-sized
samples from the audio trak. The Android MP4 multiplexer tends to add
them at the very end of the audio stream. Their presence may negatively
affect the declared audio stream duration, and pose further complications
down the road.

The changes are verified on Samsung A54 (Android 14) device.
2025-03-26 13:59:11 -04:00
Greyson Parrelli
7c7dc679e9 Only write out one MDAT box for a video transcode.
Co-authored-by: Milan Stevanovic <milan@signal.org>
2025-02-11 15:31:06 -05:00
Greyson Parrelli
7b101e13fb Upgrade to kotlin 2.1.0 2024-12-21 12:39:10 -05:00
Alex Hart
bdd19f6b47 Replace collectAsState with collectAsStateWithLifecycle. 2024-11-04 09:44:44 -04:00
Greyson Parrelli
ee488ea0b8 Rename some video constants for readability. 2024-10-23 15:51:54 -04:00
Greyson Parrelli
a8fb4eb21a Rename TruncatingInputStream -> LimitedInputStream. 2024-09-13 10:51:30 -04:00
Greyson Parrelli
a6767e4f8a Replace other limiting streams with TruncatingInputStream. 2024-09-13 10:51:30 -04:00
Nicholas Tinsley
69d62d385e Small fixes for the video transcoding playground app. 2024-08-27 13:21:20 -04:00
Nicholas Tinsley
0f7f866562 Experimental HEVC encoding support for videos. 2024-08-27 13:21:20 -04:00
Nicholas Tinsley
076df8c429 Update video sample app to read and write from private app storage. 2024-08-22 13:04:59 -07:00
Nicholas Tinsley
8727f0d90d Update video sample app for API 34. 2024-08-22 13:04:59 -07:00
Nicholas Tinsley
f247fd78c6 Constant bitrate video encoding. 2024-07-12 11:01:03 -04:00
Nicholas Tinsley
489b58ad67 Abort transcoding if frame processing gets stuck. 2024-06-24 15:04:02 -04:00
Nicholas Tinsley
65dc0d3f34 Disable verbose logging in media converter. 2024-06-10 14:38:19 -04:00
Cody Henthorne
537fc0ef5c Update to Kotlin 1.9.20, AGP 8.4.0, and Gradle 8.6 2024-06-05 15:45:59 -04:00
Nicholas Tinsley
4a08de370a Fix issue with Mp4Writer with massive time scales. 2024-05-01 16:45:36 -04:00
Nicholas Tinsley
eec2685e67 Registration refactor initial scaffolding. 2024-04-18 16:24:13 -04:00
Nicholas Tinsley
c53abe0941 Video Sending Redesign 2024-03-06 20:42:01 -04:00
Nicholas Tinsley
fc1d60e65b Fallback to matching video decoder by MIME type. 2024-02-23 16:42:57 -05:00
Nicholas Tinsley
f18070b78c Revert "Don't recreate attachment InputStream if we don't have to."
This reverts commit 467dae8132.
2024-02-05 10:49:05 -05:00
Nicholas Tinsley
4545e70384 Remix audio remuxing into its own feature flag. 2024-02-03 13:57:49 -05:00
Nicholas Tinsley
467dae8132 Don't recreate attachment InputStream if we don't have to. 2024-01-31 22:13:46 -05:00
Nicholas Tinsley
9a52f4e3ff Remux audio if possible when transcoding.
Addresses #11712, #12674, #12945, #13084, #13346.
2024-01-31 22:12:17 -05:00
Nicholas Tinsley
8d44222097 Enable logcat in the video sample app. 2024-01-31 22:12:17 -05:00
Nicholas Tinsley
9cb2024334 Option to persist task in video sample app. 2024-01-31 22:12:17 -05:00
Nicholas Tinsley
6fc9055221 Calculate video encoding settings based on trimmed duration. 2024-01-25 18:59:57 -05:00
Nicholas Tinsley
d2cbf11264 Don't fail video send on postprocess failure. 2024-01-25 13:32:03 -05:00
Nicholas Tinsley
ee19520e1b Improve video sample app UI. 2024-01-23 13:18:56 -05:00
Nicholas Tinsley
6f16b3fee7 Add video sample app test dependencies. 2024-01-23 13:18:56 -05:00
Nicholas Tinsley
7666462de2 Support Dolby Vision HDR videos in transcoder. 2024-01-23 13:18:56 -05:00
Nicholas Tinsley
54cf11a78b Request notification permissions for video sample app. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
a36f31c2d0 Allow full disablement of StreamingTranscoder output size limit. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
69c864f984 Allow slight variations in video output frame count. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
3c9a7fd329 Reorganize video converter library packages 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
7bb1c58452 Refactor Mp4FaststartPostProcessor. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
8e7383be05 Make Mp4Writer output compatible with Quicktime. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
c41795e7f0 Extract postprocessor lambda into interface. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
52120afdbd Remove dependency on Guava limited stream. 2024-01-23 11:52:04 -05:00
Nicholas Tinsley
393730cea9 Fix video sample app output. 2024-01-23 11:52:04 -05:00
Alex Hart
7b9554a42c Align profile screen with figma. 2024-01-23 11:52:03 -05:00
Nicholas Tinsley
ddcc06c6b7 Update video transcoding sample cleanup file extension. 2024-01-23 11:52:03 -05:00
Nicholas Tinsley
caa5e233df Expose StreamingTranscoder configuration options in sample app. 2024-01-23 11:52:03 -05:00
Nicholas Tinsley
c7609f9a2a StreamingTranscoder sample app. 2024-01-23 11:52:03 -05:00
Nicholas Tinsley
dd1a15c249 fixup! Refactor video testapp. 2024-01-10 11:52:20 -05:00
Nicholas Tinsley
8b24498fa7 Refactor video testapp. 2024-01-10 11:50:54 -05:00
Greyson Parrelli
766733617e Converted all minor modules to .gradle.kts. 2023-12-04 16:18:11 -05:00
Greyson Parrelli
9cc020a2c7 Move the video lib to the proper directory. 2023-10-17 11:15:56 -04:00
Greyson Parrelli
6145fa213e Move common gradle config into convention plugins. 2023-02-14 14:03:09 -05:00