Skip to content

feat(presets): video size limit in MB or as a percentage of the original file - #883

Merged
KnifeLemon merged 26 commits into
KnifeLemon:mainfrom
gianabif14:feat/video-size-percent
Oct 31, 2026
Merged

KnifeLemon merged 26 commits into
KnifeLemon:mainfrom
gianabif14:feat/video-size-percent

Conversation

@gianabif14

Copy link
Copy Markdown
Contributor

A video preset's Size limit can now be specified either in MB (as before) or as a % of the original file (1–99%).

  • Preset editor: In the Video card, follows feat(presets): image file size as a range in KB or MBΒ #791's pattern for pictures with a single numeric box and a unit selector (MB | %). Switching between units preserves each value separately so switching units does not silently convert numbers.
  • Settings & compatibility: Adds MediaOptions.MaxSizePercent (default 0 = off). Existing presets remain completely unchanged without needing a settings migration step. Only one limit is active at a time.
  • Target limits: Supports 1–99%, enforced only for video targets (MediaEncoding.VideoTargets), not audio or GIF.
  • Encoding path: Reuses the existing FfmpegConverter and MediaEncoding.ForSizeLimit capped-bitrate encoding and fit-again mechanism; impossible percentages are refused before encoding starts with error.over_size_limit.
  • Localization: Added presets.size_limit across all 19 i18n/*.json catalogs.
  • Tests & Docs: Added unit and integration tests (percentage byte calculations, intermediate step resets, real FFmpeg tests, refusal on impossible percentages, and UI unit-switch tests) and documented the option in docs/ENGINES.md.

Closes #680

Screenshots

Size limit in % Size limit in MB
Size limit in % Size limit in MB

@github-actions github-actions Bot added the feature New features label Oct 31, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @gianabif14, this is a clean piece of work: intermediate steps drop the limit, CanCopyVideo honours %, the refusal happens before encoding, and the FFmpeg tests use real files. A few things before it goes in.

1. Switching MB β†’ % can turn a large MB value into 99 %

PresetEditorViewModel.OnVideoSizeUnitChoiceChanged raises VideoSizeMaximum (4096 β†’ 99) before VideoMaxSize.

  • At that moment the box still shows the MB value. With 500 MB, the NumericUpDown cuts it to its new maximum, 99.
  • It writes 99 back through the VideoMaxSize setter, which already routes to VideoMaxSizePercent. The preset would save 99 % although the user never typed it.

That is the case the image units guard against in OnImageSizeUnitChanged: "The boxes' maximum is raised before the values grow and lowered after they shrink, so a box never cuts a value to the other unit's maximum." The same order would fix it here:

  • going to %: notify VideoMaxSize first, then VideoSizeMaximum;
  • going to MB: notify VideoSizeMaximum first, then VideoMaxSize.

Video_size_unit_switch_keeps_each_value_separately starts from 25 MB, which is under 99, so it can't see this. Please add a case with 100 MB or more.

2. A % limit is ignored for joined videos

  • Merge videos checks the result with SizeLimit.Check(job.Preset, [output]) (JobQueue.cs, around line 542), without a source path.
  • ForVideo(media, sourcePath: null) then falls back to MaxSizeMb, which Apply set to 0. So a merged video gets no limit at all, silently.

Either take the % of all joined sources together, or refuse % for joins with a clear message. Both are fine; silently ignoring it isn't.

3. A missing source also means no limit

SizeLimit.ForVideo(media, string? sourcePath) returns 0 when the source file isn't there. A % that can't be measured should rather be refused (error.over_size_limit or a short new message) than turn into "no limit".

4. Small things

  • presets.max_size ("Size limit (MB)") isn't used anywhere now, but it's still in all 19 language files. Please remove it.

Once 1–3 are in, I'm happy to merge.

…oins

- Prevent large MB values from clamping to 99% when switching unit
- Enforce percentage size limit on joined videos based on combined source size
- Refuse unmeasurable percentage limits when source file is missing instead of ignoring
- Add unit tests for unit switching, combined sources, and missing source handling
@gianabif14
gianabif14 force-pushed the feat/video-size-percent branch from 5162952 to ca484bc Compare October 31, 2026 17:07
@gianabif14

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @KnifeLemon! I've pushed the fixes for all the items you mentioned (1-4). Let me know if it needs any further adjustments

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @gianabif14, all four points are in:

  1. Unit switch: the box's maximum now moves on the right side of the value, and the 500 MB case covers it.
  2. Joined videos: % is taken of the joined sources together.
  3. Missing source: a % that can't be measured is refused instead of becoming "no limit".
  4. presets.max_size is gone from all 19 files.

CI is green. Merging. πŸŽ‰

@KnifeLemon
KnifeLemon merged commit ae07ee2 into KnifeLemon:main Oct 31, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Compressing any video to the desired size in MB according to your requirements.

2 participants