Skip to content

[Regression] Bring back original video quality option, handle attributes correctly#30393

Merged
john-preston merged 2 commits intotelegramdesktop:devfrom
comdev1337:fix-media-player-original-quality
Apr 19, 2026
Merged

[Regression] Bring back original video quality option, handle attributes correctly#30393
john-preston merged 2 commits intotelegramdesktop:devfrom
comdev1337:fix-media-player-original-quality

Conversation

@comdev1337
Copy link
Copy Markdown
Contributor

@comdev1337 comdev1337 commented Mar 4, 2026

Fixes #29780
Fixes #30407
Fixes: a bug (?) where the video quality text (SD/HD/4K) is not displayed on the gear button if a video has no alt_documents (only speed options are available in the dropdown).

Summary

This PR aims to help the minor subset of users with a functioning eyesight by restoring the original video quality option in the media player. The original stream is included as the second option (consistent with the ordering in the Android client).

Example video. Observe: wheels turn into slop when 1080p is selected.

tg_original_quality_h264.mp4

Example video. Handling wrong attributes correctly. We now have a 1080p stream!

tg_original_wh_fix.mp4

Implementation

  • Upon resolving video qualities, the original quality is added to the array with a 1000000 integer offset (Media::kVideoQualityOriginalOffset). This eliminates resolution ambiguity between an original 1080p stream and a sloppy 1080p.
  • The settings deserializer has been updated to accept values up to 1004320 to ensure the "Original" quality preference persists across restarts.
  • Tie-Breaker Fix: Fixed an edge case in chooseQuality() where selecting the transcoded 1080p option selects the original 1080p, if the transcoded stream size is over the original file size, due to
if (abs == closestAbs && quality->size < closestSize)
  • Get video dimensions from ffmpeg directly (realsize), do not rely on attributes whenever possible.

Tried throwing a bunch of different videos at it. Works on my machine.

@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch 2 times, most recently from 34f96b9 to 305af70 Compare March 5, 2026 13:03
Comment thread Telegram/SourceFiles/data/data_document.cpp Outdated
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 305af70 to d2696d6 Compare March 5, 2026 17:30
Comment thread Telegram/SourceFiles/data/data_document.cpp Outdated
Comment thread Telegram/SourceFiles/media/player/media_player_button.cpp Outdated
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from d2696d6 to a0026be Compare March 5, 2026 18:27
Comment thread Telegram/SourceFiles/data/data_document.cpp Outdated
Comment thread Telegram/SourceFiles/media/player/media_player_dropdown.cpp Outdated
Comment thread Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp Outdated
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch 3 times, most recently from 501968b to 14dab6f Compare March 6, 2026 13:27
Comment thread Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp Outdated
}
const auto overrideDuration = _stories
|| (_chosenQuality && _chosenQuality != _document);
const auto durationDocument = (_chosenQuality && _chosenQuality != _document)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

_chosenQuality != _document)

Does it really make sense?

Copy link
Copy Markdown
Contributor Author

@comdev1337 comdev1337 Mar 6, 2026

Choose a reason for hiding this comment

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

This is necessary. We do not want to rely on the provided duration attribute, which might be fake.

See: https://t.me/cursedvideofiles/7

If you open the 720p or 480p stream in 6.6.2, you'll end up with

  1. fake duration
  2. video player dimensions change according to fake w, h attributes

I aim to resolve these 2 issues:
image

Comment thread Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp Outdated
Comment thread Telegram/SourceFiles/media/player/media_player_dropdown.cpp Outdated
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch 2 times, most recently from a2e44ea to 9621d03 Compare March 6, 2026 18:50
@comdev1337
Copy link
Copy Markdown
Contributor Author

comdev1337 commented Mar 6, 2026

Made the player more resistant against incorrect width, height, duration attributes. Unfortunately, fake w, h are common.

  • The player should now correctly adjust the size per the stream selected.
  • The player accounts for weird edge cases (like non-square SAR) when extracting the height for the original doc.

Put some edge cases the current player doesn't account for in https://t.me/cursedvideofiles

Should fix #30407

@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 9621d03 to 899ded0 Compare March 8, 2026 13:15
@comdev1337 comdev1337 changed the title [Regression] Bring back original video quality option [Regression] Bring back original video quality option, handle attributes correctly Mar 9, 2026
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 899ded0 to 580eb8b Compare March 15, 2026 22:29
Comment thread Telegram/SourceFiles/data/data_document.cpp Outdated
Comment thread Telegram/SourceFiles/media/player/media_player_dropdown.cpp Outdated
Comment on lines +65 to +66
// Propagate physical resolution parsed from the stream
to.realSize = from.realSize;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Physical? 😨

Copy link
Copy Markdown
Contributor Author

@comdev1337 comdev1337 Mar 20, 2026

Choose a reason for hiding this comment

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

Physical as in the stream resolution as reported by ffmpeg, as opposed to size which is adjusted for SAR.
I can rename it to smth like "encoded resolution" if that makes more sense?

@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 580eb8b to 6153758 Compare March 20, 2026 14:46
@FishOrBear
Copy link
Copy Markdown

I tested this PR, and the results are excellent. Previously, the system would generate an AV1-encoded video, which caused the video playback to freeze; now, it utilizes the original video (H.264), thereby preventing the freezing issue.

@john-preston
Copy link
Copy Markdown
Member

I'll rewrite it, but thanks.

@john-preston
Copy link
Copy Markdown
Member

ah. now conflicts , sorry @comdev1337, fix please

@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 6153758 to 32532a8 Compare April 17, 2026 23:39
@comdev1337
Copy link
Copy Markdown
Contributor Author

@john-preston fixed

@comdev1337
Copy link
Copy Markdown
Contributor Author

@FishOrBear

Previously, the system would generate an AV1-encoded video, which caused the video playback to freeze; now, it utilizes the original video (H.264)

This may still be an issue if you select a transcoded stream. I believe the client prioritizes fetching av01 over h264 for these.

@john-preston john-preston merged commit 827ec82 into telegramdesktop:dev Apr 19, 2026
14 checks passed
@FishOrBear
Copy link
Copy Markdown

@FishOrBear

Previously, the system would generate an AV1-encoded video, which caused the video playback to freeze; now, it utilizes the original video (H.264)

This may still be an issue if you select a transcoded stream. I believe the client prioritizes fetching av01 over h264 for these.

Yes, now I just need to select the original video.

It would be helpful to improve the video quality selection button by displaying the video's encoding format and file size; this would make debugging much easier. This is how it works on Telegram for Android.

@comdev1337
Copy link
Copy Markdown
Contributor Author

comdev1337 commented Apr 20, 2026

It would be helpful to improve the video quality selection button by displaying the video's encoding format and file size; this would make debugging much easier. This is how it works on Telegram for Android.

The Android client doesn't display the codec, from what I can see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Video player follows incorrect attributes for scaling, duration No original video quality option in the video player dropdown

5 participants