Greasy Fork

Zoom and crop YouTube videos to fill screen height

Removes letterboxing by cropping the left and right edges off of full-screen YouTube videos and zooming to fill the screen height.

当前为 2019-01-05 提交的版本,查看 最新版本

作者
uxamend
评分
0 0 0
版本
0.4
创建于
2018-12-18
更新于
2019-01-05
大小
4.0 KB
兼容性
与 Firefox 兼容 与 Chrome 兼容
许可证
CC0-1.0
适用于

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.

How it works

This script adds an event listener for the fullscreenchange event. When the video goes full-screen, and after a short delay to allow things to settle down, the script will adjust the dimensions of the video element so that it fills more of the screen height and is wider than the screen, so that any excess video width falls outside the screen (i.e. gets cropped off). Video ads can cause the video to return to its default dimensions, so the script also watches for ad playback and re-resizes the video at the start and end of each ad.

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.

Known Issues

  • Sometimes, under Chrome, the end of ad playback is not detected and so the video does not get zoomed. As this is an intermittent fault and ads can't be summoned on demand for testing purposes, it is hard to debug. Manually exiting and re-entering full-screen can be used as a workaround to trigger the application of zoom. The issue does not seem to be present under Firefox. Since the author uses Firefox ordinarily, this issue will probably not receive much attention.

  • 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 play back at 1920x960 instead of 2160x1080, even though the resolution is labelled as 1080p. On some combinations of video, hardware, and internet connection, it is possible to work around this by selecting a higher resolution (e.g. 1440p). In some cases, the user's sense of sight may provide sufficient tolerance to mask the effect.

  • On slow machines, it's possible that the script may not work properly, because the hard-coded delay before applying zoom is insufficient to allow YouTube's standard scripts to finish executing. A fix or workaround for this issue will be implemented in a future update.

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.