edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! Rate control for the sequence encoder: one QP per picture from a bit model, |
| 2 | //! with a leaky bucket that pulls the stream back to its budget. |
| 3 | //! |
| 4 | //! This is the frame-level loop of the H.264 encoder's `rc.rs`, adapted to |
| 5 | //! HEVC: QPs run 0..=51, and the QP a P picture is coded at includes the |
| 6 | //! encoder's fixed P offset ([`crate::enc_p`]'s `P_QP_DELTA`). The model is the |
| 7 | //! classic one: at a fixed complexity a picture's size scales as `2^(-QP/6)`, so |
| 8 | //! `complexity = bits * 2^(QP/6)` measured on the last picture of the same type |
| 9 | //! predicts the QP that hits the next target. |
| 10 | |
| 11 | use crateP_QP_DELTA; |
| 12 | |
| 13 | /// Frame-level rate control state for one sequence. |
| 14 | |
| 15 | pub |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /// A QP whose P picture cost more than this multiple of the picture target is a known |
| 44 | /// overspend: the next pictures do not go to that QP or below while the observation is fresh. |
| 45 | const CLIFF_RATIO: f64 = 1.5; |
| 46 | /// Share of the bucket's credit (bits saved against the budget) that a single picture may |
| 47 | /// spend above its cliff allowance, so saved bits can still pay for one expensive picture. |
| 48 | const CREDIT_SHARE: f64 = 0.8; |
| 49 | /// Most QP steps a P picture may drop below the previous P picture, bucket included. |
| 50 | const MAX_DESCENT: i32 = 4; |
| 51 | /// How many P pictures an observation stays valid for. Long enough to span the hunt back up |
| 52 | /// from a cliff (+2 QP per picture), short enough that a scene change releases the floor. |
| 53 | const CLIFF_AGE: u64 = 120; |
| 54 | /// Table slots for the QPs -12..=51 (the 10-bit range), `SEEN_OFFSET` slots below 0. |
| 55 | const SEEN_QPS: usize = 64; |
| 56 | const SEEN_OFFSET: i32 = 12; |
| 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 | |
| 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 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | /// Share of a batch's measured rate error (in QP steps) that the next batch's offset corrects. |
| 188 | const BATCH_GAIN: f64 = 0.7; |
| 189 | |
| 190 | /// The QP offset for the next batch of GOPs, from the bits the last batch spent against its |
| 191 | /// budget. Six QP steps is a factor of two in rate, as in the picture model. |
| 192 | pub |
| 193 | |
| 194 | |
| 195 | |
| 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 |