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 };
158 for (k = 0; k < 256; k++) {
159 double newocc[256] = { 0 };
160 for (m = 1; m < 256; m++)
162 len -=occ[
m]*( p *l2tab[
m]
163 + (1-p)*l2tab[256-m]);
165 if (len < best_len[k]) {
167 best_state[i][k] = j;
169 for (m = 1; m < 256; m++)
171 newocc[ one_state[
m]] += occ[
m] * p;
172 newocc[256 - one_state[256 -
m]] += occ[
m] * (1 - p);
174 memcpy(occ, newocc,
sizeof(occ));
188 #define put_rac(C, S, B) \
191 rc_stat[*(S)][B]++; \
192 rc_stat2[(S) - state][B]++; \
202 for (i = 0; i < e; i++)
206 for (i = e - 1; i >= 0; i--)
207 put_rac(c, state + 22 + i, (a >> i) & 1);
210 put_rac(c, state + 11 + e, v < 0);
212 for (i = 0; i < e; i++)
216 for (i = e - 1; i >= 0; i--)
220 put_rac(c, state + 11 + 10, v < 0);
229 int v,
int is_signed)
243 while (i < state->error_sum) {
251 if (k == 0 && 2 * state->
drift <= -state->
count)
256 code = v ^ ((2 * state->
drift + state->
count) >> 31);
259 av_dlog(
NULL,
"v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v, code,
268 int plane_index,
int bits)
290 for (x = 0; x < w; x++) {
292 int v = sample[0][x];
293 for (i = bits-1; i>=0; i--) {
295 put_rac(c, &state, (v>>i) & 1);
301 for (x = 0; x < w; x++) {
304 context =
get_context(p, sample[0] + x, sample[1] + x, sample[2] + x);
305 diff = sample[0][x] -
predict(sample[0] + x, sample[1] + x);
312 diff =
fold(diff, bits);
345 av_dlog(s->
avctx,
"count:%d index:%d, mode:%d, x:%d pos:%d\n",
346 run_count, run_index, run_mode, x,
369 int stride,
int plane_index)
378 for (y = 0; y < h; y++) {
379 for (i = 0; i < ring_size; i++)
380 sample[i] = s->
sample_buffer + (w + 6) * ((h + i -
y) % ring_size) + 3;
382 sample[0][-1]= sample[1][0 ];
383 sample[1][ w]= sample[1][w-1];
386 for (x = 0; x < w; x++)
387 sample[0][x] = src[x + stride * y];
388 if((ret =
encode_line(s, w, sample, plane_index, 8)) < 0)
392 for (x = 0; x < w; x++) {
393 sample[0][x] = ((uint16_t*)(src + stride*y))[x];
396 for (x = 0; x < w; x++) {
409 int w,
int h,
const int stride[3])
423 for (y = 0; y < h; y++) {
424 for (i = 0; i < ring_size; i++)
426 sample[p][i]= s->
sample_buffer + p*ring_size*(w+6) + ((h+i-
y)%ring_size)*(w+6) + 3;
428 for (x = 0; x < w; x++) {
431 unsigned v = *((
const uint32_t*)(src[0] + x*4 + stride[0]*y));
434 r = (v >> 16) & 0xFF;
437 b = *((
const uint16_t *)(src[0] + x*2 + stride[0]*y));
438 g = *((
const uint16_t *)(src[1] + x*2 + stride[1]*y));
439 r = *((
const uint16_t *)(src[2] + x*2 + stride[2]*y));
457 sample[p][0][-1] = sample[p][1][0 ];
458 sample[p][1][ w] = sample[p][1][w-1];
460 ret =
encode_line(s, w, sample[p], (p + 1) / 2, 9);
475 memset(state, 128,
sizeof(state));
477 for (i = 1; i < 128; i++)
478 if (quant_table[i] != quant_table[i - 1]) {
489 for (i = 0; i < 5; i++)
499 memset(state, 128,
sizeof(state));
505 for (i = 1; i < 256; i++)
548 memset(state2, 128,
sizeof(state2));
549 memset(state, 128,
sizeof(state));
552 (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;
570 for (i = 1; i < 256; i++)
618 int i, i2, changed, print = 0;
622 for (i = 12; i < 244; i++) {
623 for (i2 = i + 1; i2 < 245 && i2 < i + 4; i2++) {
625 #define COST(old, new) \
626 s->rc_stat[old][0] * -log2((256 - (new)) / 256.0) + \
627 s->rc_stat[old][1] * -log2((new) / 256.0)
629 #define COST2(old, new) \
630 COST(old, new) + COST(256 - (old), 256 - (new))
634 if (size0 - sizeX > size0*(1e-14) && i != 128 && i2 != 128) {
636 FFSWAP(
int, stt[i], stt[i2]);
640 FFSWAP(
int, stt[256 - i], stt[256 - i2]);
644 for (j = 1; j < 256; j++) {
647 else if (stt[j] == i2)
650 if (stt[256 - j] == 256 - i)
651 stt[256 - j] = 256 - i2;
652 else if (stt[256 - j] == 256 - i2)
653 stt[256 - j] = 256 - i;
693 av_log(avctx,
AV_LOG_ERROR,
"Version 2 needed for requested features but version 2 is experimental and not enabled\n");
739 av_log(avctx,
AV_LOG_ERROR,
"bits_per_raw_sample of more than 8 needs -coder 1 currently\n");
784 av_log(avctx,
AV_LOG_ERROR,
"bits_per_raw_sample of more than 8 needs -coder 1 currently\n");
793 av_log(avctx,
AV_LOG_WARNING,
"Storing alpha plane, this will require a recent FFV1 decoder to playback!\n");
801 for (i = 1; i < 256; i++)
804 for (i = 0; i < 256; i++) {
875 for (j = 0; j < 256; j++)
876 for (i = 0; i < 2; i++) {
877 s->
rc_stat[j][i] = strtol(p, &next, 0);
880 "2Pass file invalid at %d %d [%s]\n", j, i, p);
888 for (k = 0; k < 32; k++)
889 for (m = 0; m < 2; m++) {
890 s->
rc_stat2[i][j][k][
m] = strtol(p, &next, 0);
893 "2Pass file invalid at %d %d %d %d [%s]\n",
901 gob_count = strtol(p, &next, 0);
902 if (next == p || gob_count <= 0) {
908 while (*p ==
'\n' || *p ==
' ')
918 for (k = 0; k < 32; k++) {
925 p = 256.0 *
b / (a +
b);
927 best_state[av_clip(
round(p), 1, 255)][av_clip_uint8((a +
b) / gob_count)];
928 for(jp++; jp<j; jp++)
935 p = 256.0 *
b / (a +
b);
938 best_state[av_clip(
round(p), 1, 255)][av_clip_uint8((a +
b) / gob_count)];
954 "Unsupported number %d of slices requested, please specify a "
955 "supported number with -slices (ex:4,6,9,12,16, ...)\n",
968 #define STATS_OUT_SIZE 1024 * 1024 * 6
992 memset(state, 128,
sizeof(state));
1022 #define NB_Y_COEFF 15
1023 static const int rct_y_coeff[15][2] = {
1043 int x,
y, i, p, best;
1047 for (y = 0; y < h; y++) {
1048 int lastr=0, lastg=0, lastb=0;
1049 for (p = 0; p < 3; p++)
1052 for (x = 0; x < w; x++) {
1056 unsigned v = *((
const uint32_t*)(src[0] + x*4 + stride[0]*y));
1058 g = (v >> 8) & 0xFF;
1059 r = (v >> 16) & 0xFF;
1061 b = *((
const uint16_t*)(src[0] + x*2 + stride[0]*y));
1062 g = *((
const uint16_t*)(src[1] + x*2 + stride[1]*y));
1063 r = *((
const uint16_t*)(src[2] + x*2 + stride[2]*y));
1070 int bg = ag - sample[0][x];
1071 int bb = ab - sample[1][x];
1072 int br = ar - sample[2][x];
1078 stat[i] +=
FFABS(bg + ((br*rct_y_coeff[i][0] + bb*rct_y_coeff[i][1])>>2));
1094 if (stat[i] < stat[best])
1141 if (f->colorspace == 0) {
1144 const int cx = x >> f->chroma_h_shift;
1145 const int cy =
y >> f->chroma_v_shift;
1149 if (f->chroma_planes) {
1150 ret |=
encode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
1151 ret |=
encode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);
1153 if (fs->transparency)
1162 if (fs->version < 4 || !fs->ac) {
1167 fs->slice_coding_mode = 1;
1176 const AVFrame *pict,
int *got_packet)
1200 for (i = 0; i < 256; i++) {
1206 for (m = 0; m < 32; m++) {
1213 for (j = 0; j < 256; j++) {
1214 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1222 for (m = 0; m < 32; m++) {
1223 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1259 for (i = 1; i < 256; i++) {
1287 if (i > 0 || f->
version > 2) {
1291 AV_WB24(buf_p + bytes, bytes);
1324 #define OFFSET(x) offsetof(FFV1Context, x)
1325 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM