Skip to content

Let --resolution take just a height or a percentage - #144

Merged
zfleeman merged 2 commits into
mainfrom
zf/resolution-height
Nov 6, 2026
Merged

zfleeman merged 2 commits into
mainfrom
zf/resolution-height

Conversation

@zfleeman

@zfleeman zfleeman commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #137.

-r used to take only WIDTHxHEIGHT, so shrinking a clip meant working out a width that keeps the aspect ratio, and doing it again after a crop. Now -r takes three forms:

-r 1920x1080 input Notes
1280x720 1280x720 Same as before
720 1280x720 The width follows the height
50% 960x540 A percentage of the height, rounded to an even number

The new forms use ffmpeg's scale=-2:<height>. The -2 makes ffmpeg pick the width that keeps the aspect ratio, rounded to an even number, which x264 and x265 need. The scale runs after the crop, so with -x the height and the percentage apply to the cropped area.

Changes

  • twopass.py: a new TwoPass._scale_size() turns -r into the scale filter's width and height. _check_video_size() and _apply_video_filters() both use it instead of splitting WIDTHxHEIGHT themselves. A Resolution in any other format (like 720p, 0, or 0%) now raises a clear ValueError instead of an int() error. An odd height like -r 721 raises the existing even-size error for x264 and x265. The aspect-ratio warning only applies to WIDTHxHEIGHT, since the other forms always keep the ratio.
  • __main__.py: RESOLUTION_PATTERN and its error message accept the new forms.
  • web.html: the Resolution field's browser-side check accepts them, rejects 0 and 0%, and shows the hint "e.g. 1280x720, 720, or 50%".
  • README.md: the -r row lists all three forms, and the Detailed Example notes that -r 1080 or -r 75% would have done the same job.

Checked

Real x264 encodes of 5 seconds of a 1920x1080, 60 fps Call of Duty clip:

Flags Output
-r 1280x720 1280x720
-r 720 1280x720
-r 50% 960x540
-r 33% 632x356
-x 240x0x1440x1080 -r 50% 720x540
-r 721 "x264 needs an even width and height, but the Resolution (-r) is 721."
-r 720p "Invalid Resolution (-r) '720p'. Use width x height, a height, or a percentage of the height, ..."

Tests

  • test_twopass.py: scale arguments for each form, a percentage with a crop, odd-height rounding for 33%, no aspect warning for a height, and errors for odd heights (x264/x265 only) and bad formats.
  • test_main.py: the web form accepts 1280x720, 720, 50%, and 33.3%, and rejects 720p and 0%.

@zfleeman
zfleeman merged commit 750d11f into main Nov 6, 2026
6 checks passed
@zfleeman
zfleeman deleted the zf/resolution-height branch November 6, 2026 17:19
@zfleeman zfleeman mentioned this pull request Nov 6, 2026
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.

Let --resolution take just a height or a percentage

1 participant