invisimark 0.2.0__tar.gz

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.
Files changed (37) hide show
  1. invisimark-0.2.0/LICENSE +202 -0
  2. invisimark-0.2.0/PKG-INFO +379 -0
  3. invisimark-0.2.0/README.md +357 -0
  4. invisimark-0.2.0/pyproject.toml +42 -0
  5. invisimark-0.2.0/pyproject.toml.orig +41 -0
  6. invisimark-0.2.0/src/invisimark/__init__.py +6 -0
  7. invisimark-0.2.0/src/invisimark/ai.py +402 -0
  8. invisimark-0.2.0/src/invisimark/calibrate.py +191 -0
  9. invisimark-0.2.0/src/invisimark/cli.py +458 -0
  10. invisimark-0.2.0/src/invisimark/course.py +235 -0
  11. invisimark-0.2.0/src/invisimark/detect.py +508 -0
  12. invisimark-0.2.0/src/invisimark/embed.py +145 -0
  13. invisimark-0.2.0/src/invisimark/keys.py +110 -0
  14. invisimark-0.2.0/src/invisimark/media.py +136 -0
  15. invisimark-0.2.0/src/invisimark/py.typed +0 -0
  16. invisimark-0.2.0/src/invisimark/service.py +910 -0
  17. invisimark-0.2.0/src/invisimark/site.py +201 -0
  18. invisimark-0.2.0/src/invisimark/static/index.html +280 -0
  19. invisimark-0.2.0/src/invisimark/static/site/app.js +184 -0
  20. invisimark-0.2.0/src/invisimark/static/site/apple-touch-icon.png +0 -0
  21. invisimark-0.2.0/src/invisimark/static/site/check.js +81 -0
  22. invisimark-0.2.0/src/invisimark/static/site/favicon.svg +1 -0
  23. invisimark-0.2.0/src/invisimark/static/site/layout.html +72 -0
  24. invisimark-0.2.0/src/invisimark/static/site/og.png +0 -0
  25. invisimark-0.2.0/src/invisimark/static/site/pages/about.html +24 -0
  26. invisimark-0.2.0/src/invisimark/static/site/pages/check.html +33 -0
  27. invisimark-0.2.0/src/invisimark/static/site/pages/eu-ai-act-marking.html +48 -0
  28. invisimark-0.2.0/src/invisimark/static/site/pages/guides/find-who-leaked-your-video.html +50 -0
  29. invisimark-0.2.0/src/invisimark/static/site/pages/guides/invisible-vs-visible-watermarks.html +32 -0
  30. invisimark-0.2.0/src/invisimark/static/site/pages/guides/watermark-course-videos.html +41 -0
  31. invisimark-0.2.0/src/invisimark/static/site/pages/guides.html +9 -0
  32. invisimark-0.2.0/src/invisimark/static/site/pages/index.html +89 -0
  33. invisimark-0.2.0/src/invisimark/static/site/pages/privacy.html +15 -0
  34. invisimark-0.2.0/src/invisimark/static/site/pages/terms.html +15 -0
  35. invisimark-0.2.0/src/invisimark/static/site/style.css +137 -0
  36. invisimark-0.2.0/src/invisimark/tile.py +99 -0
  37. invisimark-0.2.0/src/invisimark/web.py +290 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: invisimark
3
+ Version: 0.2.0
4
+ Summary: Invisible watermarks for images and video: trace which copy leaked, or mark AI-generated output for anyone to check.
5
+ Author: Adam Gibbons
6
+ Author-email: Adam Gibbons <adam.p.gibbons@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Dist: c2pa-python==0.38.1
10
+ Requires-Dist: cryptography>=44
11
+ Requires-Dist: numpy>=2.5.3
12
+ Requires-Dist: opencv-python-headless>=5.0.0.93
13
+ Requires-Dist: python-multipart>=0.0.32
14
+ Requires-Dist: scipy>=1.18.1
15
+ Requires-Dist: starlette>=1.7.0
16
+ Requires-Dist: uvicorn>=0.54.0
17
+ Requires-Python: >=3.13
18
+ Project-URL: Source, https://github.com/Huckcity/invisimark
19
+ Project-URL: Specification, https://github.com/Huckcity/invisimark/blob/main/docs/spec.md
20
+ Project-URL: Changelog, https://github.com/Huckcity/invisimark/blob/main/CHANGELOG.md
21
+ Description-Content-Type: text/markdown
22
+
23
+ # invisimark
24
+
25
+ Invisible per-recipient watermarks for images and video. Give every recipient a copy that looks identical to the
26
+ original but carries a mark only you can read, then, when a copy leaks, upload it and find out whose it was.
27
+
28
+ Everything runs on your machine. There is no server, no account and no upload.
29
+
30
+ It also [marks AI-generated images and video](#marking-ai-generated-images-and-video) with a public watermark and signed C2PA metadata, for apps preparing for EU AI Act Article 50.
31
+
32
+ <!-- numbers:transcript -->
33
+ ```
34
+ $ invisimark keygen
35
+ wrote ~/.config/invisimark/key (mode 600). Back it up: without it, issued copies cannot be traced.
36
+ $ invisimark issue master.mp4 --to alice --to bob --to order-1093
37
+ calibrating strength against recompression, downscaling and screen capture ...
38
+ strength 1.75 (robust); tightest case half-size: sync z 9.5, id z 10.0
39
+ alice: master.alice.mp4
40
+ bob: master.bob.mp4
41
+ order-1093: master.order-1093.mp4
42
+
43
+ $ invisimark trace screen-recording-from-a-forum.mp4
44
+ marked by this key: sync z 14.5, scale x0.564
45
+ bob z 10.0
46
+ alice z 0.7
47
+ order-1093 z -0.5
48
+ => traced to: bob
49
+ ```
50
+
51
+ A real run on the 10 s `bbb` clip (`bench/results/transcript.md`, commit `4d513e7`, ffmpeg 5.1.9, 2026-12-04),
52
+ regenerated by `bench/transcript.py`. The leak is bob's copy shrunk into a 1920x1080 screen recording (the
53
+ `screenrec_small` attack below). `keygen` makes a new random key every time, so the scores move from run to run, and
54
+ they will differ on your footage; `issue` measures each file before marking it.
55
+ <!-- /numbers:transcript -->
56
+
57
+ Or run `invisimark serve` for a local web app that does the same with drag and drop.
58
+
59
+ ## What it survives
60
+
61
+ Measured, not claimed. `bench/` marks a clip, mangles the marked file the way leaks get mangled, then traces it
62
+ with 500 wrong names plus the right one in the list. "Named" means the right recipient was accused, at the
63
+ thresholds described below, with nobody else near.
64
+
65
+ Every number in the tables and summaries below is generated from the results files in `bench/results/` by
66
+ `bench/readme_numbers.py`, and CI fails if the README and the results disagree.
67
+
68
+ <!-- numbers:video -->
69
+ **Video** (720p, 10 s clips, 27 attacks each; `bench/results/video.md`, commit `d44bb17`, ffmpeg 5.1.9, 2026-11-30)
70
+
71
+ | clip | picture | strength | PSNR vs original | named |
72
+ |---|---|---|---|---|
73
+ | `bbb` | textured animation | 2.1 (auto) | 40.8 dB (plain re-encode: 43.6) | **27 / 27** |
74
+ | `jelly` | natural footage | 1.75 (auto) | 43.3 dB (plain re-encode: 47.1) | **26 / 27**, misses `240p` |
75
+ | `sintel` | flat shading, dark scenes | 2.6 (ceiling) | 42.0 dB (plain re-encode: 50.7) | 21 / 27, flagged **weak**; misses `crf34`, `360p`, `240p`, `blur2`, `screenrec_small`, `worst` |
76
+ <!-- /numbers:video -->
77
+
78
+ The 27 attacks: x264 at crf 23, 28 and 34; H.265 crf 30; VP9 crf 40; downscale to 720p@2 Mbps, 480p@1 Mbps, 360p
79
+ and 240p; upscale to 1080p; 24 and 15 fps; crop 10% and 25%; zoom to 80%; reframe to 9:16 vertical; brightness,
80
+ contrast, saturation and gamma shifts; Gaussian blur at sigma 1 and 2; sharpen; film grain; left-right mirror;
81
+ a screen recording of the player inside a 1920x1080 desktop, at two sizes; a 2 s trim; and a worst case that
82
+ stacks downscale, crop, blur, a brightness shift and crf 32.
83
+
84
+ These are three 10-second clips of open test footage (the 720p encodes of Big Buck Bunny, Jellyfish and Sintel from
85
+ test-videos.co.uk), so read them as a sketch of the range, not a guarantee for your material. `issue` re-measures on
86
+ *your* file before it marks anything. The clips are pinned by checksum in `bench/footage.py`, so you can rerun the
87
+ table yourself:
88
+
89
+ ```
90
+ uv run python bench/footage.py fetch footage
91
+ uv run python bench/attacks.py footage/bbb720.mp4 footage/jelly720.mp4 footage/sintel720.mp4 --out video.md
92
+ ```
93
+
94
+ With the same ffmpeg build, two runs agree row for row except the two bitrate-capped attacks (`720p_2M`, `480p_1M`),
95
+ whose scores move by up to 1 z between runs because x264's multithreaded rate control is not deterministic. A
96
+ different ffmpeg build moves scores further: against the previous table, made with an unrecorded build, identity
97
+ scores moved by up to 0.4 z on `bbb`, 2.3 on `jelly` and 5.9 on `sintel`. Across all of these runs, every clip named or
98
+ missed exactly the same attacks.
99
+
100
+ <!-- numbers:images -->
101
+ **Images** (17 attacks each; `bench/results/images.md`)
102
+
103
+ | image | source | size | strength | PSNR vs original | named |
104
+ |---|---|---|---|---|---|
105
+ | `bbb` | still from `bbb` | 1280x720 | 0.85 (auto) | 48.6 dB | **16 / 17**, misses `crop60` |
106
+ | `jelly` | still from `jelly` | 1280x720 | 1.75 (auto) | 43.2 dB | **17 / 17** |
107
+ | `sintel` | still from `sintel` | 1280x720 | 2.1 (auto) | 41.9 dB | **17 / 17** |
108
+ | `coffee` | stock photo | 600x400 | 2.1 (auto) | 41.6 dB | **15 / 17**, misses `crop60`, `worst` |
109
+ | `astronaut` | stock photo | 512x512 | 2.6 (ceiling) | 39.9 dB | 15 / 17, flagged **weak**; misses `crop60`, `worst` |
110
+ <!-- /numbers:images -->
111
+
112
+ The stills are 1280x720 frames cut from the video clips; `coffee` and `astronaut` are small stock photos. The attacks
113
+ include JPEG quality 30, 80% and 60% crops, half size, a chat-app resize-and-recompress, a screenshot, mirroring and a
114
+ combined worst case. The 60% crop and the stacked worst case are what the small photos miss.
115
+
116
+ <!-- numbers:null-study -->
117
+ **False accusations** (`bench/results/null_study.txt`): 260 runs on unmarked images and videos, and on marked videos
118
+ traced with a wrong key, a different random key each time. The sync statistic had a mean of 5.0, a standard deviation of
119
+ 0.6 and a maximum of 6.6; it needs 7.5 to count as a mark on its own, and nothing got there. The best of 200 wrong names
120
+ scored 4.4 at most against a threshold of 6.0. Nobody was named, and nothing was called marked.
121
+ <!-- /numbers:null-study -->
122
+
123
+ **Speed**: marking a 10 s 720p clip takes about 8-10 s per recipient, plus 35-50 s of calibration once per master.
124
+ Tracing a video typically takes 10-30 s. A 12 megapixel photo marks in about a second and traces in about 9.
125
+
126
+ ## What it does not survive
127
+
128
+ Be honest with yourself about these before you rely on it.
129
+
130
+ * **Flat or dark pictures.** The mark lives where the picture has texture, because that is where the eye and the
131
+ encoder both let it through. Cartoon-flat shading, black backgrounds and sky carry little. `issue` measures this and
132
+ prints `WEAK`; then copies are traceable when shared as they are or lightly recompressed, not through heavy
133
+ recompression. Do not promise yourself more than the calibration says.
134
+ * **Small pictures and heavy crops.** The mark repeats every 128 px and detection needs a few dozen repeats. A 512 px
135
+ picture survives recompression and resizing but not a 60% crop. Mark the full-size original, not a thumbnail.
136
+ * **Very small copies.** 240p (a third of 720p) is the edge for video.
137
+ * **A phone filming a screen.** Perspective, moire and rotation by any angle other than a multiple of 90 degrees are
138
+ not handled and not tested. Screen *recordings* are tested.
139
+ * **Generative reprocessing.** AI upscaling, denoising or "enhance" passes, and frame interpolation, are untested and
140
+ should be assumed to strip it.
141
+ * **Someone who knows it is there.** Strong noise plus blur, or averaging several recipients' copies together, damages
142
+ the mark. In the tests two colluders' averaged copy ranks both of them first and second; with many colluders you
143
+ should expect no one to stand out. Treat this as deterrence plus evidence, not a lock.
144
+ * **Video format limits.** 8-bit SDR only. Variable-frame-rate sources are re-timed to constant. HDR is untested.
145
+
146
+ ## Reading a result
147
+
148
+ * **traced to X**: X scored above the threshold for the size of your candidate list (at least 6, higher for long
149
+ lists) and clear of the runner-up. The threshold is set so an unrelated name should pass about once in ten million;
150
+ that assumes the null stays Gaussian in the tail, which was checked only out to about 4.5.
151
+ * **weak lead: X**: X is clearly ahead but below the threshold. A reason to look, not a reason to accuse.
152
+ * **marked, but no one stands out**: your mark is present (the alignment signal is strong on its own) but the copy was
153
+ changed too much to tell recipients apart, or the leaker is not on your list.
154
+ * **no mark from this key**: either the file did not come from you or it was changed too much. Absence is not proof
155
+ of innocence. "Marked" needs either a strong alignment signal on its own (7.5, against a null that peaks near 6.6) or
156
+ a weaker one together with a candidate that clears the naming threshold.
157
+
158
+ A match is evidence, not proof. Check it against how and when you sent each copy before acting on it.
159
+
160
+ ## How it works
161
+
162
+ Each copy gets two band-limited noise tiles added to its brightness, repeated every 128 px and scaled by a
163
+ perceptual mask (more where the picture is busy). Both are derived from your secret key with HMAC, so no database is
164
+ needed to re-derive them:
165
+
166
+ * the **sync tile** is the same for every copy of a key and sits in the low bands, which survive compression and blur
167
+ best. It lets the detector recover scale, crop and orientation;
168
+ * the **id tile** is unique to the recipient's label and sits in the mid bands.
169
+
170
+ To trace, the detector band-passes and soft-clips sampled frames (so a few sharp edges cannot outvote the mark),
171
+ averages them, then walks a range of scales, resizing the average until the pattern's period is 128 px again and
172
+ folding it onto a single 128x128 cell. Flips and transposes of the image are flips and transposes of that cell, so
173
+ mirrored and 90-degree-rotated copies cost almost nothing to test. The cell is correlated with the sync tile
174
+ (whitened, so busy low frequencies stop drowning the mark) to find scale, orientation and shift. At that alignment it
175
+ is correlated with every candidate's id tile and each score is compared with a null built from 1,500 decoy names.
176
+
177
+ Recipients are found by *matching* against a list, not by decoding a payload. That is why it tolerates so much damage,
178
+ and why you need to know who might have the file: the ledger from `issue` supplies the list, and `trace
179
+ --candidates names.txt` adds more.
180
+
181
+ **Strength is chosen per master.** The same mark that is invisible on foliage shows on a flat sky and is erased from
182
+ it by the encoder, so `issue` defaults to `--strength auto`: it marks a typical 5 s excerpt at a few strengths, pushes
183
+ each through recompression, half-size and screen-capture panels, traces it, and keeps the weakest strength that
184
+ clears the detection thresholds with margin. Strength is the RMS of the added pattern in 8-bit code values; for
185
+ scale, a plain x264 re-encode at crf 18 already costs about 0.7 to 1.7 depending on the picture.
186
+
187
+ ## Courses: one render per lesson, not one per student
188
+
189
+ `issue` costs about one real-time render per recipient, which is hopeless for 300 students and 40 lessons. `course`
190
+ renders each lesson **twice** (variant A and variant B, in 5 s segments that each start on a keyframe), then builds a
191
+ student's copy by taking every segment from A or from B according to a bit string derived from your key, the student and
192
+ the lesson, joined with `ffmpeg -c copy`. A copy is a file concatenation: well under a second. The source's own audio
193
+ is kept as it is (it is not marked).
194
+
195
+ ```
196
+ invisimark course issue lessons/*.mp4 --roster students.txt --out copies/ # copies/<student>/<lesson>.mp4
197
+ invisimark course trace leaked-lesson.mp4 [--trim SECONDS] [--roster more.txt]
198
+ ```
199
+
200
+ Rendered segments stay in `copies/.work`, so an interrupted run resumes, and a student added later costs seconds.
201
+ Course copies are recorded in `course-ledger.jsonl` beside the ledger; plain `trace` knows nothing about them.
202
+
203
+ **How a leak is read.** The file is aligned once (scale, crop, mirroring) by the ordinary detector. Each 5 s window is then
204
+ scored against that lesson's A and B tiles, which gives one bit per segment, or nothing when the window is unreadable.
205
+ Because each student's bits come from an HMAC, an unrelated student matches each clear segment with probability exactly one
206
+ half, so the report is an exact binomial tail rather than a tuned threshold:
207
+
208
+ ```
209
+ lesson lesson3_phone: sync z 14.3, scale x0.999; read 51 of 51 segments
210
+ alice agrees on 48 of 48 clear segments; an unrelated student would do that by luck 1 time in 281,474,976,710,656
211
+ dave agrees on 30 of 48 clear segments; an unrelated student would do that by luck 1 time in 18
212
+ erin agrees on 25 of 48 clear segments; an unrelated student would do that by luck 1 time in 2
213
+ carol agrees on 23 of 48 clear segments; an unrelated student would do that by luck 1 time in 1
214
+ frank agrees on 23 of 48 clear segments; an unrelated student would do that by luck 1 time in 1
215
+ => traced to: alice
216
+ ```
217
+
218
+ Someone is named when the odds of *any* innocent student on the roster doing as well are 1 in a million or better. Short of
219
+ that you get a "weak lead" with its odds. Two students who swap segments both stand out.
220
+
221
+ **Measured** (`bench/course_eval.py`; one 4-minute, 720x1558 screen recording, 51 segments, six students, strength 2.6,
222
+ which the tool flags `WEAK` on this flat footage). "Named" means the right student, with no one else near:
223
+
224
+ | leak | result |
225
+ |---|---|
226
+ | as delivered | named, 1 in 5x10^13 |
227
+ | x264 crf 28 | named, 1 in 3x10^9 and 1 in 1x10^10 (two students) |
228
+ | crf 34 | weak lead on the right student, 1 in 3x10^4 and 1 in 6x10^4 (two students) |
229
+ | 75% size + crf 28 | named (1 in 4x10^8) for one student, weak lead (1 in 4x10^5) for the other |
230
+ | first 12 s cut off, crf 23, `--trim 12` | named, 1 in 7x10^11 and 1 in 2x10^11 |
231
+ | true leaker not on the roster | nobody named (best unrelated student 30 of 48) |
232
+ | unmarked original, unrelated video | no mark found |
233
+ | 300-student roster | alice named, 1 in 9x10^11 |
234
+
235
+ **What it costs.** Rendering the 4-minute lesson in both variants took 3 min 35 s on 16 cores (about 0.85 s per second of
236
+ video, and it does not grow with the number of students). Copies came out 6 to 76 percent larger than their sources
237
+ (18 MB to 19 MB for camera footage, 17 MB to 30 MB for the screen recording): the mark is noise, and noise is not free to
238
+ encode. The segments take about 110 MB for three lessons.
239
+
240
+ **What it does not do.**
241
+ * **It needs enough footage.** To name someone among six students you need about 23 clear segments agreeing, among 300 about
242
+ 29: two to two and a half minutes of a leaked lesson at 5 s. A 50 s leak can only give a weak lead (1 in 341 for six
243
+ students). Shorter segments help evidence per minute and cost bitrate; there is no setting here that beats having more
244
+ of the lesson. Evidence from several leaked lessons is not yet combined.
245
+ * **A trimmed start needs `--trim`.** There is no automatic search for the cut point yet. A leak cut mid-segment still reads
246
+ from the segments it fully contains.
247
+ * **Flat footage is the weak case**, as above, and so are screen recordings of the player and phone filming a screen:
248
+ untested in this mode.
249
+ * **Variable frame rate sources** are re-timed to constant, so segment edges can drift by a frame. Convert first.
250
+ * **Collusion** is only handled in the simple case: students who swap segments are all named. Students who average their
251
+ copies, or many colluders, are not modelled.
252
+
253
+ ## Marking AI-generated images and video
254
+
255
+ A second use, separate from tracing leaks: mark what an AI system generates, so anyone can check it. It follows the two layers in Measure 1.1 of the EU Code of Practice on Transparency of AI-Generated Content: an imperceptible watermark from a published key, and a signed, time-stamped C2PA manifest.
256
+
257
+ ```
258
+ $ invisimark mark output.png marked.png --cert chain.pem --signing-key key.pem --provider "Acme" --system "AcmeGen"
259
+ marked.png: watermark at strength 1.75, signed
260
+
261
+ $ invisimark check marked.png
262
+ Watermark: this file carries the public Invisimark AI-marking watermark. ...
263
+ Metadata: a C2PA manifest signed by Acme. The signature is intact, ...
264
+ ```
265
+
266
+ `invisimark dev-cert` makes a throwaway certificate for trying this out. `invisimark report-key`, `check --report-key` and `verify-report` produce and verify signed detection results. The format is in `docs/spec.md`, so anyone can write their own detector.
267
+
268
+ <!-- numbers:ai-table -->
269
+ Measured at the default strength of 1.75 (`bench/results/ai.md`, PSNR about 43 dB), on 12 photographs at 1024 px:
270
+
271
+ | change | detected |
272
+ |---|---|
273
+ | untouched, JPEG down to quality 30, WebP, half size, 1.5x, chat-app recompression, screenshot, contrast, blur, grain, mirror, 90-degree turn, blurred region, crops to 80% and 60%, half size plus crop | **12 / 12** each |
274
+ | tilts of 1, 3, 5 and 10 degrees; one axis stretched to 4:3 or 16:9 | **12 / 12** each |
275
+ | stacked worst case | 11 / 12 |
276
+ | **tilt of 25 degrees; tilt plus half size; both axes scaled differently** | **0 / 12** each |
277
+ <!-- /numbers:ai-table -->
278
+
279
+ The search for tilts covers up to 15 degrees at 0.7x to 1.3x size, and one-axis stretches from 0.45x to 2.2x. It adds about 8 seconds to any check that does not find a mark straight away.
280
+
281
+ <!-- numbers:ai-adversarial -->
282
+ **Against someone trying to defeat it** (`bench/results/ai-adversarial.md`, 12 images):
283
+
284
+ | attack | public mark still detected | private tile still verifies |
285
+ |---|---|---|
286
+ | **subtract the published tile** (53.9 dB, effectively invisible) | **0 / 12** | 12 / 12, when the file has one |
287
+ | subtract it at half, 1.5 times or twice its strength | 11 / 12, 1 / 12 and 8 / 12 | not measured |
288
+ | lift the pattern from the file and subtract it, no key needed (42.8 dB) | 7 / 12 | 7 / 12 |
289
+ | **copy the pattern onto another image** | **11 / 12: a false "marked"** | **12 / 12: a false "verified"** |
290
+ | heavy denoising and resampling, as a stand-in for regeneration | 11 or 12 / 12 | not measured |
291
+ <!-- /numbers:ai-adversarial -->
292
+
293
+ So the public mark helps with accidental loss, such as recompression, not with someone determined. Its key is published, which is what lets anyone check it and also what makes removal this easy. No generative model was run, so real regeneration may do much better than the stand-ins.
294
+
295
+ <!-- numbers:ai-null -->
296
+ **False positives** (`bench/results/ai-null.txt`): none on 768 variants of 24 unmarked images. The highest score was 6.81 against a threshold of 8.0. The variants are not independent, so read the 0.39% upper bound as optimistic.
297
+ <!-- /numbers:ai-null -->
298
+
299
+ Other limits:
300
+
301
+ * The corpus is natural photographs, not model output.
302
+ * The mark says "marked as AI", not who made the file. Only signed metadata shows origin, and most platforms strip it. A private tile added with `--provider-key` lets a provider recognise its own output after the public tile is subtracted, but it can be copied too, so it doesn't prove origin. It holds up about as well as the public mark against everyday changes, though it's weaker on heavy crops and stacked changes (`bench/results/ai-provider.md`).
303
+ * Audio and text are not covered.
304
+
305
+ Using this does not by itself make anyone compliant with the AI Act. What is and is not covered is listed in `docs/article-50.md`.
306
+
307
+ ## Install
308
+
309
+ Python 3.13, with `ffmpeg` and `ffprobe` on the path. Marking video needs an ffmpeg built with libx264; some Linux
310
+ distributions ship one without it (Fedora's default `ffmpeg-free`, for example), and `invisimark` says so if yours
311
+ lacks it. Images do not need it.
312
+
313
+ ```
314
+ uv tool install invisimark # from PyPI; gives you the `invisimark` command
315
+ # or: pipx install invisimark, or pip install invisimark into an environment of your own
316
+ ```
317
+
318
+ From a checkout of this repository: `uv tool install .`, or `uv sync && uv run invisimark --help`.
319
+
320
+ ## Using it
321
+
322
+ ```
323
+ invisimark keygen # once; back up the key file
324
+ invisimark issue FILE --to alice --to bob # or --to-file names.txt
325
+ invisimark issue FILE --to alice --strength subtle # auto | subtle | standard | strong | an RMS number
326
+ invisimark trace LEAKED [--candidates names.txt] [--json]
327
+ invisimark inspect FILE # is this marked with my key at all?
328
+ invisimark serve # local web app on 127.0.0.1
329
+ invisimark course issue|trace ... # whole courses, see below
330
+ invisimark mark IN OUT [--cert C --signing-key K] # mark AI output, see below
331
+ invisimark check FILE # look for AI marks
332
+ invisimark host # public, anonymous, capped service: docs/self-hosting.md
333
+ ```
334
+
335
+ `trace` exits 0 when it names someone, 2 when the mark is present but nobody can be named, 1 when there is no mark.
336
+
337
+ The key lives at `~/.config/invisimark/key` (override with `--key` or `$INVISIMARK_KEY`), mode 600. **Back it up.**
338
+ Without it nothing can be traced. Anyone with it can mark files and accuse, so keep it private. The ledger
339
+ (`ledger.jsonl` beside it) records who got which file when, with hashes; it is a convenience, the evidence is the
340
+ mark. Labels are exact and case-sensitive: `Bob` and `bob` are different recipients.
341
+
342
+ The web app binds to 127.0.0.1, requires a per-launch token on every request (so another page open in your browser
343
+ cannot drive it), keeps uploads in a temporary folder that is cleared when you stop it, and never talks to the network.
344
+
345
+ ## Using it responsibly
346
+
347
+ Mark files you have the right to share, and tell recipients their copy is individually marked; that is most of the
348
+ deterrent. The mark itself holds no personal data, but the ledger does (names, dates), so treat it as personal data.
349
+
350
+ ## Development
351
+
352
+ ```
353
+ uv run pytest # the full suite, about nine minutes (see CI)
354
+ uv run python bench/attacks.py CLIP.mp4 # the 27-attack video matrix, strength auto
355
+ uv run python bench/footage.py fetch DIR # the pinned open clips behind bench/results/video.md
356
+ uv run python bench/images.py STILL.png # the 17-attack image matrix
357
+ uv run python bench/null_study.py CLIP.mp4 # how high does the statistic get when there is nothing to find
358
+ ```
359
+
360
+ Changes are listed in `CHANGELOG.md`; a version is tagged only once it has a dated section there.
361
+
362
+ | file | job |
363
+ |---|---|
364
+ | `tile.py` | keyed tiles and the mark's shape |
365
+ | `embed.py` | adds the mark to an image or, through ffmpeg pipes, a video |
366
+ | `detect.py` | scale, orientation and shift recovery; candidate scoring; thresholds |
367
+ | `calibrate.py` | closed-loop strength |
368
+ | `course.py` | A/B segment marking for sets of lessons: render, assemble, read, score |
369
+ | `service.py`, `static/site/` | the public service: capped anonymous jobs, case files, pages (see `docs/self-hosting.md`) |
370
+ | `ai.py` | AI marking: the public mark, C2PA manifests, checks and signed results (see `docs/spec.md`) |
371
+ | `keys.py`, `cli.py`, `web.py` | key and ledger, command line, local app |
372
+
373
+ The shape of the mark was tuned by comparing variants at equal visible distortion, by hand, during development; that
374
+ comparison is not reproduced here. What helped most: giving each tile an equal-magnitude spectrum with random phases
375
+ (a Gaussian spectrum leaves some keys with a poor matched filter; this lifted typical sync scores by 10-50% and made
376
+ small pictures workable), putting the sync tile in the low bands, and weighting the mask toward texture. Things tried
377
+ that did not help: a lower-band id tile for flat content (a little
378
+ better, not enough), more sampled frames (the noise is not independent across frames), and a scale search on the
379
+ power spectrum's lattice lines (it needs roughly 3.4x more mark than coherent matching).