Skip to content

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

Open
comdev1337 wants to merge 1 commit intotelegramdesktop:devfrom
comdev1337:fix-media-player-original-quality
Open

[Regression] Bring back original video quality option, handle attributes correctly#30393
comdev1337 wants to merge 1 commit 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
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from 305af70 to d2696d6 Compare March 5, 2026 17:30
@comdev1337 comdev1337 force-pushed the fix-media-player-original-quality branch from d2696d6 to a0026be Compare March 5, 2026 18:27
Comment on lines +862 to +865
auto displayHeight = now.height;
if (displayHeight >= Media::kVideoQualityOriginalOffset) {
displayHeight -= Media::kVideoQualityOriginalOffset;
}
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.

The same.

Copy link
Copy Markdown
Contributor Author

@comdev1337 comdev1337 Mar 5, 2026

Choose a reason for hiding this comment

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

Updated everything to be <79, replaced with const auto, ?:

Comment on lines +4776 to +4780
if (quality == _document) {
result.push_back(Media::kVideoQualityOriginalOffset + quality->resolveVideoQuality());
} else {
result.push_back(quality->resolveVideoQuality());
}
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.

?:

Copy link
Copy Markdown
Contributor Author

@comdev1337 comdev1337 Mar 5, 2026

Choose a reason for hiding this comment

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

Replaced with ?:

@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 on lines +4279 to +4280
const auto weak = base::make_weak(_widget);
crl::on_main(weak, [=] {
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.

Suggested change
const auto weak = base::make_weak(_widget);
crl::on_main(weak, [=] {
crl::on_main(_widget, [=] {

?

}
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

const auto value = (quality == _document)
? (res + Media::kVideoQualityOriginalOffset)
: res;
if (std::find(seen.begin(), seen.end(), value) == seen.end()) {
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.

Suggested change
if (std::find(seen.begin(), seen.end(), value) == seen.end()) {
if (ranges::find(seen, value) == seen.end()) {

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.

Oh.
Even ranges::contains.

const auto text = !quality
? automatic
: (quality >= offset)
? u"Original (%1p)"_q.arg(quality - offset)
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.

(quality - offset)

Maybe some std::clamp, idk...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added clamp up to 4320

@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
}
}
const auto apiSize = isVideoFile() ? dimensions : QSize();
const auto api = apiSize.isEmpty()
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.

Such names should not be here.

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.

replaced these

*/
#include "media/player/media_player_dropdown.h"

#include <algorithm>
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.

Suggested change
#include <algorithm>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

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
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

2 participants