FFmpeg
cfhdenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * Cineform HD video encoder
24  */
25 
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "libavutil/imgutils.h"
30 #include "libavutil/opt.h"
31 
32 #include "avcodec.h"
33 #include "bytestream.h"
34 #include "cfhd.h"
35 #include "cfhdencdsp.h"
36 #include "codec_internal.h"
37 #include "encode.h"
38 #include "put_bits.h"
39 #include "thread.h"
40 
41 /* Derived from existing tables from decoder */
42 static const unsigned codebook[256][2] = {
43  { 1, 0x00000000 }, { 2, 0x00000002 }, { 3, 0x00000007 }, { 5, 0x00000019 }, { 6, 0x00000030 },
44  { 6, 0x00000036 }, { 7, 0x00000063 }, { 7, 0x0000006B }, { 7, 0x0000006F }, { 8, 0x000000D4 },
45  { 8, 0x000000DC }, { 9, 0x00000189 }, { 9, 0x000001A0 }, { 9, 0x000001AB }, {10, 0x00000310 },
46  {10, 0x00000316 }, {10, 0x00000354 }, {10, 0x00000375 }, {10, 0x00000377 }, {11, 0x00000623 },
47  {11, 0x00000684 }, {11, 0x000006AB }, {11, 0x000006EC }, {12, 0x00000C44 }, {12, 0x00000C5C },
48  {12, 0x00000C5E }, {12, 0x00000D55 }, {12, 0x00000DD1 }, {12, 0x00000DD3 }, {12, 0x00000DDB },
49  {13, 0x0000188B }, {13, 0x000018BB }, {13, 0x00001AA8 }, {13, 0x00001BA0 }, {13, 0x00001BA4 },
50  {13, 0x00001BB5 }, {14, 0x00003115 }, {14, 0x00003175 }, {14, 0x0000317D }, {14, 0x00003553 },
51  {14, 0x00003768 }, {15, 0x00006228 }, {15, 0x000062E8 }, {15, 0x000062F8 }, {15, 0x00006AA4 },
52  {15, 0x00006E85 }, {15, 0x00006E87 }, {15, 0x00006ED3 }, {16, 0x0000C453 }, {16, 0x0000C5D3 },
53  {16, 0x0000C5F3 }, {16, 0x0000DD08 }, {16, 0x0000DD0C }, {16, 0x0000DDA4 }, {17, 0x000188A4 },
54  {17, 0x00018BA5 }, {17, 0x00018BE5 }, {17, 0x0001AA95 }, {17, 0x0001AA97 }, {17, 0x0001BA13 },
55  {17, 0x0001BB4A }, {17, 0x0001BB4B }, {18, 0x00031748 }, {18, 0x000317C8 }, {18, 0x00035528 },
56  {18, 0x0003552C }, {18, 0x00037424 }, {18, 0x00037434 }, {18, 0x00037436 }, {19, 0x00062294 },
57  {19, 0x00062E92 }, {19, 0x00062F92 }, {19, 0x0006AA52 }, {19, 0x0006AA5A }, {19, 0x0006E84A },
58  {19, 0x0006E86A }, {19, 0x0006E86E }, {20, 0x000C452A }, {20, 0x000C5D27 }, {20, 0x000C5F26 },
59  {20, 0x000D54A6 }, {20, 0x000D54B6 }, {20, 0x000DD096 }, {20, 0x000DD0D6 }, {20, 0x000DD0DE },
60  {21, 0x00188A56 }, {21, 0x0018BA4D }, {21, 0x0018BE4E }, {21, 0x0018BE4F }, {21, 0x001AA96E },
61  {21, 0x001BA12E }, {21, 0x001BA12F }, {21, 0x001BA1AF }, {21, 0x001BA1BF }, {22, 0x00317498 },
62  {22, 0x0035529C }, {22, 0x0035529D }, {22, 0x003552DE }, {22, 0x003552DF }, {22, 0x0037435D },
63  {22, 0x0037437D }, {23, 0x0062295D }, {23, 0x0062E933 }, {23, 0x006AA53D }, {23, 0x006AA53E },
64  {23, 0x006AA53F }, {23, 0x006E86B9 }, {23, 0x006E86F8 }, {24, 0x00C452B8 }, {24, 0x00C5D265 },
65  {24, 0x00D54A78 }, {24, 0x00D54A79 }, {24, 0x00DD0D70 }, {24, 0x00DD0D71 }, {24, 0x00DD0DF2 },
66  {24, 0x00DD0DF3 }, {26, 0x03114BA2 }, {25, 0x0188A5B1 }, {25, 0x0188A58B }, {25, 0x0188A595 },
67  {25, 0x0188A5D6 }, {25, 0x0188A5D7 }, {25, 0x0188A5A8 }, {25, 0x0188A5AE }, {25, 0x0188A5AF },
68  {25, 0x0188A5C4 }, {25, 0x0188A5C5 }, {25, 0x0188A587 }, {25, 0x0188A584 }, {25, 0x0188A585 },
69  {25, 0x0188A5C6 }, {25, 0x0188A5C7 }, {25, 0x0188A5CC }, {25, 0x0188A5CD }, {25, 0x0188A581 },
70  {25, 0x0188A582 }, {25, 0x0188A583 }, {25, 0x0188A5CE }, {25, 0x0188A5CF }, {25, 0x0188A5C2 },
71  {25, 0x0188A5C3 }, {25, 0x0188A5C1 }, {25, 0x0188A5B4 }, {25, 0x0188A5B5 }, {25, 0x0188A5E6 },
72  {25, 0x0188A5E7 }, {25, 0x0188A5E4 }, {25, 0x0188A5E5 }, {25, 0x0188A5AB }, {25, 0x0188A5E0 },
73  {25, 0x0188A5E1 }, {25, 0x0188A5E2 }, {25, 0x0188A5E3 }, {25, 0x0188A5B6 }, {25, 0x0188A5B7 },
74  {25, 0x0188A5FD }, {25, 0x0188A57E }, {25, 0x0188A57F }, {25, 0x0188A5EC }, {25, 0x0188A5ED },
75  {25, 0x0188A5FE }, {25, 0x0188A5FF }, {25, 0x0188A57D }, {25, 0x0188A59C }, {25, 0x0188A59D },
76  {25, 0x0188A5E8 }, {25, 0x0188A5E9 }, {25, 0x0188A5EA }, {25, 0x0188A5EB }, {25, 0x0188A5EF },
77  {25, 0x0188A57A }, {25, 0x0188A57B }, {25, 0x0188A578 }, {25, 0x0188A579 }, {25, 0x0188A5BA },
78  {25, 0x0188A5BB }, {25, 0x0188A5B8 }, {25, 0x0188A5B9 }, {25, 0x0188A588 }, {25, 0x0188A589 },
79  {25, 0x018BA4C8 }, {25, 0x018BA4C9 }, {25, 0x0188A5FA }, {25, 0x0188A5FB }, {25, 0x0188A5BC },
80  {25, 0x0188A5BD }, {25, 0x0188A598 }, {25, 0x0188A599 }, {25, 0x0188A5F4 }, {25, 0x0188A5F5 },
81  {25, 0x0188A59B }, {25, 0x0188A5DE }, {25, 0x0188A5DF }, {25, 0x0188A596 }, {25, 0x0188A597 },
82  {25, 0x0188A5F8 }, {25, 0x0188A5F9 }, {25, 0x0188A5F1 }, {25, 0x0188A58E }, {25, 0x0188A58F },
83  {25, 0x0188A5DC }, {25, 0x0188A5DD }, {25, 0x0188A5F2 }, {25, 0x0188A5F3 }, {25, 0x0188A58C },
84  {25, 0x0188A58D }, {25, 0x0188A5A4 }, {25, 0x0188A5F0 }, {25, 0x0188A5A5 }, {25, 0x0188A5A6 },
85  {25, 0x0188A5A7 }, {25, 0x0188A59A }, {25, 0x0188A5A2 }, {25, 0x0188A5A3 }, {25, 0x0188A58A },
86  {25, 0x0188A5B0 }, {25, 0x0188A5A0 }, {25, 0x0188A5A1 }, {25, 0x0188A5DA }, {25, 0x0188A5DB },
87  {25, 0x0188A59E }, {25, 0x0188A59F }, {25, 0x0188A5D8 }, {25, 0x0188A5EE }, {25, 0x0188A5D9 },
88  {25, 0x0188A5F6 }, {25, 0x0188A5F7 }, {25, 0x0188A57C }, {25, 0x0188A5C8 }, {25, 0x0188A5C9 },
89  {25, 0x0188A594 }, {25, 0x0188A5FC }, {25, 0x0188A5CA }, {25, 0x0188A5CB }, {25, 0x0188A5B2 },
90  {25, 0x0188A5AA }, {25, 0x0188A5B3 }, {25, 0x0188A572 }, {25, 0x0188A573 }, {25, 0x0188A5C0 },
91  {25, 0x0188A5BE }, {25, 0x0188A5BF }, {25, 0x0188A592 }, {25, 0x0188A580 }, {25, 0x0188A593 },
92  {25, 0x0188A590 }, {25, 0x0188A591 }, {25, 0x0188A586 }, {25, 0x0188A5A9 }, {25, 0x0188A5D2 },
93  {25, 0x0188A5D3 }, {25, 0x0188A5D4 }, {25, 0x0188A5D5 }, {25, 0x0188A5AC }, {25, 0x0188A5AD },
94  {25, 0x0188A5D0 },
95 };
96 
97 /* Derived by extracting runcodes from existing tables from decoder */
98 static const uint16_t runbook[18][3] = {
99  {1, 0x0000, 1}, {2, 0x0000, 2}, {3, 0x0000, 3}, {4, 0x0000, 4},
100  {5, 0x0000, 5}, {6, 0x0000, 6}, {7, 0x0000, 7}, {8, 0x0000, 8},
101  {9, 0x0000, 9}, {10, 0x0000, 10}, {11, 0x0000, 11},
102  {7, 0x0069, 12}, {8, 0x00D1, 20}, {9, 0x018A, 32},
103  {10, 0x0343, 60}, {11, 0x0685, 100}, {13, 0x18BF, 180}, {13, 0x1BA5, 320},
104 };
105 
106 /*
107  * Derived by inspecting various quality encodes
108  * and adding some more from scratch.
109  */
110 static const uint16_t quantization_per_subband[2][3][13][9] = {
111  {{
112  { 16, 16, 8, 4, 4, 2, 6, 6, 9, }, // film3+
113  { 16, 16, 8, 4, 4, 2, 6, 6, 9, }, // film3
114  { 16, 16, 8, 4, 4, 2, 7, 7, 10, }, // film2+
115  { 16, 16, 8, 4, 4, 2, 8, 8, 12, }, // film2
116  { 16, 16, 8, 4, 4, 2, 16, 16, 26, }, // film1++
117  { 24, 24, 12, 6, 6, 3, 24, 24, 36, }, // film1+
118  { 24, 24, 12, 6, 6, 3, 24, 24, 36, }, // film1
119  { 32, 32, 24, 8, 8, 6, 32, 32, 48, }, // high+
120  { 32, 32, 24, 8, 8, 6, 32, 32, 48, }, // high
121  { 48, 48, 32, 12, 12, 8, 64, 64, 96, }, // medium+
122  { 48, 48, 32, 12, 12, 8, 64, 64, 96, }, // medium
123  { 64, 64, 48, 16, 16, 12, 96, 96, 144, }, // low+
124  { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
125  },
126  {
127  { 16, 16, 8, 4, 4, 2, 6, 6, 9, }, // film3+
128  { 16, 16, 8, 4, 4, 2, 6, 6, 12, }, // film3
129  { 16, 16, 8, 4, 4, 2, 7, 7, 14, }, // film2+
130  { 16, 16, 8, 4, 4, 2, 8, 8, 16, }, // film2
131  { 16, 16, 8, 4, 4, 2, 16, 16, 26, }, // film1++
132  { 24, 24, 12, 6, 6, 3, 24, 24, 36, }, // film1+
133  { 24, 24, 12, 6, 6, 3, 24, 24, 48, }, // film1
134  { 32, 32, 24, 8, 8, 6, 32, 32, 48, }, // high+
135  { 48, 48, 32, 12, 12, 8, 32, 32, 64, }, // high
136  { 48, 48, 32, 12, 12, 8, 64, 64, 96, }, // medium+
137  { 48, 48, 32, 12, 12, 8, 64, 64, 128, }, // medium
138  { 64, 64, 48, 16, 16, 12, 96, 96, 160, }, // low+
139  { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
140  },
141  {
142  { 16, 16, 8, 4, 4, 2, 6, 6, 9, }, // film3+
143  { 16, 16, 8, 4, 4, 2, 6, 6, 12, }, // film3
144  { 16, 16, 8, 4, 4, 2, 7, 7, 14, }, // film2+
145  { 16, 16, 8, 4, 4, 2, 8, 8, 16, }, // film2
146  { 16, 16, 8, 4, 4, 2, 16, 16, 26, }, // film1++
147  { 24, 24, 12, 6, 6, 3, 24, 24, 36, }, // film1+
148  { 24, 24, 12, 6, 6, 3, 24, 24, 48, }, // film1
149  { 32, 32, 24, 8, 8, 6, 32, 32, 48, }, // high+
150  { 48, 48, 32, 12, 12, 8, 32, 32, 64, }, // high
151  { 48, 48, 32, 12, 12, 8, 64, 64, 96, }, // medium+
152  { 48, 48, 32, 12, 12, 8, 64, 64, 128, }, // medium
153  { 64, 64, 48, 16, 16, 12, 96, 96, 160, }, // low+
154  { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
155  }},
156  {{
157  { 16, 16, 8, 16, 16, 8, 24, 24, 36, }, // film3+
158  { 16, 16, 8, 16, 16, 8, 24, 24, 36, }, // film3
159  { 16, 16, 8, 16, 16, 8, 32, 32, 48, }, // film2+
160  { 16, 16, 8, 16, 16, 8, 32, 32, 48, }, // film2
161  { 16, 16, 8, 20, 20, 10, 80, 80, 128, }, // film1++
162  { 24, 24, 12, 24, 24, 12, 96, 96, 144, }, // film1+
163  { 24, 24, 12, 24, 24, 12, 96, 96, 144, }, // film1
164  { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
165  { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high
166  { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
167  { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium
168  { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
169  { 64, 64, 48, 64, 64, 48, 512, 512, 768, }, // low
170  },
171  {
172  { 16, 16, 8, 16, 16, 8, 24, 24, 36, }, // film3+
173  { 16, 16, 8, 16, 16, 8, 48, 48, 72, }, // film3
174  { 16, 16, 8, 16, 16, 8, 48, 48, 72, }, // film2+
175  { 16, 16, 8, 16, 16, 8, 64, 64, 96, }, // film2
176  { 16, 16, 8, 20, 20, 10, 80, 80, 128, }, // film1++
177  { 24, 24, 12, 24, 24, 12, 96, 96, 144, }, // film1+
178  { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
179  { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
180  { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
181  { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
182  { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
183  { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
184  { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
185  },
186  {
187  { 16, 16, 8, 16, 16, 8, 24, 24, 36, }, // film3+
188  { 16, 16, 8, 16, 16, 8, 48, 48, 72, }, // film3
189  { 16, 16, 8, 16, 16, 8, 48, 48, 72, }, // film2+
190  { 16, 16, 8, 16, 16, 8, 64, 64, 96, }, // film2
191  { 16, 16, 10, 20, 20, 10, 80, 80, 128, }, // film1++
192  { 24, 24, 12, 24, 24, 12, 96, 96, 144, }, // film1+
193  { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
194  { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
195  { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
196  { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
197  { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
198  { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
199  { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
200  }},
201 };
202 
203 typedef struct Codebook {
204  unsigned bits;
205  unsigned size;
206 } Codebook;
207 
208 typedef struct Runbook {
209  unsigned size;
210  unsigned bits;
211  unsigned run;
212 } Runbook;
213 
214 typedef struct PlaneEnc {
215  unsigned size;
216 
217  int16_t *dwt_buf;
218  int16_t *dwt_tmp;
219 
222  int16_t *l_h[8];
223 
225 } PlaneEnc;
226 
227 typedef struct CFHDEncContext {
228  const AVClass *class;
229 
232 
233  int quality;
234  int planes;
238 
239  uint16_t lut[1024];
240  Runbook rb[321];
241  Codebook cb[513];
242  int16_t *alpha;
243 
246 
248 {
249  CFHDEncContext *s = avctx->priv_data;
250  const int sign_mask = 256;
251  const int twos_complement = -sign_mask;
252  const int mag_mask = sign_mask - 1;
253  int ret, last = 0;
254 
256  &s->chroma_h_shift,
257  &s->chroma_v_shift);
258  if (ret < 0)
259  return ret;
260 
261  if (avctx->height < 4) {
262  av_log(avctx, AV_LOG_ERROR, "Height must be >= 4.\n");
263  return AVERROR_INVALIDDATA;
264  }
265 
266  if (avctx->width & 15) {
267  av_log(avctx, AV_LOG_ERROR, "Width must be multiple of 16.\n");
268  return AVERROR_INVALIDDATA;
269  }
270 
271  s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
272 
273  for (int i = 0; i < s->planes; i++) {
274  int w8, h8, w4, h4, w2, h2;
275  const int a_height = FFALIGN(avctx->height, 8);
276  int width = i ? AV_CEIL_RSHIFT(avctx->width, s->chroma_h_shift) : avctx->width;
277  int height = i ? a_height >> s->chroma_v_shift: a_height;
278 
279  w8 = width / 8 + 64;
280  h8 = height / 8;
281  w4 = w8 * 2;
282  h4 = h8 * 2;
283  w2 = w4 * 2;
284  h2 = h4 * 2;
285 
286  s->plane[i].dwt_buf =
287  av_calloc(h8 * 8 * w8 * 8, sizeof(*s->plane[i].dwt_buf));
288  s->plane[i].dwt_tmp =
289  av_malloc_array(h8 * 8 * w8 * 8, sizeof(*s->plane[i].dwt_tmp));
290  if (!s->plane[i].dwt_buf || !s->plane[i].dwt_tmp)
291  return AVERROR(ENOMEM);
292 
293  s->plane[i].subband[0] = s->plane[i].dwt_buf;
294  s->plane[i].subband[1] = s->plane[i].dwt_buf + 2 * w8 * h8;
295  s->plane[i].subband[2] = s->plane[i].dwt_buf + 1 * w8 * h8;
296  s->plane[i].subband[3] = s->plane[i].dwt_buf + 3 * w8 * h8;
297  s->plane[i].subband[4] = s->plane[i].dwt_buf + 2 * w4 * h4;
298  s->plane[i].subband[5] = s->plane[i].dwt_buf + 1 * w4 * h4;
299  s->plane[i].subband[6] = s->plane[i].dwt_buf + 3 * w4 * h4;
300  s->plane[i].subband[7] = s->plane[i].dwt_buf + 2 * w2 * h2;
301  s->plane[i].subband[8] = s->plane[i].dwt_buf + 1 * w2 * h2;
302  s->plane[i].subband[9] = s->plane[i].dwt_buf + 3 * w2 * h2;
303 
304  for (int j = 0; j < DWT_LEVELS; j++) {
305  for (int k = 0; k < FF_ARRAY_ELEMS(s->plane[i].band[j]); k++) {
306  s->plane[i].band[j][k].width = (width / 8) << j;
307  s->plane[i].band[j][k].height = height >> (DWT_LEVELS - j);
308  s->plane[i].band[j][k].a_width = w8 << j;
309  s->plane[i].band[j][k].a_height = h8 << j;
310  }
311  }
312 
313  /* ll2 and ll1 commented out because they are done in-place */
314  s->plane[i].l_h[0] = s->plane[i].dwt_tmp;
315  s->plane[i].l_h[1] = s->plane[i].dwt_tmp + 2 * w8 * h8;
316  // s->plane[i].l_h[2] = ll2;
317  s->plane[i].l_h[3] = s->plane[i].dwt_tmp;
318  s->plane[i].l_h[4] = s->plane[i].dwt_tmp + 2 * w4 * h4;
319  // s->plane[i].l_h[5] = ll1;
320  s->plane[i].l_h[6] = s->plane[i].dwt_tmp;
321  s->plane[i].l_h[7] = s->plane[i].dwt_tmp + 2 * w2 * h2;
322  }
323 
324  for (int i = 0; i < 512; i++) {
325  int value = (i & sign_mask) ? twos_complement + (i & mag_mask): i;
326  int mag = FFMIN(FFABS(value), 255);
327 
328  if (mag) {
329  s->cb[i].bits = (codebook[mag][1] << 1) | (value > 0 ? 0 : 1);
330  s->cb[i].size = codebook[mag][0] + 1;
331  } else {
332  s->cb[i].bits = codebook[mag][1];
333  s->cb[i].size = codebook[mag][0];
334  }
335  }
336 
337  s->cb[512].bits = 0x3114ba3;
338  s->cb[512].size = 26;
339 
340  s->rb[0].run = 0;
341 
342  for (int i = 1, j = 0; i < 320 && j < 17; j++) {
343  int run = runbook[j][2];
344  int end = runbook[j+1][2];
345 
346  while (i < end) {
347  s->rb[i].run = run;
348  s->rb[i].bits = runbook[j][1];
349  s->rb[i++].size = runbook[j][0];
350  }
351  }
352 
353  s->rb[320].bits = runbook[17][1];
354  s->rb[320].size = runbook[17][0];
355  s->rb[320].run = 320;
356 
357  for (int i = 0; i < 256; i++) {
358  int idx = i + ((768LL * i * i * i) / (256 * 256 * 256));
359 
360  s->lut[idx] = i;
361  }
362  for (int i = 0; i < 1024; i++) {
363  if (s->lut[i])
364  last = s->lut[i];
365  else
366  s->lut[i] = last;
367  }
368 
369  ff_cfhdencdsp_init(&s->dsp);
370 
371  if (s->planes != 4)
372  return 0;
373 
374  s->alpha = av_calloc(avctx->width * avctx->height, sizeof(*s->alpha));
375  if (!s->alpha)
376  return AVERROR(ENOMEM);
377 
378  return 0;
379 }
380 
381 static void quantize_band(int16_t *input, int width, int a_width,
382  int height, unsigned quantization)
383 {
384  const int16_t factor = (uint32_t)(1U << 15) / quantization;
385 
386  for (int i = 0; i < height; i++) {
387  for (int j = 0; j < width; j++)
388  input[j] = av_clip_intp2(((input[j] * factor + 16384 * FFSIGN(input[j])) / 32768), 10);
389  input += a_width;
390  }
391 }
392 
393 static int put_runcode(PutBitContext *pb, int count, const Runbook *const rb)
394 {
395  while (count > 0) {
396  const int index = FFMIN(320, count);
397 
398  put_bits(pb, rb[index].size, rb[index].bits);
399  count -= rb[index].run;
400  }
401 
402  return 0;
403 }
404 
405 static void process_alpha(const int16_t *src, int width, int height, ptrdiff_t stride, int16_t *dst)
406 {
407  for (int i = 0; i < height; i++) {
408  for (int j = 0; j < width; j++) {
409  int alpha = src[j];
410 
411  if (alpha > 0 && alpha < 4080) {
412  alpha *= 223;
413  alpha += 128;
414  alpha >>= 8;
415  alpha += 256;
416  }
417 
418  dst[j] = av_clip_uintp2(alpha, 12);
419  }
420 
421  src += stride;
422  dst += width;
423  }
424 }
425 
427  const AVFrame *frame, int *got_packet)
428 {
429  CFHDEncContext *s = avctx->priv_data;
430  CFHDEncDSPContext *dsp = &s->dsp;
431  PutByteContext *pby = &s->pby;
432  PutBitContext *pb = &s->pb;
433  const Codebook *const cb = s->cb;
434  const Runbook *const rb = s->rb;
435  const uint16_t *lut = s->lut;
436  unsigned pos;
437  int ret;
438 
439  for (int plane = 0; plane < s->planes; plane++) {
440  const int h_shift = plane ? s->chroma_h_shift : 0;
441  int width = s->plane[plane].band[2][0].width;
442  int a_width = s->plane[plane].band[2][0].a_width;
443  int height = s->plane[plane].band[2][0].height;
444  int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
445  const int16_t *input = (int16_t *)frame->data[act_plane];
446  int16_t *buf;
447  int16_t *low = s->plane[plane].l_h[6];
448  int16_t *high = s->plane[plane].l_h[7];
449  ptrdiff_t in_stride = frame->linesize[act_plane] / 2;
450  int low_stride, high_stride;
451 
452  if (plane == 3) {
453  process_alpha(input, avctx->width, avctx->height,
454  in_stride, s->alpha);
455  input = s->alpha;
456  in_stride = avctx->width;
457  }
458 
459  dsp->horiz_filter(input, low, high,
460  in_stride, a_width, a_width,
461  avctx->width >> h_shift, avctx->height);
462 
463  input = s->plane[plane].l_h[7];
464  low = s->plane[plane].subband[7];
465  low_stride = s->plane[plane].band[2][0].a_width;
466  high = s->plane[plane].subband[9];
467  high_stride = s->plane[plane].band[2][0].a_width;
468 
469  dsp->vert_filter(input, low, high,
470  a_width, low_stride, high_stride,
471  width, height * 2);
472 
473  input = s->plane[plane].l_h[6];
474  low = s->plane[plane].l_h[7];
475  high = s->plane[plane].subband[8];
476 
477  dsp->vert_filter(input, low, high,
478  a_width, low_stride, high_stride,
479  width, height * 2);
480 
481  a_width = s->plane[plane].band[1][0].a_width;
482  width = s->plane[plane].band[1][0].width;
483  height = s->plane[plane].band[1][0].height;
484  input = s->plane[plane].l_h[7];
485  low = s->plane[plane].l_h[3];
486  low_stride = s->plane[plane].band[1][0].a_width;
487  high = s->plane[plane].l_h[4];
488  high_stride = s->plane[plane].band[1][0].a_width;
489 
490  buf = s->plane[plane].l_h[7];
491  for (int i = 0; i < height * 2; i++) {
492  for (int j = 0; j < width * 2; j++)
493  buf[j] /= 4;
494  buf += a_width * 2;
495  }
496 
497  dsp->horiz_filter(input, low, high,
498  a_width * 2, low_stride, high_stride,
499  width * 2, height * 2);
500 
501  input = s->plane[plane].l_h[4];
502  low = s->plane[plane].subband[4];
503  high = s->plane[plane].subband[6];
504 
505  dsp->vert_filter(input, low, high,
506  a_width, low_stride, high_stride,
507  width, height * 2);
508 
509  input = s->plane[plane].l_h[3];
510  low = s->plane[plane].l_h[4];
511  high = s->plane[plane].subband[5];
512 
513  dsp->vert_filter(input, low, high,
514  a_width, low_stride, high_stride,
515  width, height * 2);
516 
517  a_width = s->plane[plane].band[0][0].a_width;
518  width = s->plane[plane].band[0][0].width;
519  height = s->plane[plane].band[0][0].height;
520  input = s->plane[plane].l_h[4];
521  low = s->plane[plane].l_h[0];
522  low_stride = s->plane[plane].band[0][0].a_width;
523  high = s->plane[plane].l_h[1];
524  high_stride = s->plane[plane].band[0][0].a_width;
525 
526  if (avctx->pix_fmt != AV_PIX_FMT_YUV422P10) {
527  int16_t *buf = s->plane[plane].l_h[4];
528  for (int i = 0; i < height * 2; i++) {
529  for (int j = 0; j < width * 2; j++)
530  buf[j] /= 4;
531  buf += a_width * 2;
532  }
533  }
534 
535  dsp->horiz_filter(input, low, high,
536  a_width * 2, low_stride, high_stride,
537  width * 2, height * 2);
538 
539  low = s->plane[plane].subband[1];
540  high = s->plane[plane].subband[3];
541  input = s->plane[plane].l_h[1];
542 
543  dsp->vert_filter(input, low, high,
544  a_width, low_stride, high_stride,
545  width, height * 2);
546 
547  low = s->plane[plane].subband[0];
548  high = s->plane[plane].subband[2];
549  input = s->plane[plane].l_h[0];
550 
551  dsp->vert_filter(input, low, high,
552  a_width, low_stride, high_stride,
553  width, height * 2);
554  }
555 
556  ret = ff_alloc_packet(avctx, pkt, 256LL + s->planes * (2LL * avctx->width * (avctx->height + 15) + 2048LL));
557  if (ret < 0)
558  return ret;
559 
561 
562  bytestream2_put_be16(pby, SampleType);
563  bytestream2_put_be16(pby, 9);
564 
565  bytestream2_put_be16(pby, SampleIndexTable);
566  bytestream2_put_be16(pby, s->planes);
567 
568  for (int i = 0; i < s->planes; i++)
569  bytestream2_put_be32(pby, 0);
570 
571  bytestream2_put_be16(pby, TransformType);
572  bytestream2_put_be16(pby, 0);
573 
574  bytestream2_put_be16(pby, NumFrames);
575  bytestream2_put_be16(pby, 1);
576 
577  bytestream2_put_be16(pby, ChannelCount);
578  bytestream2_put_be16(pby, s->planes);
579 
580  bytestream2_put_be16(pby, EncodedFormat);
581  bytestream2_put_be16(pby, avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 1 : 3 + (s->planes == 4));
582 
583  bytestream2_put_be16(pby, WaveletCount);
584  bytestream2_put_be16(pby, 3);
585 
586  bytestream2_put_be16(pby, SubbandCount);
587  bytestream2_put_be16(pby, SUBBAND_COUNT);
588 
589  bytestream2_put_be16(pby, NumSpatial);
590  bytestream2_put_be16(pby, 2);
591 
592  bytestream2_put_be16(pby, FirstWavelet);
593  bytestream2_put_be16(pby, 3);
594 
595  bytestream2_put_be16(pby, ImageWidth);
596  bytestream2_put_be16(pby, avctx->width);
597 
598  bytestream2_put_be16(pby, ImageHeight);
599  bytestream2_put_be16(pby, FFALIGN(avctx->height, 8));
600 
601  bytestream2_put_be16(pby, -DisplayHeight);
602  bytestream2_put_be16(pby, avctx->height);
603 
604  bytestream2_put_be16(pby, -FrameNumber);
605  bytestream2_put_be16(pby, frame->pts & 0xFFFF);
606 
607  bytestream2_put_be16(pby, Precision);
608  bytestream2_put_be16(pby, avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12);
609 
610  bytestream2_put_be16(pby, PrescaleTable);
611  bytestream2_put_be16(pby, avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 0x2000 : 0x2800);
612 
613  bytestream2_put_be16(pby, SampleFlags);
614  bytestream2_put_be16(pby, 1);
615 
616  for (int p = 0; p < s->planes; p++) {
617  int width = s->plane[p].band[0][0].width;
618  int a_width = s->plane[p].band[0][0].a_width;
619  int height = s->plane[p].band[0][0].height;
620  int16_t *data = s->plane[p].subband[0];
621 
622  if (p) {
623  bytestream2_put_be16(pby, SampleType);
624  bytestream2_put_be16(pby, 3);
625 
626  bytestream2_put_be16(pby, ChannelNumber);
627  bytestream2_put_be16(pby, p);
628  }
629 
630  bytestream2_put_be16(pby, BitstreamMarker);
631  bytestream2_put_be16(pby, 0x1a4a);
632 
633  pos = bytestream2_tell_p(pby);
634 
635  bytestream2_put_be16(pby, LowpassSubband);
636  bytestream2_put_be16(pby, 0);
637 
638  bytestream2_put_be16(pby, NumLevels);
639  bytestream2_put_be16(pby, 3);
640 
641  bytestream2_put_be16(pby, LowpassWidth);
642  bytestream2_put_be16(pby, width);
643 
644  bytestream2_put_be16(pby, LowpassHeight);
645  bytestream2_put_be16(pby, height);
646 
647  bytestream2_put_be16(pby, PixelOffset);
648  bytestream2_put_be16(pby, 0);
649 
650  bytestream2_put_be16(pby, LowpassQuantization);
651  bytestream2_put_be16(pby, 1);
652 
653  bytestream2_put_be16(pby, LowpassPrecision);
654  bytestream2_put_be16(pby, 16);
655 
656  bytestream2_put_be16(pby, BitstreamMarker);
657  bytestream2_put_be16(pby, 0x0f0f);
658 
659  for (int i = 0; i < height; i++) {
660  for (int j = 0; j < width; j++)
661  bytestream2_put_be16(pby, data[j]);
662  data += a_width;
663  }
664 
665  bytestream2_put_be16(pby, BitstreamMarker);
666  bytestream2_put_be16(pby, 0x1b4b);
667 
668  for (int l = 0; l < 3; l++) {
669  for (int i = 0; i < 3; i++) {
670  s->plane[p].quantization[1 + l * 3 + i] = quantization_per_subband[avctx->pix_fmt != AV_PIX_FMT_YUV422P10][p >= 3 ? 0 : p][s->quality][l * 3 + i];
671  }
672  }
673 
674  for (int l = 0; l < 3; l++) {
675  int a_width = s->plane[p].band[l][0].a_width;
676  int width = s->plane[p].band[l][0].width;
677  int stride = FFALIGN(width, 8);
678  int height = s->plane[p].band[l][0].height;
679 
680  bytestream2_put_be16(pby, BitstreamMarker);
681  bytestream2_put_be16(pby, 0x0d0d);
682 
683  bytestream2_put_be16(pby, WaveletType);
684  bytestream2_put_be16(pby, 3 + 2 * (l == 2));
685 
686  bytestream2_put_be16(pby, WaveletNumber);
687  bytestream2_put_be16(pby, 3 - l);
688 
689  bytestream2_put_be16(pby, WaveletLevel);
690  bytestream2_put_be16(pby, 3 - l);
691 
692  bytestream2_put_be16(pby, NumBands);
693  bytestream2_put_be16(pby, 4);
694 
695  bytestream2_put_be16(pby, HighpassWidth);
696  bytestream2_put_be16(pby, width);
697 
698  bytestream2_put_be16(pby, HighpassHeight);
699  bytestream2_put_be16(pby, height);
700 
701  bytestream2_put_be16(pby, LowpassBorder);
702  bytestream2_put_be16(pby, 0);
703 
704  bytestream2_put_be16(pby, HighpassBorder);
705  bytestream2_put_be16(pby, 0);
706 
707  bytestream2_put_be16(pby, LowpassScale);
708  bytestream2_put_be16(pby, 1);
709 
710  bytestream2_put_be16(pby, LowpassDivisor);
711  bytestream2_put_be16(pby, 1);
712 
713  for (int i = 0; i < 3; i++) {
714  int16_t *data = s->plane[p].subband[1 + l * 3 + i];
715  int count = 0, padd = 0;
716 
717  bytestream2_put_be16(pby, BitstreamMarker);
718  bytestream2_put_be16(pby, 0x0e0e);
719 
720  bytestream2_put_be16(pby, SubbandNumber);
721  bytestream2_put_be16(pby, i + 1);
722 
723  bytestream2_put_be16(pby, BandCodingFlags);
724  bytestream2_put_be16(pby, 1);
725 
726  bytestream2_put_be16(pby, BandWidth);
727  bytestream2_put_be16(pby, width);
728 
729  bytestream2_put_be16(pby, BandHeight);
730  bytestream2_put_be16(pby, height);
731 
732  bytestream2_put_be16(pby, SubbandBand);
733  bytestream2_put_be16(pby, 1 + l * 3 + i);
734 
735  bytestream2_put_be16(pby, BandEncoding);
736  bytestream2_put_be16(pby, 3);
737 
738  bytestream2_put_be16(pby, Quantization);
739  bytestream2_put_be16(pby, s->plane[p].quantization[1 + l * 3 + i]);
740 
741  bytestream2_put_be16(pby, BandScale);
742  bytestream2_put_be16(pby, 1);
743 
744  bytestream2_put_be16(pby, BandHeader);
745  bytestream2_put_be16(pby, 0);
746 
747  quantize_band(data, width, a_width, height,
748  s->plane[p].quantization[1 + l * 3 + i]);
749 
751 
752  for (int m = 0; m < height; m++) {
753  for (int j = 0; j < stride; j++) {
754  int16_t index = j >= width ? 0 : FFSIGN(data[j]) * lut[FFABS(data[j])];
755 
756  if (index < 0)
757  index += 512;
758  if (index == 0) {
759  count++;
760  continue;
761  } else if (count > 0) {
762  count = put_runcode(pb, count, rb);
763  }
764 
765  put_bits(pb, cb[index].size, cb[index].bits);
766  }
767 
768  data += a_width;
769  }
770 
771  if (count > 0) {
772  count = put_runcode(pb, count, rb);
773  }
774 
775  put_bits(pb, cb[512].size, cb[512].bits);
776 
777  flush_put_bits(pb);
779  padd = (4 - (bytestream2_tell_p(pby) & 3)) & 3;
780  while (padd--)
781  bytestream2_put_byte(pby, 0);
782 
783  bytestream2_put_be16(pby, BandTrailer);
784  bytestream2_put_be16(pby, 0);
785  }
786 
787  bytestream2_put_be16(pby, BitstreamMarker);
788  bytestream2_put_be16(pby, 0x0c0c);
789  }
790 
791  s->plane[p].size = bytestream2_tell_p(pby) - pos;
792  }
793 
794  bytestream2_put_be16(pby, GroupTrailer);
795  bytestream2_put_be16(pby, 0);
796 
798 
800 
801  bytestream2_seek_p(pby, 8, SEEK_SET);
802  for (int i = 0; i < s->planes; i++)
803  bytestream2_put_be32(pby, s->plane[i].size);
804 
805  *got_packet = 1;
806 
807  return 0;
808 }
809 
811 {
812  CFHDEncContext *s = avctx->priv_data;
813 
814  for (int i = 0; i < s->planes; i++) {
815  av_freep(&s->plane[i].dwt_buf);
816  av_freep(&s->plane[i].dwt_tmp);
817 
818  for (int j = 0; j < SUBBAND_COUNT; j++)
819  s->plane[i].subband[j] = NULL;
820 
821  for (int j = 0; j < 8; j++)
822  s->plane[i].l_h[j] = NULL;
823  }
824 
825  av_freep(&s->alpha);
826 
827  return 0;
828 }
829 
830 #define OFFSET(x) offsetof(CFHDEncContext, x)
831 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
832 static const AVOption options[] = {
833  { "quality", "set quality", OFFSET(quality), AV_OPT_TYPE_INT, {.i64= 0}, 0, 12, VE, "q" },
834  { "film3+", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 0}, 0, 0, VE, "q" },
835  { "film3", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 1}, 0, 0, VE, "q" },
836  { "film2+", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 2}, 0, 0, VE, "q" },
837  { "film2", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 3}, 0, 0, VE, "q" },
838  { "film1.5", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 4}, 0, 0, VE, "q" },
839  { "film1+", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 5}, 0, 0, VE, "q" },
840  { "film1", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 6}, 0, 0, VE, "q" },
841  { "high+", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 7}, 0, 0, VE, "q" },
842  { "high", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 8}, 0, 0, VE, "q" },
843  { "medium+", NULL, 0, AV_OPT_TYPE_CONST, {.i64= 9}, 0, 0, VE, "q" },
844  { "medium", NULL, 0, AV_OPT_TYPE_CONST, {.i64=10}, 0, 0, VE, "q" },
845  { "low+", NULL, 0, AV_OPT_TYPE_CONST, {.i64=11}, 0, 0, VE, "q" },
846  { "low", NULL, 0, AV_OPT_TYPE_CONST, {.i64=12}, 0, 0, VE, "q" },
847  { NULL},
848 };
849 
850 static const AVClass cfhd_class = {
851  .class_name = "cfhd",
852  .item_name = av_default_item_name,
853  .option = options,
854  .version = LIBAVUTIL_VERSION_INT,
855 };
856 
858  .p.name = "cfhd",
859  CODEC_LONG_NAME("GoPro CineForm HD"),
860  .p.type = AVMEDIA_TYPE_VIDEO,
861  .p.id = AV_CODEC_ID_CFHD,
862  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
863  .priv_data_size = sizeof(CFHDEncContext),
864  .p.priv_class = &cfhd_class,
865  .init = cfhd_encode_init,
866  .close = cfhd_encode_close,
868  .p.pix_fmts = (const enum AVPixelFormat[]) {
873  },
874  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
875 };
Runbook::run
unsigned run
Definition: cfhdenc.c:211
ChannelNumber
@ ChannelNumber
Definition: cfhd.h:77
ChannelCount
@ ChannelCount
Definition: cfhd.h:41
process_alpha
static void process_alpha(const int16_t *src, int width, int height, ptrdiff_t stride, int16_t *dst)
Definition: cfhdenc.c:405
LowpassSubband
@ LowpassSubband
Definition: cfhd.h:51
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
Precision
@ Precision
Definition: cfhd.h:80
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
GroupTrailer
@ GroupTrailer
Definition: cfhd.h:46
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
VE
#define VE
Definition: cfhdenc.c:831
BandHeader
@ BandHeader
Definition: cfhd.h:75
quantization_per_subband
static const uint16_t quantization_per_subband[2][3][13][9]
Definition: cfhdenc.c:110
PrescaleTable
@ PrescaleTable
Definition: cfhd.h:88
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:239
BandHeight
@ BandHeight
Definition: cfhd.h:70
cfhd_class
static const AVClass cfhd_class
Definition: cfhdenc.c:850
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:119
PlaneEnc::quantization
unsigned quantization[SUBBAND_COUNT]
Definition: cfhdenc.c:220
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
WaveletCount
@ WaveletCount
Definition: cfhd.h:42
NumSpatial
@ NumSpatial
Definition: cfhd.h:44
SampleType
int32_t SampleType
Definition: ac3enc.h:67
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:221
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVOption
AVOption.
Definition: opt.h:251
encode.h
BandScale
@ BandScale
Definition: cfhd.h:74
HighpassWidth
@ HighpassWidth
Definition: cfhd.h:62
bytestream2_tell_p
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:197
data
const char data[16]
Definition: mxf.c:146
Runbook::bits
unsigned bits
Definition: cfhdenc.c:210
WaveletNumber
@ WaveletNumber
Definition: cfhd.h:59
FFCodec
Definition: codec_internal.h:119
FrameNumber
@ FrameNumber
Definition: cfhd.h:79
LowpassWidth
@ LowpassWidth
Definition: cfhd.h:53
CFHDEncContext::plane
PlaneEnc plane[4]
Definition: cfhdenc.c:237
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
thread.h
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
LowpassQuantization
@ LowpassQuantization
Definition: cfhd.h:56
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2898
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:123
cfhd.h
CFHDEncContext::planes
int planes
Definition: cfhdenc.c:234
Codebook::bits
unsigned bits
Definition: cfhdenc.c:204
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:112
FFSIGN
#define FFSIGN(a)
Definition: common.h:65
LowpassDivisor
@ LowpassDivisor
Definition: cfhd.h:67
WaveletLevel
@ WaveletLevel
Definition: cfhd.h:60
DWT_LEVELS
#define DWT_LEVELS
Definition: cfhd.h:105
FirstWavelet
@ FirstWavelet
Definition: cfhd.h:45
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2886
LowpassPrecision
@ LowpassPrecision
Definition: cfhd.h:57
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:307
Quantization
@ Quantization
Definition: cfhd.h:73
Runbook
Definition: cfhdenc.c:208
BandEncoding
@ BandEncoding
Definition: cfhd.h:72
WaveletType
@ WaveletType
Definition: cfhd.h:58
SubbandNumber
@ SubbandNumber
Definition: cfhd.h:68
NumFrames
@ NumFrames
Definition: cfhd.h:40
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
bytestream2_get_bytes_left_p
static av_always_inline int bytestream2_get_bytes_left_p(PutByteContext *p)
Definition: bytestream.h:163
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
PlaneEnc::dwt_buf
int16_t * dwt_buf
Definition: cfhdenc.c:217
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
options
static const AVOption options[]
Definition: cfhdenc.c:832
AV_CODEC_ID_CFHD
@ AV_CODEC_ID_CFHD
Definition: codec_id.h:270
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:256
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:480
TransformType
TransformType
Definition: webp.c:112
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
LowpassScale
@ LowpassScale
Definition: cfhd.h:66
bits
uint8_t bits
Definition: vp3data.h:128
cfhd_encode_init
static av_cold int cfhd_encode_init(AVCodecContext *avctx)
Definition: cfhdenc.c:247
DisplayHeight
@ DisplayHeight
Definition: cfhd.h:90
cfhd_encode_frame
static int cfhd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: cfhdenc.c:426
cfhd_encode_close
static av_cold int cfhd_encode_close(AVCodecContext *avctx)
Definition: cfhdenc.c:810
PutBitContext
Definition: put_bits.h:50
PlaneEnc
Definition: cfhdenc.c:214
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:264
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
if
if(ret)
Definition: filter_design.txt:179
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:113
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
PlaneEnc::subband
int16_t * subband[SUBBAND_COUNT]
Definition: cfhdenc.c:221
Codebook::size
unsigned size
Definition: cfhdenc.c:205
NULL
#define NULL
Definition: coverity.c:32
av_clip_intp2
#define av_clip_intp2
Definition: common.h:116
run
uint8_t run
Definition: svq3.c:203
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:460
CFHDEncContext::pby
PutByteContext pby
Definition: cfhdenc.c:231
HighpassHeight
@ HighpassHeight
Definition: cfhd.h:63
index
int index
Definition: gxfenc.c:89
SUBBAND_COUNT
#define SUBBAND_COUNT
Definition: cfhd.h:96
PutByteContext
Definition: bytestream.h:37
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
CFHDEncContext::lut
uint16_t lut[1024]
Definition: cfhdenc.c:239
AVPacket::size
int size
Definition: packet.h:375
codec_internal.h
CFHDEncContext::quality
int quality
Definition: cfhdenc.c:233
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
BitstreamMarker
@ BitstreamMarker
Definition: cfhd.h:34
PlaneEnc::size
unsigned size
Definition: cfhdenc.c:215
size
int size
Definition: twinvq_data.h:10344
Runbook::size
unsigned size
Definition: cfhdenc.c:209
cfhdencdsp.h
SubBand
Definition: cfhd.h:108
PlaneEnc::l_h
int16_t * l_h[8]
Definition: cfhdenc.c:222
height
#define height
CFHDEncDSPContext::vert_filter
void(* vert_filter)(const int16_t *input, int16_t *low, int16_t *high, ptrdiff_t in_stride, ptrdiff_t low_stride, ptrdiff_t high_stride, int width, int height)
Definition: cfhdencdsp.h:31
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
CFHDEncContext
Definition: cfhdenc.c:227
NumBands
@ NumBands
Definition: cfhd.h:61
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
SubbandCount
@ SubbandCount
Definition: cfhd.h:43
bytestream2_skip_p
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
Definition: bytestream.h:180
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:476
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
LowpassBorder
@ LowpassBorder
Definition: cfhd.h:64
SubbandBand
@ SubbandBand
Definition: cfhd.h:71
Codebook
Definition: cfhdenc.c:203
PlaneEnc::band
SubBand band[DWT_LEVELS][4]
Definition: cfhdenc.c:224
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
CFHDEncContext::pb
PutBitContext pb
Definition: cfhdenc.c:230
PlaneEnc::dwt_tmp
int16_t * dwt_tmp
Definition: cfhdenc.c:218
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:211
CFHDEncDSPContext::horiz_filter
void(* horiz_filter)(const int16_t *input, int16_t *low, int16_t *high, ptrdiff_t in_stride, ptrdiff_t low_stride, ptrdiff_t high_stride, int width, int height)
Definition: cfhdencdsp.h:26
AVCodecContext::height
int height
Definition: avcodec.h:571
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:608
ImageWidth
@ ImageWidth
Definition: cfhd.h:48
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
CFHDEncContext::chroma_h_shift
int chroma_h_shift
Definition: cfhdenc.c:235
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
CFHDEncContext::dsp
CFHDEncDSPContext dsp
Definition: cfhdenc.c:244
pos
unsigned int pos
Definition: spdifenc.c:412
BandCodingFlags
@ BandCodingFlags
Definition: cfhd.h:82
U
#define U(x)
Definition: vpx_arith.h:37
EncodedFormat
@ EncodedFormat
Definition: cfhd.h:89
ff_cfhdencdsp_init
av_cold void ff_cfhdencdsp_init(CFHDEncDSPContext *c)
Definition: cfhdencdsp.c:71
AVCodecContext
main external API structure.
Definition: avcodec.h:398
runbook
static const uint16_t runbook[18][3]
Definition: cfhdenc.c:98
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
bytestream2_seek_p
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:236
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
CFHDEncContext::cb
Codebook cb[513]
Definition: cfhdenc.c:241
ImageHeight
@ ImageHeight
Definition: cfhd.h:49
BandTrailer
@ BandTrailer
Definition: cfhd.h:76
BandWidth
@ BandWidth
Definition: cfhd.h:69
CFHDEncContext::chroma_v_shift
int chroma_v_shift
Definition: cfhdenc.c:236
factor
static const int factor[16]
Definition: vf_pp7.c:76
SampleFlags
@ SampleFlags
Definition: cfhd.h:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
CFHDEncDSPContext
Definition: cfhdencdsp.h:25
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
NumLevels
@ NumLevels
Definition: cfhd.h:52
LowpassHeight
@ LowpassHeight
Definition: cfhd.h:54
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:425
HighpassBorder
@ HighpassBorder
Definition: cfhd.h:65
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:571
bytestream.h
imgutils.h
CFHDEncContext::rb
Runbook rb[321]
Definition: cfhdenc.c:240
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
quantize_band
static void quantize_band(int16_t *input, int width, int a_width, int height, unsigned quantization)
Definition: cfhdenc.c:381
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
OFFSET
#define OFFSET(x)
Definition: cfhdenc.c:830
put_runcode
static int put_runcode(PutBitContext *pb, int count, const Runbook *const rb)
Definition: cfhdenc.c:393
put_bits.h
SampleIndexTable
@ SampleIndexTable
Definition: cfhd.h:33
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
ff_cfhd_encoder
const FFCodec ff_cfhd_encoder
Definition: cfhdenc.c:857
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:35
CFHDEncContext::alpha
int16_t * alpha
Definition: cfhdenc.c:242
codebook
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
PixelOffset
@ PixelOffset
Definition: cfhd.h:55