edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB892f813Tahinli3 months ago398 commits
| 1 | //! Small stand-ins for big files: a half-size, every-frame-a-keyframe H.264 |
| 2 | //! copy of a source, kept in the user's cache and played instead of the |
| 3 | //! original while the cut is being made. |
| 4 | //! |
| 5 | //! Why they exist at all: a 4K HEVC film decodes at a fraction of realtime on |
| 6 | //! this machine, so scrubbing it is a slideshow and every seek is a wait. A |
| 7 | //! proxy is the same film at 1280 on its long edge, coded so that **every frame |
| 8 | //! is a random-access point** -- which is what makes a seek land on the frame |
| 9 | //! that was asked for instead of on the nearest one a decoder can start from, |
| 10 | //! and what takes the whole open-GOP class of seek faults off the table by |
| 11 | //! construction. |
| 12 | //! |
| 13 | //! Three rules, and they are the whole contract: |
| 14 | //! |
| 15 | //! - **Picture only.** No sound is coded into a proxy. The mix always comes off |
| 16 | //! the original file ([`crate::PlaybackSession`] opens audio by its own path, |
| 17 | //! which this module never touches), so nothing a listener hears has been |
| 18 | //! through a second encoder. |
| 19 | //! - **Never exported.** [`crate::export`] reads the project's own sources and |
| 20 | //! knows nothing of this module. Delivery is the original, always. |
| 21 | //! - **Derived, never authoritative.** A proxy is named after the source's |
| 22 | //! path, length and modification time ([`path_for`]), so a re-encoded or |
| 23 | //! re-cut original simply misses the cache and a stale proxy can never be |
| 24 | //! found. Deleting the cache directory costs time and nothing else. |
| 25 | //! |
| 26 | //! Generation is [`crate::export`]'s own decode -> scale -> encode walk, given |
| 27 | //! a one-clip project and a smaller canvas: the hardware seat where the GPU has |
| 28 | //! one, the software encoder where it does not, the same progress and the same |
| 29 | //! cancel a file export has ([`Job`]). |
| 30 | |
| 31 | use ; |
| 32 | use UNIX_EPOCH; |
| 33 | |
| 34 | use crate; |
| 35 | use crate; |
| 36 | use crate; |
| 37 | use crateFitPolicy; |
| 38 | |
| 39 | /// The long edge of a proxy picture, in samples: 1280, so a 4K source loses |
| 40 | /// nine tenths of its samples and a 1080p one a little over half. Chosen as |
| 41 | /// what a cut can be judged on at editing size, in the neighbourhood of every |
| 42 | /// shipped proxy preset (Resolve's half-res, kdenlive's 640/1000-wide |
| 43 | /// defaults). |
| 44 | pub const LONG_EDGE: u32 = 1280; |
| 45 | |
| 46 | /// Bits per pixel per second a proxy is coded at, [`crate::export`]'s own rate |
| 47 | /// rule at three times the number: every frame being an IDR means no frame |
| 48 | /// borrows anything from its neighbours, so the same picture at the inter rate |
| 49 | /// would be mush -- and mush is not something a cut can be judged on. |
| 50 | const BITS_PER_PIXEL: f64 = 0.3; |
| 51 | |
| 52 | /// Whether this is a file worth standing in for: bigger than 1080p, or coded in |
| 53 | /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p |
| 54 | /// plays natively and a proxy of it would cost time and buy nothing. |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most |
| 60 | /// [`LONG_EDGE`], both axes even because 4:2:0 has no half chroma samples. A |
| 61 | /// source already that small is coded at its own size (rounded down to even), |
| 62 | /// which is what makes [`generate`] safe to ask for on anything at all. |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | /// Where the proxy of `source` lives, whether or not it has been made yet. |
| 74 | /// |
| 75 | /// The name is one hash of the source's canonical path, its length **and** its |
| 76 | /// modification time, so an original that changed at all is a different name |
| 77 | /// and its old proxy is simply never looked at again -- the staleness check is |
| 78 | /// the lookup. `None` where the file cannot be stat'd or the machine has no |
| 79 | /// cache directory at all, which is a source that gets no proxy rather than one |
| 80 | /// littering the working directory. |
| 81 | /// |
| 82 | /// corner-cut: nothing evicts, exactly as the Matroska index cache beside it |
| 83 | /// states. A proxy of a feature film is hundreds of megabytes and a re-encoded |
| 84 | /// source leaves its old one behind; the upgrade path is a size-capped sweep of |
| 85 | /// the directory at open. It is the user's own cache to delete meanwhile. |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | /// The proxy of `source` if one has already been made, `None` otherwise. The |
| 106 | /// answer a session asks at open: a hit costs one `stat`. |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | /// A proxy being made -- or one that was already there, which is the same thing |
| 112 | /// to whoever is waiting for a path. |
| 113 | /// |
| 114 | /// Poll [`progress`](Job::progress) while [`is_finished`](Job::is_finished) is |
| 115 | /// false and take the [`outcome`](Job::outcome) when it flips, exactly as an |
| 116 | /// export is polled. Dropping the job does not stop the work; |
| 117 | /// [`cancel`](Job::cancel) does. |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | /// Starts making the proxy of `source`, or hands back the one already in the |
| 176 | /// cache. Errors are the ones that happen before a worker exists -- a file with |
| 177 | /// no picture in it, nowhere to put a cache -- and everything after them comes |
| 178 | /// back through [`Job::outcome`], so a caller has two places to look and not |
| 179 | /// twenty. |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | /// The same, for a file that is worth standing in for and nobody else |
| 185 | /// ([`wanted`]) -- `Ok(None)` is a film this machine already cuts at speed. |
| 186 | /// |
| 187 | /// The header is read *once* for both questions: on a Matroska that read is the |
| 188 | /// cluster walk, so asking `wanted` and then `generate` separately would pay |
| 189 | /// for it twice. |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | /// Both doors: the cache is looked at, the header is read once, and `only_if` |
| 195 | /// decides off that header whether there is anything to do. |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 |