Skip to content

When transcoding a video fails, send it as a file #4257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Feb 10, 2025

Content

Changes:

  • Make sure the 'at most' video dimensions are 1080p for non-compressed media and 720p for compressed media, matching iOS.
  • Try avoiding transcoding when possible, and when it's not try matching as much properties of the original video as possible.
  • If transcoding fails, send the original video as a file.

While reviewing you might want to skip/not thoroughly review commit 64ba34c since it's reworked shortly after.

Motivation and context

Fixes #4243, or at least adds a workaround.

Tests

I was able to make the transcoding fail with this video in a Xiaomi Mi 9T with Android 14.

  • Try sending the video as an attachment in some room. Processing and transcoding the video will fail.
  • Send the video. It will be sent as is, without a thumbnail, but it should still be playable on the other side. For some reason it's send as an m.video message instead of a m.file one, but it seems like this might need to be changed in the SDK.
  • Try some other MP4 video, larger than 1080p if you have disabled media optimisation or 720p if it's enabled, the video will be resized.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

Copy link
Contributor

github-actions bot commented Feb 10, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/ifBAYU

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 29.41176% with 48 lines in your changes missing coverage. Please review.

Project coverage is 79.96%. Comparing base (b636c69) to head (4c1b728).
Report is 64 commits behind head on develop.

Files with missing lines Patch % Lines
...roid/libraries/mediaupload/impl/VideoCompressor.kt 37.73% 29 Missing and 4 partials ⚠️
...aries/mediaupload/impl/AndroidMediaPreProcessor.kt 0.00% 15 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4257      +/-   ##
===========================================
- Coverage    79.99%   79.96%   -0.04%     
===========================================
  Files         2107     2107              
  Lines        55847    55895      +48     
  Branches      6973     6992      +19     
===========================================
+ Hits         44676    44696      +20     
- Misses        8774     8798      +24     
- Partials      2397     2401       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmartinesp jmartinesp mentioned this pull request Feb 10, 2025
Copy link

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a first comment, I do not see any MonotonicTimelineInterpolator in the changes. What am I missing?

@jmartinesp
Copy link
Member Author

The title is a bit outdated, this PR was just added so we could test solutions to fix an issue when trying to transcode videos before sending them (the linked one above) in some Android versions (MIUI for Android 12?).

The original error said:

java.lang.IllegalStateException: Timestamps must be monotonically increasing: 0, 0

So I tried to fix that by using an interpolator that ensures the video timestamps always go forward, to see if that could solve the issue (it doesn't). This is either a problem with the codecs in the OS shipped by problematic vendors or an issue with the lib we're using to simplify the transcoding process.

So I guess our options are either allowing videos to be sent as is if transcoding fails (either as a file or as the actual media) or using a different lib or transcoder for this. I'm waiting for a decision from @mxandreas , but the latest commit tries to implement the first solution.

@mxandreas
Copy link
Contributor

videos to be sent as is if transcoding fails (either as a file or as the actual media)

If "as is" means that the video size/quality will not be affected, but we can still remove the sensitive pieces (like geolocation tags), then I think that's fine. However, I would send them as "file" to have some indication that the transcoding was not applied.

@jmartinesp jmartinesp force-pushed the fix/jme/timestamps-must-be-monotonically-increasing branch from 67839c4 to 98e1ef0 Compare April 25, 2025 13:43
@jmartinesp jmartinesp changed the title Use MonotonicTimelineInterpolator in video transcoder When transcoding a video fails, send it as a file Apr 25, 2025
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Apr 25, 2025
@jmartinesp jmartinesp force-pushed the fix/jme/timestamps-must-be-monotonically-increasing branch from 98e1ef0 to b7c7dbe Compare April 25, 2025 14:01
@jmartinesp jmartinesp marked this pull request as ready for review April 25, 2025 14:03
@jmartinesp jmartinesp requested a review from a team as a code owner April 25, 2025 14:03
@jmartinesp jmartinesp requested review from ganfra and removed request for a team April 25, 2025 14:03
@ganfra
Copy link
Member

ganfra commented May 12, 2025

@jmartinesp what are we doing with that?

@jmartinesp
Copy link
Member Author

@jmartinesp what are we doing with that?

It's now ready for review (I just remembered we had to add a mime-type change). If the video can't be sent as a video it'll be sent as a file, as the description says. I think it matches what Andreas said above.

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, maybe we should add some test on the VideoCompressor class?

@jmartinesp
Copy link
Member Author

jmartinesp commented May 13, 2025

LGTM, maybe we should add some test on the VideoCompressor class?

Actually, that's going to be difficult since that's where we're actually performing the video transcoding. Maybe I can extract the transcoding configuration logic somewhere else and test that instead.

@jmartinesp jmartinesp enabled auto-merge (squash) May 13, 2025 10:48
Copy link

@jmartinesp jmartinesp merged commit c9ec26f into develop May 13, 2025
29 checks passed
@jmartinesp jmartinesp deleted the fix/jme/timestamps-must-be-monotonically-increasing branch May 13, 2025 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Videos fail to send
4 participants