Background
It's now relatively common for YouTube videos to have aspect ratios wider than 16:9, such as 18:9 or other "ultrawide" or cinema aspects. By default, if these are played full-screen on a display with a narrower aspect ratio, they are letterboxed with horizontal black bars at the top and bottom. Depending on circumstances, video content and user preference, this might be annoying. It might be preferable to fill the screen height and crop off the sides of the video instead.
The same issue arises when watching ordinary 16:9 videos on a 16:10, 5:4, 4:3 or other narrower aspect ratio display. This script is targeted at both use cases.
How it works
When the video goes full-screen, and thereafter each time the video element on the page 'mutates', the script will adjust the dimensions of the video element. It will be adjusted so that it fills more of the screen height and is wider than the screen. Any excess video width falls outside of the edge of the screen (i.e. it gets cropped off). Upon leaving fullscreen, the script stops applying zoom and stops watching for video element mutations.
To disable the zoom, disable the script and reload the page.
If you have a screen narrower than 16:10, by default the script will still apply some letterboxing to avoid large amounts of cropping. If this is not desirable, edit the script to change the definition of min_cropped_aspect
.
- If you set
min_cropped_aspect
to a value less than or equal your screen aspect ratio, then no letterboxing will occur.
- Conversely, if you set
min_cropped_aspect
to a value greater than your screen aspect ratio, then videos wider than your screen will be zoomed and cropped so that the visible portion of the video frame has the specified aspect ratio.
If you find that particularly wide videos are being cropped too much, try editing the definition of max_crop_proportion
to specify what proportion of the width of a video you are prepared to lose to cropping. By default, no limit is set.
Compatibility
The script should work with any screen aspect ratio. Contrary to the name of the script, for screens narrower than 16:10, the video is cropped to a letterboxed 16:10 by default. If you want the video to fill the screen height regardless, set min_cropped_aspect
to your screen aspect ratio.
This script probably requires a relatively recent browser version. It may work in browsers other than Firefox and Chrome, but that is untested.
It is for the current (not classic) version of YouTube, as of December 2018.
N.B. This script does not do anything to fix videos with 'baked-in' letterboxing, where the video itself contains the black bars.
Known Issues
It appears that YouTube's video resolutions are optimised for letterboxed playback. So, for example, an 18:9 video, zoomed and cropped to fill a 1920x1080 16:9 screen, will have a resolution of 1920x960 instead of 2160x1080, even though the resolution is labelled as 1080p. If the video is available in resolutions higher than that of your screen and your hardware and internet connection can handle it, then it is possible to work around this by selecting a higher resolution (e.g. 1440p). Alternatively, many people (the author being among them) may not find this to be a problem in the first place, whether through poor eyesight or high tolerance for fuzzy-looking video.
In versions below 0.5, sometimes the end of ad playback did not trigger the zoom. Manually exiting and re-entering full-screen could be used as a workaround to trigger the application of zoom. Fixed in version 0.5.
In versions below 0.5, zoom was not applied when replaying a video, skipping back into the video after the video ends, jumping directly to a new video without exiting full-screen mode, or going into full-screen mode before the video had actually loaded. Fixed in version 0.5.
In versions below 0.5, there was general intermittent unreliability. Hopefully much improved in 0.5.
Version history
0.1. First release. Probably full of bugs and stupid mistakes.
0.2. Fix incompatibility with Chrome.
0.3. Added min_cropped_aspect
and max_crop_proportion
parameters. Changes default behaviour for screens narrower than 16:10.
0.4. Bug fix: don't just match /watch pages, as it's possible to reach them from other YouTube pages without a page load occurring.
0.5. Redesigned to trigger on changes to the video element, to improve reliability and remove bugs.