edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBf7fa0feTahinli25 days ago1027 commits
| 1 | //! Walking a clip's frames backwards without holding the clip in memory. |
| 2 | //! |
| 3 | //! A video codec only decodes forwards: a picture needs the ones before it, back to |
| 4 | //! the last sync frame. So a reversed clip is served a *block* at a time -- decode a |
| 5 | //! stretch of the window forwards, hand it out last to first, then the stretch |
| 6 | //! before it -- and memory is bounded by the block, not the clip. The blocks are cut |
| 7 | //! on sync frames where the container says where they are (one GOP is then decoded |
| 8 | //! once, not once per picture), and capped at [`BLOCK_BUDGET`] bytes of decoded |
| 9 | //! pictures: a GOP longer than the cap is decoded again from its sync frame for each |
| 10 | //! of its blocks, which is slower but never larger. |
| 11 | //! |
| 12 | //! This module is only the plan -- which blocks, in which order. The decoding and |
| 13 | //! the pictures' type belong to the caller (playback walks BGRA canvases, export |
| 14 | //! I420 planes), so both serve a reversed clip by the one rule. |
| 15 | |
| 16 | use Path; |
| 17 | |
| 18 | /// What one block of decoded pictures may weigh. A 1080p BGRA canvas is 8 MB, so |
| 19 | /// this is thirty-odd of them; 4K takes eight. |
| 20 | pub const BLOCK_BUDGET: usize = 256 << 20; |
| 21 | |
| 22 | /// The most pictures one block may hold when each is `bytes` big: never fewer than |
| 23 | /// two, so a block always makes progress, and never more than a hundred and twenty. |
| 24 | pub |
| 25 | |
| 26 | |
| 27 | |
| 28 | /// Every frame of `path`'s picture a decoder may be started on, when that is cheap |
| 29 | /// to ask: an mp4 answers off its sync table, while a Matroska file costs a walk of |
| 30 | /// its clusters (seconds on a big film), so it answers nothing and its blocks are |
| 31 | /// cut without. Empty is always a legal answer; the plan is merely less tidy. |
| 32 | pub |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// The walk down a window of source frames: [`Walk::next`] hands out the blocks |
| 40 | /// `[start, end)` from the window's last frame to its first. |
| 41 | pub |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 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 |