Repository navigation
feat(presets): a size limit, and ready-made presets for email, Discord, WhatsApp and Instagram (#553) - #567
cre8ive-marketing wants to merge 3 commits into
Conversation
…nifeLemon#553) Pictures and videos get a "Size limit (MB)". A picture over it is saved again at a lower quality (down to 50), then smaller, until it fits. A video over it is encoded again from the source at the bitrate its length allows, twice at most. When it can't fit, the file is refused with a reason rather than handed over too large. Only the step that writes the result sees the limit. Settings → Presets → New now offers an empty preset or a copy of a ready-made one: video for email (18 MB), Discord (10 MB), WhatsApp (720p, 16 MB) and a photo for Instagram (JPG, 1080 px wide). They aren't in the library or on a donut: no settings migration.
|
@KnifeLemon, CI is green on every check here. When you have reviewed it, could you merge it into main? |
KnifeLemon
left a comment
There was a problem hiding this comment.
Thanks @cre8ive-marketing, this follows the #553 decision exactly: the ready-made presets are only in the New menu, there's no migration and nothing goes on the donut. Stripping the limit from every step but the last in JobQueue is the right call. Both of your choices are right: 18 MB for email (once a megabyte is 1,000,000 bytes, point 3), and 1080 px wide for Instagram, since that's what Instagram uses for square, 4:5 and landscape, and ResizeMode.Width never upscales.
- The limit is silently ignored on several routes where the field is shown. It's only applied in
ImageEncoder.Write(single frames) and the plainFfmpegConverterpath. It does nothing for HEIC (shows the field but is written byHeicWriter,FfmpegConverter.cs:129); CAD and 3D renders to JPG/WebP (CadConverter.cs:127,ModelConverter.cs:168); animated WebP and multi-page files (ImageEncoder.cs:399); "Remove metadata" MP4 → MP4 (FfmpegConverter.cs:154, which returns before fitting); Merge videos and Video from images (JobQueue.cs:462); VOB and DV (a fixed-b:vor no rate argument forAtBitrateto replace). The PR promises a failure rather than handing over a file that breaks the limit, so please add one check after the last step inJobQueue: if an output is overMaxSizeMb, fail it witherror.over_size_limit. Also hide the field where nothing can fit it (joins,vob/dv), or fit those routes as well. - Video: one encode, not up to three, and keep the progress bar moving. Today a file over the limit is encoded in full at CRF, then once or twice more at a bitrate (
FfmpegConverter.cs:196,:230), and those runs passprogress: null, so the bar sits at the end for minutes. WhenMaxSizeMb > 0and the duration is known, add-maxrate {kbps}k -bufsize {2×kbps}kto the first pass next to the CRF: one encode, never larger than the plain CRF result, and usually within the limit. Keep the bitrate re-encode only as the fallback, with progress. WhenFitBitrateKbpsreturns 0, refuse before encoding anything ("an hour in 10 MB" currently encodes the whole film first). - MB should be 1,000,000 bytes.
ImageEncoder.cs:420andFfmpegConverter.cs:217useMaxSizeMb * 1024 * 1024. Filee shows sizes in decimal MB, and so do the services: with MiB, "18 MB" is 18.87 MB, about 25.8 MB after base64, so it bounces at 25 MB. The same goes for WhatsApp 16 and Discord 10. The error detail (/ 1048576.0) should use the same unit. - Pictures have no pixel floor. After quality 50,
FitToSizeshrinks up to 8 more times, so a large photo with a tight limit can come back as a thumbnail and count as fitted. Please stop shrinking below a sensible size (for example a long edge of 640 px, or a quarter of the original) and refuse there. - Small fixes:
Preset.cs:613still says "email 20";PresetsPage.axaml:26-29hard-codes the four menu items toPlacePresets[0..3], so generating them fromPlacePresetswould keep the menu in step if the list changes.
…cimal MB From the review of KnifeLemon#567: - The queue checks every result against the preset's limit after the last step, and after a join, and refuses one that's over (HEIC, CAD and 3D renders, animations, pages, Remove metadata). The video field is hidden for joins, slideshows, VOB and DV. - Video: one encode, its bitrate capped (-maxrate / -bufsize) at what the length allows next to the CRF. The video is never copied as-is with a limit, and a second encode at a lower bitrate runs only if the first missed, on the last tenth of the progress bar. When nothing fits, it's refused before anything is encoded. - MB is 1,000,000 bytes (SizeLimit.Bytes), in the error detail too. - Pictures stop shrinking at a long edge of 640 px (or their own) and are refused there, never made a thumbnail. - The New menu is filled from PlacePresets; the "email 20" comment says 18. German strings for the new keys (KnifeLemon#541).
|
@KnifeLemon, thanks for the review. All five points are in, pushed as 87cfb1e, with main merged in:
German strings for the new keys are included, since #541 came in on main. New tests:
Full |
|
@KnifeLemon, CI is green on every check after the review fixes. Could you take another look and merge it into main if it is good? |
Part 1 of #553, as approved: the ready-made presets are only in the Add list, with no migration, no schema change and nothing on the default donut.
What it does
Size limit (MB) on a preset, one field for pictures (next to Quality) and one for videos (with the other video options). 0 = no limit.
ImageEncoder.FitToSize).-b:v. An MP4 that Balanced would have copied as it is gets encoded too.Settings → Presets → New is now a menu: Empty preset, or a copy of a ready-made one:
Two choices that differ from the plan, for you to check:
Each Add makes a new preset with its own id, so it can be added twice and changed freely. The names are translated (
NameKey). New strings are in all 16 languages.Tests
SizeLimitTests(Engines):-b:v 0turned into a bitrate;SizeLimitTests(Core): only the last step of a two-engine route gets the limit; the ready-made presets are offered but not in the library.RenderTests.Add_offers_presets_for_where_a_file_goes_and_the_editor_keeps_their_size_limit(en, ru): Add makes two separate copies; the editor shows and saves the limit, and drops it for a target where it isn't shown. It also saves the screenshot above.dotnet format --verify-no-changesis clean.dotnet test: Platform 81, Core 604, CLI 27, Setup 176, Engines 1828 and App 1346 pass, none fail.Part of #553 (Undo is #564).