44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
45 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
46 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
47 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49 2, 2, 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, -1,
57 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
59 -1, -1, -1, -1, -1, -1, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0,
63 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
64 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
65 2, 2, 2, 2, 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, -1, -1, -1,
82 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
84 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
85 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
86 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
87 4, 4, 4, 4, 4, 4, 4, 4, 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, -3, -3, -3, -3, -3, -3, -3,
95 -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
96 -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
97 -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -0, -0, -0, -0,
101 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
102 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
103 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
104 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
105 5, 5, 5, 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, -4, -4,
115 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
116 -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -1,
120 0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49,
121 59, 25, 26, 26, 27, 31, 33, 33, 33, 34, 34, 37, 67, 38, 39, 39,
122 40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52,
123 53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69,
124 87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97,
125 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
126 105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125,
127 115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129,
128 165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148,
129 147, 155, 151, 149, 151, 150, 152, 157, 153, 154, 156, 168, 158, 162, 161, 160,
130 172, 163, 169, 164, 166, 184, 167, 170, 177, 174, 171, 173, 182, 176, 180, 178,
131 175, 189, 179, 181, 186, 183, 192, 185, 200, 187, 191, 188, 190, 197, 193, 196,
132 197, 194, 195, 196, 198, 202, 199, 201, 210, 203, 207, 204, 205, 206, 208, 214,
133 209, 211, 221, 212, 213, 215, 224, 216, 217, 218, 219, 220, 222, 228, 223, 225,
134 226, 224, 227, 229, 240, 230, 231, 232, 233, 234, 235, 236, 238, 239, 237, 242,
135 241, 243, 242, 244, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255,
144 for (
i = 1;
i < 256;
i++)
145 l2tab[
i] =
log2(
i / 256.0);
147 for (
i = 0;
i < 256;
i++) {
148 double best_len[256];
149 double p =
i / 256.0;
151 for (j = 0; j < 256; j++)
152 best_len[j] = 1 << 30;
154 for (j =
FFMAX(
i - 10, 1); j <
FFMIN(
i + 11, 256); j++) {
155 double occ[256] = { 0 };
162 for (k = 0; k < 256; k++) {
163 double newocc[256] = { 0 };
164 for (m = 1; m < 256; m++)
166 len -=occ[m]*( p *l2tab[ m]
167 + (1-p)*l2tab[256-m]);
169 if (
len < best_len[k]) {
171 best_state[
i][k] = j;
173 for (m = 1; m < 256; m++)
175 newocc[ one_state[ m]] += occ[m] * p;
176 newocc[256 - one_state[256 - m]] += occ[m] * (1 - p);
178 memcpy(occ, newocc,
sizeof(occ));
187 uint64_t rc_stat[256][2],
188 uint64_t rc_stat2[32][2])
192 #define put_rac(C, S, B) \
195 rc_stat[*(S)][B]++; \
196 rc_stat2[(S) - state][B]++; \
202 const unsigned a = is_signed ?
FFABS(v) : v;
206 for (
i = 0;
i < e;
i++)
210 for (
i = e - 1;
i >= 0;
i--)
216 for (
i = 0;
i < e;
i++)
220 for (
i = e - 1;
i >= 0;
i--)
233 int v,
int is_signed)
247 while (i < state->error_sum) {
256 ff_dlog(
NULL,
"v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v,
code,
264 #define RENAME(name) name
270 #define RENAME(name) name ## 32
274 int stride,
int plane_index,
int pixel_stride)
277 const int ring_size =
s->context_model ? 3 : 2;
283 memset(
s->sample_buffer, 0,
ring_size * (
w + 6) *
sizeof(*
s->sample_buffer));
285 for (y = 0; y <
h; y++) {
291 if (
s->bits_per_raw_sample <= 8) {
292 for (x = 0; x <
w; x++)
297 if (
s->packed_at_lsb) {
298 for (x = 0; x <
w; x++) {
302 for (x = 0; x <
w; x++) {
303 sample[0][x] = ((uint16_t*)(
src +
stride*y))[x] >> (16 -
s->bits_per_raw_sample);
320 for (
i = 1;
i < 128;
i++)
332 for (
i = 0;
i < 5;
i++)
341 for (
int i = 0;
i < nb_contexts;
i++)
343 if (initial_state[
i][j] != 128)
356 if (
f->version < 2) {
360 for (
i = 1;
i < 256;
i++)
362 f->state_transition[
i] -
c->one_state[
i], 1);
373 }
else if (
f->version < 3) {
375 for (
i = 0;
i <
f->slice_count;
i++) {
378 (
fs->slice_x + 1) *
f->num_h_slices /
f->width, 0);
380 (
fs->slice_y + 1) *
f->num_v_slices /
f->height, 0);
382 (
fs->slice_width + 1) *
f->num_h_slices /
f->width - 1,
385 (
fs->slice_height + 1) *
f->num_v_slices /
f->height - 1,
387 for (j = 0; j <
f->plane_count; j++) {
389 av_assert0(
f->plane[j].quant_table_index ==
f->context_model);
403 memset(state2, 128,
sizeof(state2));
406 f->avctx->extradata_size = 10000 + 4 +
407 (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;
409 if (!
f->avctx->extradata)
415 if (
f->version > 2) {
416 if (
f->version == 3) {
417 f->micro_version = 4;
418 }
else if (
f->version == 4)
419 f->micro_version = 2;
425 for (
i = 1;
i < 256;
i++)
438 for (
i = 0;
i <
f->quant_table_count;
i++)
441 for (
i = 0;
i <
f->quant_table_count;
i++) {
444 for (j = 0; j <
f->context_count[
i]; j++)
446 int pred = j ?
f->initial_states[
i][j - 1][k] : 128;
448 (int8_t)(
f->initial_states[
i][j][k] -
pred), 1);
455 if (
f->version > 2) {
462 AV_WL32(
f->avctx->extradata +
f->avctx->extradata_size, v);
463 f->avctx->extradata_size += 4;
470 int i, i2, changed,
print = 0;
474 for (
i = 12;
i < 244;
i++) {
475 for (i2 =
i + 1; i2 < 245 && i2 <
i + 4; i2++) {
477 #define COST(old, new) \
478 s->rc_stat[old][0] * -log2((256 - (new)) / 256.0) + \
479 s->rc_stat[old][1] * -log2((new) / 256.0)
481 #define COST2(old, new) \
482 COST(old, new) + COST(256 - (old), 256 - (new))
486 if (size0 - sizeX > size0*(1e-14) &&
i != 128 && i2 != 128) {
489 FFSWAP(
int,
s->rc_stat[
i][0],
s->rc_stat[i2][0]);
490 FFSWAP(
int,
s->rc_stat[
i][1],
s->rc_stat[i2][1]);
492 FFSWAP(
int, stt[256 -
i], stt[256 - i2]);
493 FFSWAP(
int,
s->rc_stat[256 -
i][0],
s->rc_stat[256 - i2][0]);
494 FFSWAP(
int,
s->rc_stat[256 -
i][1],
s->rc_stat[256 - i2][1]);
496 for (j = 1; j < 256; j++) {
499 else if (stt[j] == i2)
502 if (stt[256 - j] == 256 -
i)
503 stt[256 - j] = 256 - i2;
504 else if (stt[256 - j] == 256 - i2)
505 stt[256 - j] = 256 -
i;
529 s->version =
FFMAX(
s->version, 2);
538 s->version =
FFMAX(
s->version, 2);
540 if (avctx->
level <= 0 &&
s->version == 2) {
544 if (avctx->
level <
s->version) {
545 av_log(avctx,
AV_LOG_ERROR,
"Version %d needed for requested features but %d requested\n",
s->version, avctx->
level);
548 s->version = avctx->
level;
552 s->ec = (
s->version >= 3);
557 s->version =
FFMAX(
s->version, 3);
560 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");
564 #if FF_API_CODER_TYPE
586 s->bits_per_raw_sample = 9;
596 s->bits_per_raw_sample = 10;
603 s->bits_per_raw_sample = 12;
608 s->bits_per_raw_sample = 14;
609 s->packed_at_lsb = 1;
618 s->bits_per_raw_sample = 16;
619 }
else if (!
s->bits_per_raw_sample) {
622 if (
s->bits_per_raw_sample <= 8) {
626 s->version =
FFMAX(
s->version, 1);
638 s->chroma_planes =
desc->nb_components < 3 ? 0 : 1;
642 s->bits_per_raw_sample = 8;
643 else if (!
s->bits_per_raw_sample)
644 s->bits_per_raw_sample = 8;
649 s->chroma_planes = 1;
650 s->bits_per_raw_sample = 8;
655 s->chroma_planes = 1;
656 s->bits_per_raw_sample = 16;
658 s->version =
FFMAX(
s->version, 1);
662 s->chroma_planes = 1;
663 s->bits_per_raw_sample = 16;
665 s->version =
FFMAX(
s->version, 1);
669 s->chroma_planes = 1;
670 s->bits_per_raw_sample = 8;
674 s->bits_per_raw_sample = 9;
678 s->bits_per_raw_sample = 10;
682 s->bits_per_raw_sample = 12;
685 s->bits_per_raw_sample = 14;
689 s->bits_per_raw_sample = 16;
690 else if (!
s->bits_per_raw_sample)
694 s->chroma_planes = 1;
695 if (
s->bits_per_raw_sample >= 16) {
698 s->version =
FFMAX(
s->version, 1);
706 if (
s->bits_per_raw_sample > 8) {
709 "bits_per_raw_sample > 8, forcing range coder\n");
713 #if FF_API_PRIVATE_OPT
725 for (
i = 1;
i < 256;
i++)
730 for (
i = 1;
i < 256;
i++)
731 s->state_transition[
i] =
c.one_state[
i];
734 for (
i = 0;
i < 256;
i++) {
735 s->quant_table_count = 2;
736 if (
s->bits_per_raw_sample <= 8) {
742 s->quant_tables[1][2][
i]= 11*11*
quant5 [
i];
743 s->quant_tables[1][3][
i]= 5*11*11*
quant5 [
i];
744 s->quant_tables[1][4][
i]= 5*5*11*11*
quant5 [
i];
745 s->context_count[0] = (11 * 11 * 11 + 1) / 2;
746 s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
756 s->context_count[0] = (9 * 9 * 9 + 1) / 2;
757 s->context_count[1] = (9 * 9 * 5 * 5 * 5 + 1) / 2;
760 memcpy(
s->quant_table,
s->quant_tables[
s->context_model],
761 sizeof(
s->quant_table));
763 for (
i = 0;
i <
s->plane_count;
i++) {
774 #if FF_API_CODED_FRAME
780 if (!
s->transparency)
782 if (!
s->chroma_planes &&
s->version > 3)
789 s->picture_number = 0;
792 for (
i = 0;
i <
s->quant_table_count;
i++) {
794 sizeof(*
s->rc_stat2[
i]));
810 for (j = 0; j < 256; j++)
811 for (
i = 0;
i < 2;
i++) {
812 s->rc_stat[j][
i] = strtol(p, &next, 0);
815 "2Pass file invalid at %d %d [%s]\n", j,
i, p);
821 for (
i = 0;
i <
s->quant_table_count;
i++)
822 for (j = 0; j <
s->context_count[
i]; j++) {
823 for (k = 0; k < 32; k++)
824 for (m = 0; m < 2; m++) {
825 s->rc_stat2[
i][j][k][m] = strtol(p, &next, 0);
828 "2Pass file invalid at %d %d %d %d [%s]\n",
836 gob_count = strtol(p, &next, 0);
837 if (next == p || gob_count <= 0) {
843 while (*p ==
'\n' || *p ==
' ')
853 for (
i = 0;
i <
s->quant_table_count;
i++) {
854 for (k = 0; k < 32; k++) {
857 for (j = 0; j <
s->context_count[
i]; j++) {
859 if (
s->rc_stat2[
i][j][k][0] +
s->rc_stat2[
i][j][k][1] > 200 && j ||
a+
b > 200) {
861 p = 256.0 *
b / (
a +
b);
862 s->initial_states[
i][jp][k] =
864 for(jp++; jp<j; jp++)
865 s->initial_states[
i][jp][k] =
s->initial_states[
i][jp-1][k];
868 a +=
s->rc_stat2[
i][j][k][0];
869 b +=
s->rc_stat2[
i][j][k][1];
871 p = 256.0 *
b / (
a +
b);
873 s->initial_states[
i][j][k] =
881 if (
s->version > 1) {
882 int plane_count = 1 + 2*
s->chroma_planes +
s->transparency;
885 s->num_v_slices = (avctx->
width > 352 || avctx->
height > 288 || !avctx->
slices) ? 2 : 1;
887 s->num_v_slices =
FFMIN(
s->num_v_slices, max_v_slices);
889 for (;
s->num_v_slices < 32;
s->num_v_slices++) {
890 for (
s->num_h_slices =
s->num_v_slices;
s->num_h_slices < 2*
s->num_v_slices;
s->num_h_slices++) {
891 int maxw = (avctx->
width +
s->num_h_slices - 1) /
s->num_h_slices;
892 int maxh = (avctx->
height +
s->num_v_slices - 1) /
s->num_v_slices;
893 if (
s->num_h_slices > max_h_slices ||
s->num_v_slices > max_v_slices)
895 if (maxw * maxh * (
int64_t)(
s->bits_per_raw_sample+1) * plane_count > 8<<24)
906 "Unsupported number %d of slices requested, please specify a "
907 "supported number with -slices (ex:4,6,9,12,16, ...)\n",
917 s->slice_count =
s->max_slice_count;
921 #define STATS_OUT_SIZE 1024 * 1024 * 6
926 for (
i = 0;
i <
s->quant_table_count;
i++)
927 for (j = 0; j <
s->max_slice_count; j++) {
951 for (j=0; j<
f->plane_count; j++) {
953 av_assert0(
f->plane[j].quant_table_index ==
f->context_model);
955 if (!
f->picture.f->interlaced_frame)
961 if (
f->version > 3) {
963 if (
fs->slice_coding_mode == 1)
966 if (
fs->slice_coding_mode != 1) {
975 #define NB_Y_COEFF 15
976 static const int rct_y_coeff[15][2] = {
996 int x, y,
i, p, best;
998 int lbd =
fs->bits_per_raw_sample <= 8;
999 int packed = !
src[1];
1000 int transparency =
fs->transparency;
1001 int packed_size = (3 + transparency)*2;
1003 for (y = 0; y <
h; y++) {
1004 int lastr=0, lastg=0, lastb=0;
1005 for (p = 0; p < 3; p++)
1008 for (x = 0; x <
w; x++) {
1012 unsigned v = *((
const uint32_t*)(
src[0] + x*4 +
stride[0]*y));
1014 g = (v >> 8) & 0xFF;
1015 r = (v >> 16) & 0xFF;
1016 }
else if (packed) {
1017 const uint16_t *p = ((
const uint16_t*)(
src[0] + x*packed_size +
stride[0]*y));
1022 b = *((
const uint16_t*)(
src[0] + x*2 +
stride[0]*y));
1023 g = *((
const uint16_t*)(
src[1] + x*2 +
stride[1]*y));
1024 r = *((
const uint16_t*)(
src[2] + x*2 +
stride[2]*y));
1031 int bg = ag -
sample[0][x];
1032 int bb = ab -
sample[1][x];
1033 int br = ar -
sample[2][x];
1039 stat[
i] +=
FFABS(bg + ((br*rct_y_coeff[
i][0] + bb*rct_y_coeff[
i][1])>>2));
1055 if (stat[
i] < stat[best])
1059 fs->slice_rct_by_coef = rct_y_coeff[best][1];
1060 fs->slice_rct_ry_coef = rct_y_coeff[best][0];
1069 int x =
fs->slice_x;
1070 int y =
fs->slice_y;
1071 const AVFrame *
const p =
f->picture.f;
1080 fs->slice_coding_mode = 0;
1081 if (
f->version > 3) {
1084 fs->slice_rct_by_coef = 1;
1085 fs->slice_rct_ry_coef = 1;
1091 if (
f->version > 2) {
1097 fs->c.bytestream_start +
fs->ac_byte_count,
1098 fs->c.bytestream_end -
fs->c.bytestream_start -
fs->ac_byte_count);
1104 const int cx = x >>
f->chroma_h_shift;
1105 const int cy = y >>
f->chroma_v_shift;
1109 if (
f->chroma_planes) {
1113 if (
fs->transparency)
1118 }
else if (
f->use32bit) {
1127 if (
fs->version < 4 || !
fs->ac) {
1132 fs->slice_coding_mode = 1;
1141 const AVFrame *pict,
int *got_packet)
1158 memset(
f->rc_stat, 0,
sizeof(
f->rc_stat));
1159 for (
i = 0;
i <
f->quant_table_count;
i++)
1160 memset(
f->rc_stat2[
i], 0,
f->context_count[
i] *
sizeof(*
f->rc_stat2[
i]));
1163 for (j = 0; j <
f->slice_count; j++) {
1165 for (
i = 0;
i < 256;
i++) {
1166 f->rc_stat[
i][0] +=
fs->rc_stat[
i][0];
1167 f->rc_stat[
i][1] +=
fs->rc_stat[
i][1];
1169 for (
i = 0;
i <
f->quant_table_count;
i++) {
1170 for (k = 0; k <
f->context_count[
i]; k++)
1171 for (m = 0; m < 32; m++) {
1172 f->rc_stat2[
i][k][m][0] +=
fs->rc_stat2[
i][k][m][0];
1173 f->rc_stat2[
i][k][m][1] +=
fs->rc_stat2[
i][k][m][1];
1178 for (j = 0; j < 256; j++) {
1179 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1180 f->rc_stat[j][0],
f->rc_stat[j][1]);
1185 for (
i = 0;
i <
f->quant_table_count;
i++) {
1186 for (j = 0; j <
f->context_count[
i]; j++)
1187 for (m = 0; m < 32; m++) {
1188 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1189 f->rc_stat2[
i][j][m][0],
f->rc_stat2[
i][j][m][1]);
1193 snprintf(p, end - p,
"%d\n",
f->gob_count);
1202 av_log(avctx,
AV_LOG_WARNING,
"Cannot allocate worst case packet size, the encoding could fail\n");
1215 #if FF_API_CODED_FRAME
1233 for (
i = 1;
i < 256;
i++) {
1234 c->one_state[
i] =
f->state_transition[
i];
1235 c->zero_state[256 -
i] = 256 -
c->one_state[
i];
1239 for (
i = 0;
i <
f->slice_count;
i++) {
1248 fs->c.bytestream_end =
fs->c.bytestream_start +
len;
1252 f->slice_count,
sizeof(
void *));
1255 for (
i = 0;
i <
f->slice_count;
i++) {
1265 if (
i > 0 ||
f->version > 2) {
1267 memmove(buf_p,
fs->c.bytestream_start, bytes);
1269 AV_WB24(buf_p + bytes, bytes);
1285 #if FF_API_CODED_FRAME
1291 f->picture_number++;
1307 #define OFFSET(x) offsetof(FFV1Context, x)
1308 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1312 { .i64 = 0 }, -2, 2,
VE,
"coder" },
1319 {
"ac",
"Range with custom table (the ac option exists for compatibility and is deprecated)", 0,
AV_OPT_TYPE_CONST,
1320 { .i64 = 1 }, INT_MIN, INT_MAX,
VE,
"coder" },
1322 { .i64 = 0 }, 0, 1,
VE },
1334 #if FF_API_CODER_TYPE
1374 #if FF_API_CODER_TYPE
static int ring_size(RingBuffer *ring)
Macro definitions for various function/variable attributes.
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 FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static av_cold int init(AVCodecContext *avctx)
#define fs(width, name, subs,...)
#define FFSWAP(type, a, b)
#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.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
av_cold int ff_ffv1_close(AVCodecContext *avctx)
av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
int ff_need_new_slices(int width, int num_h_slices, int chroma_shift)
int ff_ffv1_allocate_initial_states(FFV1Context *f)
av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
void ff_ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs)
FF Video Codec 1 (a lossless codec)
static void update_vlc_state(VlcState *const state, const int v)
#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_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 const AVOption options[]
static void choose_rct_params(FFV1Context *fs, const uint8_t *src[3], const int stride[3], int w, int h)
static void put_vlc_symbol(PutBitContext *pb, VlcState *const state, int v, int bits)
static void write_header(FFV1Context *f)
static av_cold int encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static const int8_t quant9_10bit[256]
static const int8_t quant5[256]
static void encode_slice_header(FFV1Context *f, FFV1Context *fs)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static const int8_t quant5_10bit[256]
static int sort_stt(FFV1Context *s, uint8_t stt[256])
static void write_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
static const AVClass ffv1_class
static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride)
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 int write_extradata(FFV1Context *f)
static const int8_t quant11[256]
static const AVCodecDefault ffv1_defaults[]
static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256])
static const uint8_t ver2_state[256]
static int RENAME() encode_rgb_frame(FFV1Context *s, const uint8_t *src[4], int w, int h, const int stride[4])
static av_always_inline int RENAME() encode_line(FFV1Context *s, int w, TYPE *const sample[3], int plane_index, int bits)
static void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len)
write signed golomb rice code (ffv1).
#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_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_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#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.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
static const int16_t quant_table[64]
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
static av_always_inline av_const double round(double x)
static const struct @323 planes[]
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 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_0RGB32
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#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_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ 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_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 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_YA8
8 bits gray, 8 bits alpha
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#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_YUV444P16
#define AV_PIX_FMT_YUV444P10
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
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 const float pred[4]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
attribute_deprecated int coder_type
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...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
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_*.
attribute_deprecated int context_model
int slices
Number of slices.
const char * name
Name of the codec implementation.
int step
Number of elements between 2 horizontally consecutive pixels.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
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.
uint64_t(*[MAX_QUANT_TABLES] rc_stat2)[32][2]
int16_t quant_table[MAX_CONTEXT_INPUTS][256]
#define av_malloc_array(a, b)
static void print(AVTreeNode *t, int depth)