46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
47 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
48 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
49 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
50 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
51 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
52 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
53 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
54 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
55 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
56 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
57 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
58 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1,
59 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
60 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
61 -1, -1, -1, -1, -1, -1, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0,
65 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
66 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
67 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
68 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
69 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
70 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
71 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
72 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
73 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
74 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
75 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
76 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
77 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
78 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
79 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
80 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1,
84 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
85 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
87 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
88 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
89 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
90 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
91 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
92 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
93 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
94 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
95 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
96 -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3,
97 -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
98 -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
99 -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -0, -0, -0, -0,
103 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
104 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
105 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
106 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
107 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
108 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
109 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
110 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
112 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
113 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
114 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
115 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
116 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -4, -4,
117 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
118 -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -1,
122 0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49,
123 59, 25, 26, 26, 27, 31, 33, 33, 33, 34, 34, 37, 67, 38, 39, 39,
124 40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52,
125 53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69,
126 87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97,
127 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
128 105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125,
129 115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129,
130 165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148,
131 147, 155, 151, 149, 151, 150, 152, 157, 153, 154, 156, 168, 158, 162, 161, 160,
132 172, 163, 169, 164, 166, 184, 167, 170, 177, 174, 171, 173, 182, 176, 180, 178,
133 175, 189, 179, 181, 186, 183, 192, 185, 200, 187, 191, 188, 190, 197, 193, 196,
134 197, 194, 195, 196, 198, 202, 199, 201, 210, 203, 207, 204, 205, 206, 208, 214,
135 209, 211, 221, 212, 213, 215, 224, 216, 217, 218, 219, 220, 222, 228, 223, 225,
136 226, 224, 227, 229, 240, 230, 231, 232, 233, 234, 235, 236, 238, 239, 237, 242,
137 241, 243, 242, 244, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255,
141 const uint8_t one_state[256])
146 for (
i = 1;
i < 256;
i++)
147 l2tab[
i] = -
log2(
i / 256.0) * ((1U << 31) / 8);
149 for (
i = 0;
i < 256;
i++) {
150 uint64_t best_len[256];
152 for (j = 0; j < 256; j++)
153 best_len[j] = UINT64_MAX;
155 for (j =
FFMAX(
i - 10, 1); j <
FFMIN(
i + 11, 256); j++) {
156 uint32_t occ[256] = { 0 };
163 for (k = 0; k < 256; k++) {
164 uint32_t newocc[256] = { 0 };
165 for (m = 1; m < 256; m++)
167 len += (occ[m]*((
i *(uint64_t)l2tab[ m]
168 + (256-
i)*(uint64_t)l2tab[256-m])>>8)) >> 8;
170 if (
len < best_len[k]) {
172 best_state[
i][k] = j;
174 for (m = 1; m < 256; m++)
176 newocc[ one_state[ m]] += occ[m] * (uint64_t)
i >> 8;
177 newocc[256 - one_state[256 - m]] += occ[m] * (uint64_t)(256 -
i) >> 8;
179 memcpy(occ, newocc,
sizeof(occ));
186 uint8_t *
state,
int v,
188 uint64_t rc_stat[256][2],
189 uint64_t rc_stat2[32][2])
193#define put_rac(C, S, B) \
196 rc_stat[*(S)][B]++; \
197 rc_stat2[(S) - state][B]++; \
203 const unsigned a = is_signed ?
FFABS(v) : v;
207 for (
i = 0;
i < e;
i++)
211 for (
i = e - 1;
i >= 0;
i--)
217 for (
i = 0;
i < e;
i++)
221 for (
i = e - 1;
i >= 0;
i--)
234 int v,
int is_signed)
257 ff_dlog(
NULL,
"v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v,
code,
265#define RENAME(name) name
271#define RENAME(name) name ## 32
275 const uint8_t *
src,
int w,
int h,
276 int stride,
int plane_index,
int remap_index,
int pixel_stride,
int ac)
280 const int ring_size =
f->context_model ? 3 : 2;
288 for (y = 0; y <
h; y++) {
295 if (
f->bits_per_raw_sample <= 8) {
296 for (x = 0; x <
w; x++)
299 for (x = 0; x <
w; x++)
305 if (
f->packed_at_lsb) {
306 for (x = 0; x <
w; x++) {
310 for (x = 0; x <
w; x++) {
311 sample[0][x] = ((uint16_t*)(
src +
stride*y))[x * pixel_stride] >> (16 -
f->bits_per_raw_sample);
315 for (x = 0; x <
w; x++)
326 const uint8_t *
src,
int w,
int h,
327 int stride,
int remap_index,
int pixel_stride)
331 memset(sc->
fltmap[remap_index], 0, 65536 *
sizeof(*sc->
fltmap[remap_index]));
333 for (y = 0; y <
h; y++) {
334 if (
f->bits_per_raw_sample <= 8) {
335 for (x = 0; x <
w; x++)
338 if (
f->packed_at_lsb) {
339 for (x = 0; x <
w; x++)
340 sc->
fltmap[remap_index][ ((uint16_t*)(
src +
stride*y))[x * pixel_stride] ] = 1;
342 for (x = 0; x <
w; x++)
343 sc->
fltmap[remap_index][ ((uint16_t*)(
src +
stride*y))[x * pixel_stride] >> (16 -
f->bits_per_raw_sample) ] = 1;
368 for (
i = 0;
i < 5;
i++)
377 for (
int i = 0;
i < nb_contexts;
i++)
379 if (initial_state[
i][j] != 128)
392 if (
f->version < 2) {
396 for (
i = 1;
i < 256;
i++)
398 f->state_transition[
i] -
c->one_state[
i], 1);
409 }
else if (
f->version < 3) {
411 for (
i = 0;
i <
f->slice_count;
i++) {
414 (
fs->slice_x + 1) *
f->num_h_slices /
f->width, 0);
416 (
fs->slice_y + 1) *
f->num_v_slices /
f->height, 0);
418 (
fs->slice_width + 1) *
f->num_h_slices /
f->width - 1,
421 (
fs->slice_height + 1) *
f->num_v_slices /
f->height - 1,
423 for (j = 0; j <
f->plane_count; j++) {
425 av_assert0(
fs->plane[j].quant_table_index ==
f->context_model);
433 f->combined_version =
f->version << 16;
434 if (
f->version > 2) {
435 if (
f->version == 3) {
436 f->micro_version = 4;
437 }
else if (
f->version == 4) {
438 f->micro_version = 10;
442 f->combined_version +=
f->micro_version;
457 memset(state2, 128,
sizeof(state2));
460 f->avctx->extradata_size = 10000 + 4 +
461 (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;
463 if (!
f->avctx->extradata)
474 for (
i = 1;
i < 256;
i++)
483 if (
f->colorspace == 2)
489 for (
i = 0;
i <
f->quant_table_count;
i++)
492 for (
i = 0;
i <
f->quant_table_count;
i++) {
495 for (j = 0; j <
f->context_count[
i]; j++)
497 int pred = j ?
f->initial_states[
i][j - 1][k] : 128;
499 (int8_t)(
f->initial_states[
i][j][k] -
pred), 1);
506 if (
f->version > 2) {
509 if (
f->combined_version >= 0x40004)
515 AV_WL32(
f->avctx->extradata +
f->avctx->extradata_size, v);
516 f->avctx->extradata_size += 4;
523 int i, i2, changed,
print = 0;
527 for (
i = 12;
i < 244;
i++) {
528 for (i2 =
i + 1; i2 < 245 && i2 <
i + 4; i2++) {
530#define COST(old, new) \
531 s->rc_stat[old][0] * -log2((256 - (new)) / 256.0) + \
532 s->rc_stat[old][1] * -log2((new) / 256.0)
534#define COST2(old, new) \
535 COST(old, new) + COST(256 - (old), 256 - (new))
539 if (size0 - sizeX > size0*(1e-14) &&
i != 128 && i2 != 128) {
542 FFSWAP(
int,
s->rc_stat[
i][0],
s->rc_stat[i2][0]);
543 FFSWAP(
int,
s->rc_stat[
i][1],
s->rc_stat[i2][1]);
545 FFSWAP(
int, stt[256 -
i], stt[256 - i2]);
546 FFSWAP(
int,
s->rc_stat[256 -
i][0],
s->rc_stat[256 - i2][0]);
547 FFSWAP(
int,
s->rc_stat[256 -
i][1],
s->rc_stat[256 - i2][1]);
549 for (j = 1; j < 256; j++) {
552 else if (stt[j] == i2)
555 if (stt[256 - j] == 256 -
i)
556 stt[256 - j] = 256 - i2;
557 else if (stt[256 - j] == 256 - i2)
558 stt[256 - j] = 256 -
i;
573 int plane_count = 1 + 2*
s->chroma_planes +
s->bayer +
s->transparency;
576 s->num_v_slices = (avctx->
width > 352 || avctx->
height > 288 || !avctx->
slices) ? 2 : 1;
577 s->num_v_slices =
FFMIN(
s->num_v_slices, max_v_slices);
578 for (;
s->num_v_slices <= 32;
s->num_v_slices++) {
579 for (
s->num_h_slices =
s->num_v_slices;
s->num_h_slices <= 2*
s->num_v_slices;
s->num_h_slices++) {
580 int maxw = (avctx->
width +
s->num_h_slices - 1) /
s->num_h_slices;
581 int maxh = (avctx->
height +
s->num_v_slices - 1) /
s->num_v_slices;
582 if (
s->num_h_slices > max_h_slices ||
s->num_v_slices > max_v_slices)
584 if (maxw * maxh * (
int64_t)(
s->bits_per_raw_sample+1) * plane_count > 8<<24)
592 if (maxw*maxh > 360*288)
599 "Unsupported number %d of slices requested, please specify a "
600 "supported number with -slices (ex:4,6,9,12,16, ...)\n",
612 s->version =
FFMAX(
s->version, 2);
621 s->version =
FFMAX(
s->version, 2);
623 if (avctx->
level <= 0 &&
s->version == 2) {
627 if (avctx->
level <
s->version) {
628 av_log(avctx,
AV_LOG_ERROR,
"Version %d needed for requested features but %d requested\n",
s->version, avctx->
level);
631 s->version = avctx->
level;
632 }
else if (
s->version < 3)
636 if (
s->version >= 4) {
638 }
else if (
s->version >= 3) {
646 s->version =
FFMAX(
s->version, 3);
648 s->version =
FFMAX(
s->version, 4);
649 s->crcref = 0x7a8c4079;
653 av_log(avctx,
AV_LOG_ERROR,
"Version 2 or 4 needed for requested features but version 2 or 4 is experimental and not enabled\n");
658 for (
i = 1;
i < 256;
i++)
663 for (
i = 1;
i < 256;
i++)
664 s->state_transition[
i] =
c.one_state[
i];
667 for (
i = 0;
i < 256;
i++) {
668 s->quant_table_count = 2;
669 if ((
s->qtable == -1 &&
s->bits_per_raw_sample <= 8) ||
s->qtable == 1) {
675 s->quant_tables[1][2][
i]= 11*11*
quant5 [
i];
676 s->quant_tables[1][3][
i]= 5*11*11*
quant5 [
i];
677 s->quant_tables[1][4][
i]= 5*5*11*11*
quant5 [
i];
678 s->context_count[0] = (11 * 11 * 11 + 1) / 2;
679 s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
689 s->context_count[0] = (9 * 9 * 9 + 1) / 2;
690 s->context_count[1] = (9 * 9 * 5 * 5 * 5 + 1) / 2;
698 if (
s->context_model == 2) {
699 const int8_t *q5 = (
s->qtable == -1 &&
s->bits_per_raw_sample <= 8) ||
s->qtable == 1 ?
701 s->quant_table_count = 3;
702 for (
i = 0;
i < 256;
i++) {
703 s->quant_tables[2][0][
i] = q5[
i];
704 s->quant_tables[2][1][
i] = 5*q5[
i];
706 s->context_count[2] = (5 * 5 + 1) / 2;
712 if (!
s->transparency)
714 if (!
s->chroma_planes &&
s->version > 3)
719 s->picture_number = 0;
722 for (
i = 0;
i <
s->quant_table_count;
i++) {
724 sizeof(*
s->rc_stat2[
i]));
740 for (j = 0; j < 256; j++)
741 for (
i = 0;
i < 2;
i++) {
742 s->rc_stat[j][
i] = strtol(p, &next, 0);
745 "2Pass file invalid at %d %d [%s]\n", j,
i, p);
751 for (
i = 0;
i <
s->quant_table_count;
i++)
752 for (j = 0; j <
s->context_count[
i]; j++) {
753 for (k = 0; k < 32; k++)
754 for (m = 0; m < 2; m++) {
755 s->rc_stat2[
i][j][k][m] = strtol(p, &next, 0);
758 "2Pass file invalid at %d %d %d %d [%s]\n",
766 gob_count = strtol(p, &next, 0);
767 if (next == p || gob_count <= 0) {
773 while (*p ==
'\n' || *p ==
' ')
783 for (
i = 0;
i <
s->quant_table_count;
i++) {
784 for (k = 0; k < 32; k++) {
787 for (j = 0; j <
s->context_count[
i]; j++) {
789 if (
s->rc_stat2[
i][j][k][0] +
s->rc_stat2[
i][j][k][1] > 200 && j ||
a+
b > 200) {
791 p = 256.0 *
b / (
a +
b);
792 s->initial_states[
i][jp][k] =
794 for(jp++; jp<j; jp++)
795 s->initial_states[
i][jp][k] =
s->initial_states[
i][jp-1][k];
798 a +=
s->rc_stat2[
i][j][k][0];
799 b +=
s->rc_stat2[
i][j][k][1];
801 p = 256.0 *
b / (
a +
b);
803 s->initial_states[
i][j][k] =
811 if (
s->version <= 1) {
839 s->bits_per_raw_sample = 9;
850 s->bits_per_raw_sample = 10;
860 s->bits_per_raw_sample = 12;
867 s->bits_per_raw_sample = 14;
868 s->packed_at_lsb = 1;
883 s->bits_per_raw_sample = 16;
884 }
else if (!
s->bits_per_raw_sample) {
887 if (
s->bits_per_raw_sample <= 8) {
891 s->version =
FFMAX(
s->version, 1);
907 s->chroma_planes =
desc->nb_components < 3 ? 0 : 1;
911 s->bits_per_raw_sample = 8;
912 else if (!
s->bits_per_raw_sample)
913 s->bits_per_raw_sample = 8;
918 s->chroma_planes = 1;
919 s->bits_per_raw_sample = 8;
924 s->chroma_planes = 1;
925 s->bits_per_raw_sample = 16;
927 s->version =
FFMAX(
s->version, 1);
931 s->chroma_planes = 1;
932 s->bits_per_raw_sample = 16;
934 s->version =
FFMAX(
s->version, 1);
938 s->chroma_planes = 1;
939 s->bits_per_raw_sample = 16;
941 s->version =
FFMAX(
s->version, 4);
947 s->chroma_planes = 1;
948 s->bits_per_raw_sample = 8;
952 s->bits_per_raw_sample = 9;
959 s->bits_per_raw_sample = 10;
964 s->bits_per_raw_sample = 12;
969 s->bits_per_raw_sample = 14;
976 s->bits_per_raw_sample = 16;
981 s->bits_per_raw_sample = 32;
982 else if (!
s->bits_per_raw_sample)
986 s->chroma_planes = 1;
987 if (
s->bits_per_raw_sample >= 16) {
990 s->version =
FFMAX(
s->version, 1);
998 if (
s->flt ||
s->remap_mode > 0)
999 s->version =
FFMAX(
s->version, 4);
1002 if (
s->remap_mode < 0)
1003 s->remap_mode =
s->flt ? 2 : 0;
1004 if (
s->remap_mode == 0 &&
s->bits_per_raw_sample == 32) {
1008 if (
s->remap_mode == 2 &&
1009 !((
s->bits_per_raw_sample == 16 ||
s->bits_per_raw_sample == 32 ||
s->bits_per_raw_sample == 64) &&
s->flt)) {
1034 if (
s->bayer && (avctx->
width & 1 || avctx->
height & 1)) {
1039 if (
s->bits_per_raw_sample > (
s->version > 3 ? 16 : 8) && !
s->remap_mode) {
1042 "high bits_per_raw_sample, forcing range coder\n");
1052 if (
s->version > 1) {
1062 ((avctx->
width +
s->num_h_slices - 1) /
s->num_h_slices) *
1063 (
int64_t)((avctx->
height +
s->num_v_slices - 1) /
s->num_v_slices) > 1 << 18) {
1064 av_log(avctx,
AV_LOG_ERROR,
"Slices larger than 262144 pixels are not supported with 32bit floats and the Golomb-Rice coder\n");
1074 s->slice_count =
s->max_slice_count;
1076 for (
int j = 0; j <
s->slice_count; j++) {
1079 for (
int i = 0;
i <
s->plane_count;
i++) {
1082 p->quant_table_index =
s->context_model;
1083 p->context_count =
s->context_count[p->quant_table_index];
1086 if (
s->remap_mode) {
1087 for (
int p = 0; p < 1 + 2*
s->chroma_planes +
s->transparency ; p++) {
1088 if (
s->bits_per_raw_sample == 32) {
1105 s->slices[j].remap =
s->remap_mode;
1111#define STATS_OUT_SIZE 1024 * 1024 * 6
1116 for (
int i = 0;
i <
s->quant_table_count;
i++)
1117 for (
int j = 0; j <
s->max_slice_count; j++) {
1141 for (j=0; j<
f->plane_count; j++) {
1151 if (
f->version > 3) {
1164#define NB_Y_COEFF 15
1172 stat[
i] += partial[
i];
1178 const uint8_t *
src[3],
const int stride[3],
int w,
int h)
1180 static const int rct_y_coeff[15][2] = {
1201 int x, y,
i, p, best;
1203 int lbd =
f->bits_per_raw_sample <= 8;
1204 int packed = !
src[1];
1205 int transparency =
f->transparency;
1206 int packed_size = (3 + transparency)*2;
1208 for (y = 0; y <
h; y++) {
1209 int lastr=0, lastg=0, lastb=0;
1210 for (p = 0; p < 3; p++)
1213 for (x = 0; x <
w; x++) {
1217 unsigned v = *((
const uint32_t*)(
src[0] + x*4 +
stride[0]*y));
1219 g = (v >> 8) & 0xFF;
1220 r = (v >> 16) & 0xFF;
1221 }
else if (packed) {
1222 const uint16_t *p = ((
const uint16_t*)(
src[0] + x*packed_size +
stride[0]*y));
1226 }
else if (
f->use32bit || transparency) {
1227 g = *((
const uint16_t *)(
src[0] + x*2 +
stride[0]*y));
1228 b = *((
const uint16_t *)(
src[1] + x*2 +
stride[1]*y));
1229 r = *((
const uint16_t *)(
src[2] + x*2 +
stride[2]*y));
1231 b = *((
const uint16_t*)(
src[0] + x*2 +
stride[0]*y));
1232 g = *((
const uint16_t*)(
src[1] + x*2 +
stride[1]*y));
1233 r = *((
const uint16_t*)(
src[2] + x*2 +
stride[2]*y));
1240 int bg = ag -
sample[0][x];
1241 int bb = ab -
sample[1][x];
1242 int br = ar -
sample[2][x];
1248 partial[
i] +=
FFABS(bg + ((br*rct_y_coeff[
i][0] + bb*rct_y_coeff[
i][1])>>2));
1259 if ((x & 4095) == 4095)
1267 if (stat[
i] < stat[best])
1276 const uint8_t *
src[4],
const int stride[4],
1279 static const int rct_y_coeff[
NB_Y_COEFF][2] = {
1280 { 0, 0 }, { 1, 1 }, { 2, 2 }, { 0, 2 }, { 2, 0 }, { 4, 0 }, { 0, 4 }, { 0, 3 },
1281 { 3, 0 }, { 3, 1 }, { 1, 3 }, { 1, 2 }, { 2, 1 }, { 0, 1 }, { 1, 0 },
1290 for (
i = 0;
i < 3;
i++)
1293 for (
int y = 0; y <
h; y += 2) {
1294 int last_gm = 0, last_b = 0, last_r = 0;
1295 for (
int x = 0; x <
w; x++) {
1296 const uint16_t *l1 = (
const uint16_t *)(
src[0] +
stride[0]*(y + 0) + x*2*2);
1297 const uint16_t *l2 = (
const uint16_t *)(
src[0] +
stride[0]*(y + 1) + x*2*2);
1303 int gm = gb + (gd >> 1);
1305 int agm = gm - last_gm;
1306 int ab =
b - last_b;
1307 int ar =
r - last_r;
1310 int bgm = agm -
sample[0][x];
1311 int bb = ab -
sample[1][x];
1312 int br = ar -
sample[2][x];
1318 partial[
i] +=
FFABS(bgm + ((br*rct_y_coeff[
i][0] + bb*rct_y_coeff[
i][1]) >> 2));
1327 if ((x & 4095) == 4095)
1335 if (stat[
i] < stat[best])
1344 int len = 1 <<
f->bits_per_raw_sample;
1347 for (
int p= 0; p < 1 + 2*
f->chroma_planes +
f->transparency; p++) {
1350 uint8_t
state[2][32];
1356 for (
int i= 0;
i<
len;
i++) {
1357 int ri =
i ^ ((
i&0x8000) ? 0 :
flip);
1378 const uint8_t *
src[4],
1382 int transparency =
f->transparency;
1385 for (y = 0; y <
h; y++) {
1386 for (x = 0; x <
w; x++) {
1389 g = *((
const uint32_t *)(
src[0] + x*4 +
stride[0]*y));
1390 b = *((
const uint32_t *)(
src[1] + x*4 +
stride[1]*y));
1391 r = *((
const uint32_t *)(
src[2] + x*4 +
stride[2]*y));
1393 a = *((
const uint32_t *)(
src[3] + x*4 +
stride[3]*y));
1395 if (sc->
remap == 2) {
1396#define FLIP(f) (((f)&0x80000000) ? (f) : (f)^0x7FFFFFFF);
1421#define CMP(A,B) ((A)->val - (int64_t)(B)->val)
1430 int p,
int mul_count,
int *mul_tab,
int update,
int final)
1433 uint8_t
state[2][3][32];
1439 int compact_index = -1;
1441 int current_mul_index = -1;
1444 int run1start_last_val;
1445 int run1start_mul_index;
1447 memcpy(mul, mul_tab,
sizeof(*mul_tab)*(mul_count+1));
1452 for (;
i < pixel_num+1;
i++) {
1453 int current_mul = current_mul_index < 0 ? 1 :
FFABS(mul[current_mul_index]);
1455 if (
i == pixel_num) {
1456 if (last_val == 0xFFFFFFFF && (!
run || run1final)) {
1459 val = last_val + ((1LL<<32) - last_val + current_mul - 1) / current_mul * current_mul;
1461 val += lu * current_mul;
1466 if (last_val !=
val) {
1472 delta -= step*current_mul;
1479 run1start_i =
i - 1;
1480 run1start_last_val = last_val;
1481 run1start_mul_index= current_mul_index;
1495 last_val += current_mul;
1499 last_val = run1start_last_val;
1500 current_mul_index = run1start_mul_index;
1512 if (current_mul > 1)
1520 current_mul_index = ((last_val + 1) * mul_count) >> 32;
1521 if (!
run || run1final) {
1523 if (mul[ current_mul_index ] < 0) {
1525 mul[ current_mul_index ] *= -1;
1532 if (!
run || run1final)
1533 if (
final &&
i < pixel_num)
1545 const uint8_t *
src[4])
1548 const int max_log2_mul_count = ((
int[]){ 1, 1, 1, 9, 9, 10})[
f->remap_optimizer];
1549 const int log2_mul_count_step = ((
int[]){ 1, 1, 1, 9, 9, 1})[
f->remap_optimizer];
1550 const int max_log2_mul = ((
int[]){ 1, 8, 8, 9, 22, 22})[
f->remap_optimizer];
1551 const int log2_mul_step = ((
int[]){ 1, 8, 1, 1, 1, 1})[
f->remap_optimizer];
1552 const int bruteforce_count = ((
int[]){ 0, 0, 0, 1, 1, 1})[
f->remap_optimizer];
1553 const int stair_mode = ((
int[]){ 0, 0, 0, 1, 0, 0})[
f->remap_optimizer];
1554 const int magic_log2 = ((
int[]){ 1, 1, 1, 1, 0, 0})[
f->remap_optimizer];
1556 for (
int p= 0; p < 1 + 2*
f->chroma_planes +
f->transparency; p++) {
1557 int best_log2_mul_count = 0;
1558 float score_sum[11] = {0};
1559 int mul_all[11][1025];
1561 for (
int log2_mul_count= 0; log2_mul_count <= max_log2_mul_count; log2_mul_count += log2_mul_count_step) {
1562 float score_tab_all[1025][23] = {0};
1564 int *mul_tab = mul_all[log2_mul_count];
1565 int last_mul_index = -1;
1566 int mul_count = 1 << log2_mul_count;
1568 score_sum[log2_mul_count] = 2 * log2_mul_count;
1570 score_sum[log2_mul_count] =
av_float2int((
float)mul_count * mul_count);
1571 for (
int i= 0;
i<pixel_num;
i++) {
1573 int mul_index = (
val + 1LL)*mul_count >> 32;
1574 if (
val != last_val) {
1575 float *score_tab = score_tab_all[(last_val + 1LL)*mul_count >> 32];
1577 for(
int si= 0; si <= max_log2_mul; si += log2_mul_step) {
1584 }
else if (stair_mode && mul_count == 512 && si == max_log2_mul ) {
1585 if (mul_index >= 0x378/8 && mul_index <= 23 + 0x378/8) {
1586 mul = (0x800080 >> (mul_index - 0x378/8));
1590 mul = (0x10001LL)<<si >> 16;
1602 if (mul_index != last_mul_index)
1607 score_tab[si] +=
log2f(score);
1611 last_mul_index = mul_index;
1613 for(
int i= 0;
i<mul_count;
i++) {
1615 float *score_tab = score_tab_all[
i];
1616 for(
int si= 0; si <= max_log2_mul; si += log2_mul_step) {
1617 if (score_tab[si] < score_tab[ best_index ])
1620 if (stair_mode && mul_count == 512 && best_index == max_log2_mul ) {
1621 if (
i >= 0x378/8 &&
i <= 23 + 0x378/8) {
1622 mul_tab[
i] = -(0x800080 >> (
i - 0x378/8));
1626 mul_tab[
i] = -((0x10001LL)<<best_index >> 16);
1627 score_sum[log2_mul_count] += score_tab[ best_index ];
1629 mul_tab[mul_count] = 1;
1631 if (bruteforce_count)
1634 if (score_sum[log2_mul_count] < score_sum[best_log2_mul_count])
1635 best_log2_mul_count = log2_mul_count;
1643 const uint8_t *
src[4],
1644 int w,
int h,
const int stride[4],
int ac)
1647 const int ring_size =
f->context_model ? 3 : 2;
1651 int transparency =
f->transparency;
1663 for (y = 0; y <
h; y++) {
1668 for (x = 0; x <
w; x++) {
1689 for (p = 0; p < 3 + transparency; p++) {
1693 ret = encode_line32(
f, sc,
f->avctx,
w,
sample[p], (p + 1) / 2,
1694 bits[p], ac, pass1);
1703 const uint8_t *
src[4],
1704 int w,
int h,
const int stride[4],
int ac)
1707 const int ring_size =
f->context_model ? 3 : 2;
1723 for (
int y = 0; y <
h; y += 2) {
1729 for (
int x = 0; x <
w; x++) {
1730 const uint16_t *l1 = ((
const uint16_t*)(
src[0] +
stride[0]*(y + 0) + x*2*2));
1731 const uint16_t *l2 = ((
const uint16_t*)(
src[0] +
stride[0]*(y + 1) + x*2*2));
1746 int gm = gb + (gd >> 1);
1765 for (
int p = 0; p < 4; p++) {
1773 p == 1 ? 2 : (p > 1),
1774 bits[p], ac, pass1);
1791 const AVFrame *
const p =
f->cur_enc_frame;
1797 const uint8_t *
planes[4] = {p->data[0] + ps*x + y*p->linesize[0],
1798 p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] :
NULL,
1799 p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] :
NULL,
1800 p->data[3] ? p->data[3] + ps*x + y*p->linesize[3] :
NULL};
1804 if (
f->version > 3 &&
f->colorspace == 1) {
1806 }
else if (
f->bayer) {
1816 if (
f->version > 2) {
1824 if (
f->bits_per_raw_sample != 32) {
1826 const int cx = x >>
f->chroma_h_shift;
1827 const int cy = y >>
f->chroma_v_shift;
1834 if (
f->chroma_planes) {
1835 load_plane(
f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
1836 load_plane(
f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 2, 1);
1838 if (
f->transparency)
1843 }
else if (
f->use32bit) {
1863 const int cx = x >>
f->chroma_h_shift;
1864 const int cy = y >>
f->chroma_v_shift;
1868 if (
f->chroma_planes) {
1869 ret |=
encode_plane(
f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1, 1, ac);
1870 ret |=
encode_plane(
f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 2, 1, ac);
1872 if (
f->transparency)
1877 }
else if (
f->bits_per_raw_sample == 32) {
1879 }
else if (
f->bayer) {
1881 }
else if (
f->use32bit) {
1896 if (
f->version < 4) {
1914 int w = avctx->
width +
f->num_h_slices;
1915 int h = avctx->
height +
f->num_v_slices;
1916 size_t maxsize =
w*
h * (1 +
f->transparency);
1917 if (
f->chroma_planes)
1919 maxsize +=
f->slice_count * 800;
1920 if (
f->version > 3) {
1921 maxsize *=
f->bits_per_raw_sample + 1;
1923 maxsize +=
f->slice_count * 70000 * (1 + 2*
f->chroma_planes +
f->bayer +
f->transparency);
1925 maxsize +=
f->slice_count * 2 * (avctx->
width + avctx->
height);
1926 maxsize *= 8*(2*
f->bits_per_raw_sample + 5);
1935 const AVFrame *pict,
int *got_packet)
1939 uint8_t keystate = 128;
1950 memset(
f->rc_stat, 0,
sizeof(
f->rc_stat));
1951 for (
i = 0;
i <
f->quant_table_count;
i++)
1952 memset(
f->rc_stat2[
i], 0,
f->context_count[
i] *
sizeof(*
f->rc_stat2[
i]));
1955 for (j = 0; j <
f->slice_count; j++) {
1957 for (
i = 0;
i < 256;
i++) {
1961 for (
i = 0;
i <
f->quant_table_count;
i++) {
1962 for (k = 0; k <
f->context_count[
i]; k++)
1963 for (m = 0; m < 32; m++) {
1964 f->rc_stat2[
i][k][m][0] += sc->
rc_stat2[
i][k][m][0];
1965 f->rc_stat2[
i][k][m][1] += sc->
rc_stat2[
i][k][m][1];
1970 for (j = 0; j < 256; j++) {
1971 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1972 f->rc_stat[j][0],
f->rc_stat[j][1]);
1975 snprintf(p, end - p,
"\n");
1977 for (
i = 0;
i <
f->quant_table_count;
i++) {
1978 for (j = 0; j <
f->context_count[
i]; j++)
1979 for (m = 0; m < 32; m++) {
1980 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1981 f->rc_stat2[
i][j][m][0],
f->rc_stat2[
i][j][m][1]);
1985 snprintf(p, end - p,
"%d\n",
f->gob_count);
1995 if (!
f->maxsize_warned) {
1996 av_log(avctx,
AV_LOG_WARNING,
"Cannot allocate worst case packet size, the encoding could fail\n");
1997 f->maxsize_warned++;
2008 f->cur_enc_frame = pict;
2022 for (
i = 1;
i < 256;
i++) {
2023 c->one_state[
i] =
f->state_transition[
i];
2024 c->zero_state[256 -
i] = 256 -
c->one_state[
i];
2028 for (
i = 0;
i <
f->slice_count;
i++) {
2031 int len =
pkt->size /
f->slice_count;
2041 f->slice_count,
sizeof(*
f->slices));
2044 for (
i = 0;
i <
f->slice_count;
i++) {
2047 if (
i > 0 ||
f->version > 2) {
2051 AV_WB24(buf_p + bytes, bytes);
2067 f->picture_number++;
2068 pkt->size = buf_p -
pkt->data;
2079 for (
int j = 0; j <
s->max_slice_count; j++) {
2082 for(
int p = 0; p<4; p++) {
2094#define OFFSET(x) offsetof(FFV1Context, x)
2095#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
2099 { .i64 = 0 }, -2, 2,
VE, .unit =
"coder" },
2106 {
"ac",
"Range with custom table (the ac option exists for compatibility and is deprecated)", 0,
AV_OPT_TYPE_CONST,
2107 { .i64 = 1 }, INT_MIN, INT_MAX,
VE, .unit =
"coder" },
2109 { .i64 = 0 }, 0, 2,
VE },
2111 { .i64 = -1 }, -1, 2,
VE , .unit =
"qtable"},
2115 { .i64 =
QTABLE_8BIT }, INT_MIN, INT_MAX,
VE, .unit =
"qtable" },
2118 {
"remap_mode",
"Remap Mode",
OFFSET(remap_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2,
VE, .unit =
"remap_mode" },
2120 { .i64 = -1 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2122 { .i64 = 0 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2124 { .i64 = 1 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2126 { .i64 = 2 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2127 {
"remap_optimizer",
"Remap Optimizer",
OFFSET(remap_optimizer),
AV_OPT_TYPE_INT, { .i64 = 3 }, 0, 5,
VE, .unit =
"remap_optimizer" },
2133 .class_name =
"ffv1 encoder",
static double val(void *priv, double ch)
static av_always_inline void update(AVFilterContext *ctx, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
const FFCodec ff_ffv1_encoder
static int ring_size(RingBuffer *ring)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Public header for CRC hash function implementation.
static av_cold int encode_close(AVCodecContext *avctx)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static enum AVPixelFormat pix_fmt
int(* init)(AVBSFContext *ctx)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
static const uint8_t bits[8]
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
int ff_need_new_slices(int width, int num_h_slices, int chroma_shift)
av_cold void ff_ffv1_close(FFV1Context *s)
int ff_ffv1_allocate_initial_states(FFV1Context *f)
void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
void ff_ffv1_compute_bits_per_plane(const FFV1Context *f, FFV1SliceContext *sc, int bits[4], int *offset, int mask[4], int bits_per_raw_sample)
av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
FF Video Codec 1 (a lossless codec)
static void update_vlc_state(VlcState *const state, const int v)
#define MAX_QUANT_TABLE_SIZE
#define AC_RANGE_DEFAULT_TAB_FORCE
#define AC_RANGE_CUSTOM_TAB
#define AC_RANGE_DEFAULT_TAB
static av_always_inline int fold(int diff, int bits)
#define MAX_CONTEXT_INPUTS
static void write_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE])
static int encode_float32_rgb_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4], int ac)
int ff_ffv1_encode_determine_slices(AVCodecContext *avctx)
static void write_quant_table(RangeCoder *c, int16_t *quant_table)
static av_noinline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed)
static int contains_non_128(uint8_t(*initial_state)[CONTEXT_SIZE], int nb_contexts)
static int encode_slice(AVCodecContext *c, void *arg)
static void set_micro_version(FFV1Context *f)
static void choose_rct_params_bayer(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], const int stride[4], int w, int h)
static void put_vlc_symbol(PutBitContext *pb, VlcState *const state, int v, int bits)
static void write_header(FFV1Context *f)
av_cold int ff_ffv1_encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static const int8_t quant9_10bit[256]
static int encode_float32_remap_segment(FFV1SliceContext *sc, int p, int mul_count, int *mul_tab, int update, int final)
static const int8_t quant5[256]
static int encode_bayer_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4], int ac)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static void load_rgb_float32_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4])
static const int8_t quant5_10bit[256]
static void encode_histogram_remap(FFV1Context *f, FFV1SliceContext *sc)
static int sort_stt(FFV1Context *s, uint8_t stt[256])
static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[3], const int stride[3], int w, int h)
static const AVClass ffv1_class
static av_always_inline av_flatten void put_symbol_inline(RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2])
static av_cold int encode_init_internal(AVCodecContext *avctx)
static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc)
size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx)
av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
static const int8_t quant11[256]
static av_always_inline void accumulate_rct_stats(int64_t stat[NB_Y_COEFF], int partial[NB_Y_COEFF])
static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256])
av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx)
static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4])
static void load_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int remap_index, int pixel_stride)
static int encode_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int plane_index, int remap_index, int pixel_stride, int ac)
static const uint8_t ver2_state[256]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
static const int16_t quant_table[64]
#define u(width, name, range_min, range_max)
static void flip(AVCodecContext *avctx, AVFrame *frame)
Macro definitions for various function/variable attributes.
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define FFSWAP(type, a, b)
Memory handling functions.
static void encode_line(AVCodecContext *avctx, uint8_t **data, const uint8_t *line, int length)
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.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_GRAYF16
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRAP14
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRAPF16
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_BAYER_RGGB16
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_X2RGB10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GBRPF16
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
exp golomb vlc writing stuff
static void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len)
write signed golomb rice code (ffv1).
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
int ff_rac_terminate(RangeCoder *c, int version)
Terminates the range coder.
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
av_cold void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size)
static int get_rac_count(RangeCoder *c)
static const float pred[4]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
char * stats_out
pass1 encoding statistics output buffer
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
int level
Encoding level descriptor.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int flags
AV_CODEC_FLAG_*.
int slices
Number of slices.
int step
Number of elements between 2 horizontally consecutive pixels.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int ac_byte_count
number of bytes used for AC coding
uint64_t(*[MAX_QUANT_TABLES] rc_stat2)[32][2]
int32_t * sample_buffer32
struct FFV1SliceContext::Unit * unit[4]
uint8_t * bytestream_start
#define av_malloc_array(a, b)
static struct @232240247175332074307271266321204261331170211232 state
static void print(AVTreeNode *t, int depth)