@ponderdev/justfits 0.0.0-stage → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,159 @@
1
- # Temporary Holding Version
1
+ # Just Fits
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Makes a video small enough to send. Point it at a file, pick a limit, and it
4
+ compresses to land just under that limit. Everything happens on your machine.
5
+
6
+ Built because "compress for Discord" is a thing everyone needs and every
7
+ existing answer is either a website you upload your footage to, or a wall of
8
+ ffmpeg flags you have to get right yourself.
9
+
10
+ ## How it decides
11
+
12
+ Hitting an exact size is arithmetic, not guesswork:
13
+
14
+ 1. Read the duration, resolution, frame rate and whether there is sound.
15
+ 2. Turn the target size into a total bitrate, minus 5 percent, because mp4
16
+ spends a little on overhead the bitrate maths cannot see.
17
+ 3. Give sound the smallest share that still sounds like sound. Speech stays
18
+ intelligible far below the point where picture falls apart, so audio gives
19
+ way first, and drops to mono before it drops below 48kbps.
20
+ 4. Give the rest to picture, then pick the largest frame size that still gets
21
+ enough bits per pixel to look like the source. Frame rate halves before the
22
+ resolution collapses.
23
+ 5. Encode in two passes, which is precisely what two-pass is for.
24
+ 6. Measure what actually came out. x264 overshoots on hard footage, so if it
25
+ missed, correct by the measured amount and go again. Three attempts.
26
+
27
+ All of that lives in `src/plan.js` as pure functions, with no ffmpeg and no
28
+ filesystem anywhere near it, because whether your file comes in under the line
29
+ is the one thing this has to get right. `test/plan.test.cjs` covers it.
30
+
31
+ ## The presets
32
+
33
+ Checked August 2026, and they move, so they live in one list in `src/plan.js`
34
+ and the custom box is always there.
35
+
36
+ Discord is 10MB free, 50MB on Nitro Basic, 500MB on Nitro, and a level 3
37
+ boosted server gives everyone in it 100MB whether they pay or not.
38
+
39
+ The email presets aim lower than the number the provider advertises, because
40
+ attachments are base64 encoded in transit and that adds about 37 percent.
41
+ Gmail says 25MB and will bounce a 25MB file, so the Gmail preset targets 18.2MB.
42
+
43
+ ## The rules it follows
44
+
45
+ - **Your original is only ever read.** Output goes to `name-fits.mp4` beside
46
+ it, and never to a path that already exists.
47
+ - **Nothing is uploaded.** There is no network code in the app at all.
48
+ - **No account, no telemetry, no update checker.** The build you have is the
49
+ build you keep.
50
+ - GPL v3, like the ffmpeg build it carries.
51
+
52
+ ## Running it
53
+
54
+ ```sh
55
+ npm install
56
+ npm run fetch-ffmpeg # puts ffmpeg and ffprobe in vendor/
57
+ npm start
58
+ ```
59
+
60
+ ## The command line
61
+
62
+ ```sh
63
+ npm install -g @ponderdev/justfits
64
+ justfits clip.mp4 --to discord
65
+ ```
66
+
67
+ No dependencies and no bundled encoder, so the install is under 2MB. It uses
68
+ whatever ffmpeg is on your PATH, which on Linux is one package away
69
+ (`pacman -S ffmpeg`, `apt install ffmpeg`). The desktop app carries its own
70
+ copy instead, because someone downloading a finished app should not then be
71
+ told to install a video encoder.
72
+
73
+ Needs Node 22 or newer, and an ffmpeg with libx264 on the PATH (no minimum version has been tested).
74
+
75
+ ```sh
76
+ justfits clip.mp4 # beside it, as clip-fits.mp4 (a picture becomes clip-fits.jpg)
77
+ justfits clip.mp4 --to gmail # any preset, or a size like 25MB
78
+ justfits clip.mp4 -o small.mp4 # somewhere specific
79
+ justfits clip.mp4 --json # for scripting
80
+ cat clip.mp4 | justfits --to 8MB > small.mp4
81
+ ```
82
+
83
+ If the name is taken it writes `clip-fits 2.mp4`, then 3, and never over an
84
+ existing file. A file that is neither video nor picture is refused with a
85
+ sentence saying so (exit 1). With input from stdin and no `-o`, the result goes
86
+ to stdout.
87
+
88
+ Progress goes to stderr, so stdout stays clean to pipe. Piped input is buffered
89
+ to a temp file first and it says so: two-pass encoding reads the input twice
90
+ and a pipe cannot be rewound.
91
+
92
+ ### For scripts and assistants
93
+
94
+ - `--json` prints one JSON line per thing it did, then a `done` line: a
95
+ `result` (written), a `skip` (it already fit) or an `error`. Errors are JSON
96
+ too. When the video itself goes to stdout, the JSON goes to stderr instead.
97
+ - `--describe` prints every option, its type and default, the targets and the
98
+ exit codes, as JSON, so nothing has to be guessed from `--help`.
99
+ - `--dry-run` says what would happen and writes nothing.
100
+ - `--help`, `--version` and `--describe` answer at once and do nothing else.
101
+
102
+ Exit status: **0** done or already fits, **1** failed, **2** a bad option,
103
+ target or missing file (nothing was started), **4** still over the target
104
+ after every try. 129, 130 and 143 mean it was stopped, with part files removed.
105
+
106
+ **Changed in 1.2.0**, for anyone with a script from before: still over the
107
+ target is now 4 (it was 2, which is now a usage error), and `--json` ends with a
108
+ `done` line, so read the first line rather than parsing everything printed.
109
+ The fields in a result are the same as before.
110
+
111
+ The maths and the ffmpeg work are shared with the desktop app rather than
112
+ reimplemented, so both produce the same output for the same input.
113
+
114
+ ## Licences
115
+
116
+ GPL-3.0-or-later, like the ffmpeg build it carries. `THIRD-PARTY-NOTICES.md`
117
+ names every bundled component and how the terms are met; `licenses/` holds the
118
+ full texts; and both are readable from inside the app under **Licences and
119
+ credits** in the footer.
120
+
121
+ `npm run licences` regenerates that screen from those files, and the build
122
+ scripts run it first so a stale one cannot ship.
123
+
124
+ ## Tests
125
+
126
+ ```sh
127
+ npm test # the size arithmetic, instant
128
+ node test/cli.test.cjs # the command line, as a subprocess
129
+ npm run test:linux # the command line on real linux, in docker
130
+ node test/encode.test.cjs # real encodes, a minute or two
131
+ electron test/window.test.cjs # the window boots and renders
132
+ ```
133
+
134
+ `encode.test.cjs` builds its own footage, compresses it, and checks the result
135
+ is both under the limit and still playable. It also checks the original came
136
+ through untouched.
137
+
138
+ `test:linux` installs the published package into a Debian container, with that
139
+ distro's own ffmpeg, and runs the same checks. The CLI is headless so a
140
+ container is a real test of it. The GUI is not testable this way.
141
+
142
+ ## ffmpeg
143
+
144
+ `vendor/` is not in git: the binaries are large, they are not ours to
145
+ redistribute through our history, and they move on someone else's schedule.
146
+ `npm run fetch-ffmpeg` pulls them, `--all` gets every arch a release needs.
147
+
148
+ Any GPL build with libx264 works. If a host moves, drop the binaries in by
149
+ hand as `ffmpeg-x64`, `ffmpeg-arm64`, `ffprobe-x64`, `ffprobe-arm64`, or with
150
+ `.exe` on Windows. Nothing in the app cares where they came from.
151
+
152
+ **Apple Silicon** builds come from osxexperts.net, since evermeet publishes
153
+ x86_64 only. Those are checked against a published SHA256 before installing,
154
+ and the script refuses rather than installs on a mismatch. Note the published
155
+ hash is of the binary inside the zip, not of the zip.
156
+
157
+ ## Still to do
158
+
159
+ - test a packaged build on Apple Silicon and on Windows, on real hardware
@@ -0,0 +1,109 @@
1
+ # Third party notices
2
+
3
+ Just Fits is built on other people's work. This file records what it uses,
4
+ under what terms, and where to get the original source. Full licence texts are
5
+ in the `licenses/` folder and are also shown inside the app under
6
+ **Licences and credits** in the footer.
7
+
8
+ Just Fits itself is GPL-3.0-or-later. See `LICENSE`.
9
+
10
+ ---
11
+
12
+ ## FFmpeg
13
+
14
+ Does all of the actual work: reading the file, deciding nothing, and encoding
15
+ what it is told to. `ffprobe` from the same project reads the duration,
16
+ resolution, frame rate and stream layout that `src/plan.js` does its
17
+ arithmetic on.
18
+
19
+ - Project: <https://ffmpeg.org>, source at <https://github.com/FFmpeg/FFmpeg>
20
+ - FFmpeg's core is **LGPL v2.1 or later**. The builds shipped here are
21
+ configured with `--enable-gpl` and `--enable-version3`, which pulls in the
22
+ GPL-licensed parts and moves the whole binary to **GPL v3 or later**.
23
+ - Full text: `licenses/ffmpeg-license.txt`, and the GPL itself in
24
+ `licenses/gpl-3.0.txt`.
25
+
26
+ **On the command line, FFmpeg is not bundled at all.** The `justfits` command
27
+ uses whatever `ffmpeg` and `ffprobe` are on your PATH, so the terms that apply
28
+ are those of the build your system installed, not of anything shipped here.
29
+ Only the desktop app carries its own copy.
30
+
31
+ **The bundled binaries are not built here and are not modified.** They are
32
+ published builds, taken as-is:
33
+
34
+ | Platform | Source |
35
+ | --- | --- |
36
+ | macOS | [evermeet.cx/ffmpeg](https://evermeet.cx/ffmpeg/) |
37
+ | Windows | [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds) |
38
+
39
+ `scripts/fetch-ffmpeg.mjs` is what downloads them, and it is the complete
40
+ record of where they came from. To see exactly how the copy on your machine
41
+ was configured, including every library compiled into it:
42
+
43
+ ```sh
44
+ "/Applications/Just Fits.app/Contents/Resources/ffmpeg/ffmpeg-x64" -version
45
+ ```
46
+
47
+ ## x264
48
+
49
+ The H.264 encoder. Every video Just Fits produces comes out of it, and the
50
+ two-pass rate control that makes a file land on a target size is x264's.
51
+
52
+ - Project: <https://www.videolan.org/developers/x264.html>
53
+ - **Licence: GNU GPL v2 or later.** Full text: `licenses/gpl-2.0.txt`
54
+ - Compiled into the FFmpeg builds above, unmodified.
55
+
56
+ ## x265
57
+
58
+ The H.265 encoder. Compiled into the same builds. Just Fits does not currently
59
+ encode H.265, but the binary carries it, so it is listed.
60
+
61
+ - Project: <https://www.videolan.org/developers/x265.html>
62
+ - **Licence: GNU GPL v2 or later.** Full text: `licenses/gpl-2.0.txt`
63
+
64
+ ## Everything else inside FFmpeg
65
+
66
+ These builds also carry libopus, libvpx, libaom, libvorbis, libmp3lame,
67
+ libwebp, libass, dav1d, libtheora, libspeex and around twenty more, each under
68
+ its own terms, mostly BSD, LGPL or MIT. They are not listed individually here
69
+ because the list belongs to the build rather than to this app, and it changes
70
+ when the build does. `ffmpeg -version` prints the exact configuration of the
71
+ copy you have, which is the authoritative answer for your binary.
72
+
73
+ ## Electron
74
+
75
+ The application shell: Chromium for the window, Node for the file handling.
76
+
77
+ - Project: <https://www.electronjs.org>
78
+ - **Licence: MIT.** Electron bundles Chromium and Node.js, whose combined
79
+ licence text ships inside the app as `LICENSES.chromium.html`.
80
+
81
+ ---
82
+
83
+ ## Meeting the GPL terms
84
+
85
+ FFmpeg as shipped here is GPL v3. Distributing it inside an application carries
86
+ obligations, and Just Fits meets them like this:
87
+
88
+ 0. **Compatibility.** Just Fits is GPL-3.0-or-later, the same licence, so there
89
+ is no combination problem to solve.
90
+ 1. **Notice.** This file, plus the in-app credits screen, names each component
91
+ and its licence.
92
+ 2. **Licence texts.** Shipped in full, both in `licenses/` and inside the app.
93
+ 3. **Source.** Linked above. Nothing was modified for Just Fits; published
94
+ builds are used as-is, so the upstream source is the complete source.
95
+ 4. **Replacing them.** The binaries live in `vendor/ffmpeg` and are found by
96
+ name at runtime. Drop your own GPL build in with the same filenames and the
97
+ app uses it. Nothing is statically linked and nothing is patched.
98
+
99
+ If you would rather have the source on a disk than a link, ask and it will be
100
+ sent.
101
+
102
+ ## A note on H.264 patents
103
+
104
+ H.264 is covered by patents in some countries. Just Fits encodes H.264 with
105
+ x264, an independent open source encoder, and the licence above covers the
106
+ copyright in that software and nothing else. Patent licensing is a separate
107
+ matter from the software licence. If you are redistributing Just Fits
108
+ commercially or at scale, take your own advice on what that means where you
109
+ operate.
@@ -0,0 +1,127 @@
1
+ # License
2
+
3
+ Most files in FFmpeg are under the GNU Lesser General Public License version 2.1
4
+ or later (LGPL v2.1+). Read the file `COPYING.LGPLv2.1` for details. Some other
5
+ files have MIT/X11/BSD-style licenses. In combination the LGPL v2.1+ applies to
6
+ FFmpeg.
7
+
8
+ Some optional parts of FFmpeg are licensed under the GNU General Public License
9
+ version 2 or later (GPL v2+). See the file `COPYING.GPLv2` for details. None of
10
+ these parts are used by default, you have to explicitly pass `--enable-gpl` to
11
+ configure to activate them. In this case, FFmpeg's license changes to GPL v2+.
12
+
13
+ Specifically, the GPL parts of FFmpeg are:
14
+
15
+ - optional x86 optimization in the files
16
+ - `libavcodec/x86/flac_dsp_gpl.asm`
17
+ - `libavcodec/x86/idct_mmx.c`
18
+ - `libavfilter/x86/vf_removegrain.asm`
19
+ - the following building and testing tools
20
+ - `compat/solaris/make_sunver.pl`
21
+ - `doc/t2h.pm`
22
+ - `doc/texi2pod.pl`
23
+ - `libswresample/tests/swresample.c`
24
+ - `tests/checkasm/*`
25
+ - `tests/tiny_ssim.c`
26
+ - the following filters in libavfilter:
27
+ - `signature_lookup.c`
28
+ - `vf_blackframe.c`
29
+ - `vf_boxblur.c`
30
+ - `vf_colormatrix.c`
31
+ - `vf_cover_rect.c`
32
+ - `vf_cropdetect.c`
33
+ - `vf_delogo.c`
34
+ - `vf_eq.c`
35
+ - `vf_find_rect.c`
36
+ - `vf_fspp.c`
37
+ - `vf_histeq.c`
38
+ - `vf_hqdn3d.c`
39
+ - `vf_kerndeint.c`
40
+ - `vf_lensfun.c` (GPL version 3 or later)
41
+ - `vf_mcdeint.c`
42
+ - `vf_mpdecimate.c`
43
+ - `vf_nnedi.c`
44
+ - `vf_owdenoise.c`
45
+ - `vf_perspective.c`
46
+ - `vf_phase.c`
47
+ - `vf_pp7.c`
48
+ - `vf_pullup.c`
49
+ - `vf_repeatfields.c`
50
+ - `vf_sab.c`
51
+ - `vf_signature.c`
52
+ - `vf_smartblur.c`
53
+ - `vf_spp.c`
54
+ - `vf_stereo3d.c`
55
+ - `vf_super2xsai.c`
56
+ - `vf_tinterlace.c`
57
+ - `vf_uspp.c`
58
+ - `vf_vaguedenoiser.c`
59
+ - `vsrc_mptestsrc.c`
60
+
61
+ Should you, for whatever reason, prefer to use version 3 of the (L)GPL, then
62
+ the configure parameter `--enable-version3` will activate this licensing option
63
+ for you. Read the file `COPYING.LGPLv3` or, if you have enabled GPL parts,
64
+ `COPYING.GPLv3` to learn the exact legal terms that apply in this case.
65
+
66
+ There are a handful of files under other licensing terms, namely:
67
+
68
+ * The files `libavcodec/jfdctfst.c`, `libavcodec/jfdctint_template.c` and
69
+ `libavcodec/jrevdct.c` are taken from libjpeg, see the top of the files for
70
+ licensing details. Specifically note that you must credit the IJG in the
71
+ documentation accompanying your program if you only distribute executables.
72
+ You must also indicate any changes including additions and deletions to
73
+ those three files in the documentation.
74
+ * `tests/reference.pnm` is under the expat license.
75
+
76
+
77
+ ## External libraries
78
+
79
+ FFmpeg can be combined with a number of external libraries, which sometimes
80
+ affect the licensing of binaries resulting from the combination.
81
+
82
+ ### Compatible libraries
83
+
84
+ The following libraries are under GPL version 2:
85
+ - avisynth
86
+ - frei0r
87
+ - libcdio
88
+ - libdavs2
89
+ - librubberband
90
+ - libvidstab
91
+ - libx264
92
+ - libx265
93
+ - libxavs
94
+ - libxavs2
95
+ - libxvid
96
+
97
+ When combining them with FFmpeg, FFmpeg needs to be licensed as GPL as well by
98
+ passing `--enable-gpl` to configure.
99
+
100
+ The following libraries are under LGPL version 3:
101
+ - gmp
102
+ - libaribb24
103
+ - liblensfun
104
+
105
+ When combining them with FFmpeg, use the configure option `--enable-version3` to
106
+ upgrade FFmpeg to the LGPL v3.
107
+
108
+ The VMAF, mbedTLS, RK MPI, OpenCORE and VisualOn libraries are under the Apache License
109
+ 2.0. That license is incompatible with the LGPL v2.1 and the GPL v2, but not with
110
+ version 3 of those licenses. So to combine these libraries with FFmpeg, the
111
+ license version needs to be upgraded by passing `--enable-version3` to configure.
112
+
113
+ The smbclient library is under the GPL v3, to combine it with FFmpeg,
114
+ the options `--enable-gpl` and `--enable-version3` have to be passed to
115
+ configure to upgrade FFmpeg to the GPL v3.
116
+
117
+ ### Incompatible libraries
118
+
119
+ There are certain libraries you can combine with FFmpeg whose licenses are not
120
+ compatible with the GPL and/or the LGPL. If you wish to enable these
121
+ libraries, even in circumstances that their license may be incompatible, pass
122
+ `--enable-nonfree` to configure. This will cause the resulting binary to be
123
+ unredistributable.
124
+
125
+ The Fraunhofer FDK AAC and OpenSSL libraries are under licenses which are
126
+ incompatible with the GPLv2 and v3. To the best of our knowledge, they are
127
+ compatible with the LGPL.