Skip to content
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

Consider object-fit when selecting playlist by player size #1051

Merged
merged 6 commits into from
Feb 5, 2025

Conversation

tf
Copy link
Contributor

@tf tf commented Jan 25, 2021

Description

So far, when limitRenditionByPlayerDimensions is true,
simpleSelector tried to either find a rendition with a resolution
that matches the size of the player exactly or, if that does not
exist, a rendition with the smallest resolution that has either
greater width or greater height than the player. This makes sense
since by default the video will be scaled to fit inside the media
element. So every resolution that exceeds player size in at least one
dimension will be scaled down.

Most browsers support customizing this scaling behavior via the
object-fit CSS property. If it set to cover, the video will
instead be scaled up if video and player aspect ratio do not match.

The previous behavior caused renditions with low resolution to be
selected for players with small width (e.g. portrait phone aspect
ratio) even when videos were then scaled up to cover the whole player.

We therefore detect if object-fit is set to cover and instead
select the smallest rendition with a resolution that exceeds player
dimensions in both width and height.

Specific Changes proposed

The first two commits are preparatory refactorings. The third commit contains the change itself.

Requirements Checklist

  • Feature implemented
  • If necessary, more likely in a feature request than a bug fix
    • Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (see comment below)
  • Reviewed by Two Core Contributors

@welcome
Copy link

welcome bot commented Jan 25, 2021

💖 Thanks for opening this pull request! 💖

Things that will help get your PR across the finish line:

  • Run npm run lint -- --errors locally to catch formatting errors earlier.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@tf
Copy link
Contributor Author

tf commented Jan 25, 2021

Both CI_TEST_TYPE=playback npm run test and CI_TEST_TYPE=unit npm run test pass locally. Not sure if failure of playback test in CI is related.

@tf
Copy link
Contributor Author

tf commented Jan 25, 2021

Regarding docs: A note about the feature could be added to the docs of limitRenditionByPlayerDimensions in the readme. The bitrate switching guide also seems relevant, feels a bit outdated already, though.

@tf
Copy link
Contributor Author

tf commented Jan 25, 2021

Here's an example showcasing the new behavior using a build that includes the changes from the PR branch.

https://jsbin.com/wuxabonezo/1/edit?html,output

@tf
Copy link
Contributor Author

tf commented Feb 19, 2021

Could somebody take a look at this PR?

src/playlist-selectors.js Show resolved Hide resolved
src/playlist-selectors.js Show resolved Hide resolved
test/playlist-selectors.test.js Outdated Show resolved Hide resolved
src/playlist-selectors.js Outdated Show resolved Hide resolved
@tf tf force-pushed the object-fit-selector branch from 4dc68f6 to d63a062 Compare March 2, 2021 08:48
Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

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

I also see the tests failing due to a linter error here, not sure why it would fail in scripts/index-demo-page.js as you didn't make any changes there. Perhaps a rebase would fix that?

src/playlist-selectors.js Outdated Show resolved Hide resolved
test/playlist-selectors.test.js Outdated Show resolved Hide resolved
@tf tf force-pushed the object-fit-selector branch 2 times, most recently from c395d50 to 00ebda7 Compare March 2, 2021 15:54
@tf
Copy link
Contributor Author

tf commented Mar 2, 2021

Changed the test case to use the original value again. Rebased onto main for linting fix.

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the outdated label Jun 26, 2021
@gkatsev gkatsev removed the outdated label Jul 2, 2021
@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Copy link
Contributor

@adrums86 adrums86 left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable addition. I think we should get this into the main branch.

tf added 4 commits January 17, 2024 06:22
Refactor from positional parameters to a single `settings`
argument. This makes it clearer what each argument means in calls of
the function. Additional parameters can now be added without making
the argument list overly long.

Key names were chosen to match those of
`minRebufferMaxBandwidthSelector` to align the signatures.
Inline the passed bandwidth value instead of referencing the config
constant since the concrete value is needed to understand why the
expected playlist is chosen. Also if the config constant should ever
change the test will fail for no good reason.
So far, when `limitRenditionByPlayerDimensions` is `true`,
`simpleSelector` tried to either find a rendition with a resolution
that matches the size of the player exactly or, if that does not
exist, a rendition with the smallest resolution that has either
greater width or greater height than the player. This makes sense
since by default the video will be scaled to fit inside the media
element. So every resolution that exceeds player size in at least one
dimension will be scaled down.

Most browsers support [1] customizing this scaling behavior via the
`object-fit` CSS property [2]. If it set to `cover`, the video will
instead be scaled up if video and player aspect ratio do not match.

The previous behavior caused renditions with low resolution to be
selected for players with small width (e.g. portrait phone aspect
ratio) even when videos were then scaled up to cover the whole player.

We therefore detect if `object-fit` is set to `cover` and instead
select the smallest rendition with a resolution that exceeds player
dimensions in both width and height.

[1] https://caniuse.com/?search=object-fit
[2] https://developer.mozilla.org/de/docs/Web/CSS/object-fit
Only consider `object-fit` CSS property when selecting playlists based
on play size when `usePlayerObjectFit` option is `true` to make new
behavior an opt-in.
@tf tf force-pushed the object-fit-selector branch from 00ebda7 to c6ea01a Compare January 17, 2024 05:50
@tf
Copy link
Contributor Author

tf commented Jan 17, 2024

Rebased onto main. Updated jsbin showcasing the new behavior using the latest version of Video.js:

https://jsbin.com/vipikadeni/edit?html,output

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.00%. Comparing base (c1d3186) to head (4b5a9d9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1051   +/-   ##
=======================================
  Coverage   83.99%   84.00%           
=======================================
  Files          44       44           
  Lines       11700    11707    +7     
  Branches     2618     2623    +5     
=======================================
+ Hits         9827     9834    +7     
  Misses       1873     1873           

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

@dzianis-dashkevich dzianis-dashkevich merged commit 2c52076 into videojs:main Feb 5, 2025
7 checks passed
Copy link

welcome bot commented Feb 5, 2025

Congrats on merging your first pull request! 🎉🎉🎉

@dzianis-dashkevich
Copy link
Contributor

@tf thanks! < 5 years :)

@tf tf deleted the object-fit-selector branch February 5, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants