48 #define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) * 128 + (level))
65 int block_last_index,
uint8_t scantable[64])
71 for (j = 1; j <= block_last_index; j++) {
72 const int index = scantable[j];
76 if ((level & (~127)) == 0) {
77 if (j < block_last_index)
100 const int dir[6],
uint8_t *st[6],
101 const int zigzag_last_index[6])
106 for (n = 0; n < 6; n++) {
112 for (i = 1; i < 8; i++)
116 for (i = 1; i < 8; i++)
131 const int dir[6],
uint8_t *st[6],
132 int zigzag_last_index[6])
140 for (n = 0; n < 6; n++) {
141 int16_t *ac_val, *ac_val1;
152 if (s->
mb_y == 0 || s->
qscale == qscale_table[xy] || n == 2 || n == 3) {
154 for (i = 1; i < 8; i++) {
158 ac_val1[i + 8] =
level;
162 for (i = 1; i < 8; i++) {
166 ac_val1[i + 8] =
level;
174 if (s->
mb_x == 0 || s->
qscale == qscale_table[xy] || n == 1 || n == 3) {
176 for (i = 1; i < 8; i++) {
184 for (i = 1; i < 8; i++) {
194 for (i = 63; i > 0; i--)
195 if (block[n][st[n][i]])
225 for (i = 0; i < s->
mb_num; i++) {
227 odd += qscale_table[mb_xy] & 1;
235 for (i = 0; i < s->
mb_num; i++) {
237 if ((qscale_table[mb_xy] & 1) != odd)
238 qscale_table[mb_xy]++;
239 if (qscale_table[mb_xy] > 31)
240 qscale_table[mb_xy] = 31;
243 for (i = 1; i < s->
mb_num; i++) {
245 if (qscale_table[mb_xy] != qscale_table[s->
mb_index2xy[i - 1]] &&
290 level = (-
level) ^ ((1 << size) - 1);
311 int16_t *
block,
int n,
int intra_dc,
315 int i, last_non_zero;
337 last_non_zero = i - 1;
338 for (; i < last_index; i++) {
339 int level = block[scan_table[i]];
341 int run = i - last_non_zero - 1;
343 if ((level & (~127)) == 0) {
345 put_bits(ac_pb, len_tab[index], bits_tab[index]);
348 7 + 2 + 1 + 6 + 1 + 12 + 1,
349 (3 << 23) + (3 << 21) + (0 << 20) + (run << 14) +
350 (1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
356 int level = block[scan_table[i]];
357 int run = i - last_non_zero - 1;
359 if ((level & (~127)) == 0) {
361 put_bits(ac_pb, len_tab[index], bits_tab[index]);
364 7 + 2 + 1 + 6 + 1 + 12 + 1,
365 (3 << 23) + (3 << 21) + (1 << 20) + (run << 14) +
366 (1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
373 int intra_dc,
uint8_t *scan_table)
375 int i, last_non_zero;
395 last_non_zero = i - 1;
396 for (; i < last_index; i++) {
397 int level = block[scan_table[i]];
399 int run = i - last_non_zero - 1;
401 if ((level & (~127)) == 0) {
403 len += len_tab[
index];
405 len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
411 int level = block[scan_table[i]];
412 int run = i - last_non_zero - 1;
414 if ((level & (~127)) == 0) {
416 len += len_tab[
index];
418 len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
426 int intra_dc[6],
uint8_t **scan_table,
434 for (i = 0; i < 6; i++)
437 intra_dc[i], scan_table[i]));
440 for (i = 0; i < 6; i++)
442 intra_dc[i], scan_table[i], dc_pb, ac_pb);
446 for (i = 0; i < 6; i++)
452 for (i = 0; i < 6; i++)
460 int motion_x,
int motion_y,
int mb_type)
468 for (i = 0; i < 6; i++) {
477 if ((motion_x | motion_y | s->
dquant | mb_type) == 0)
480 zero_score *= lambda;
481 if (zero_score <= score)
485 for (i = 0; i < 6; i++) {
492 for (i = 0; i < 6; i++) {
504 int motion_x,
int motion_y)
506 int cbpc, cbpy, pred_x, pred_y;
517 static const int mb_type_table[8] = { -1, 3, 2, 1, -1, -1, -1, 0 };
518 int mb_type = mb_type_table[s->
mv_dir];
521 for (i = 0; i < 2; i++)
546 cbp =
get_b_cbp(s, block, motion_x, motion_y, mb_type);
548 if ((cbp | motion_x | motion_y | mb_type) == 0) {
554 if (interleaved_stats) {
568 if (cbp && mb_type) {
583 if (interleaved_stats)
626 for (i = 0; i < 2; i++) {
629 s->
mv[0][i][1] - s->
last_mv[0][i][1] / 2,
632 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
637 for (i = 0; i < 2; i++) {
640 s->
mv[1][i][1] - s->
last_mv[1][i][1] / 2,
643 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
650 if (interleaved_stats)
655 if (interleaved_stats)
658 cbp =
get_p_cbp(s, block, motion_x, motion_y);
660 if ((cbp | motion_x | motion_y | s->
dquant) == 0 &&
694 for (y1 = 0; y1 < ye; y1++) {
695 for (x1 = 0; x1 < xe; x1++) {
699 diff = diff * 256 / (xe * ye);
703 if (diff > s->
qscale * 70) {
715 if (interleaved_stats) {
746 if (interleaved_stats)
772 if (interleaved_stats)
783 s->
mv[0][0][0] - pred_x,
784 s->
mv[0][0][1] - pred_y,
787 s->
mv[0][1][0] - pred_x,
788 s->
mv[0][1][1] - pred_y,
800 if (interleaved_stats)
803 for (i = 0; i < 4; i++) {
814 if (interleaved_stats)
819 if (interleaved_stats)
828 int zigzag_last_index[6];
832 for (i = 0; i < 6; i++)
838 for (i = 0; i < 6; i++)
844 for (i = 0; i < 6; i++)
872 if (interleaved_stats)
877 if (interleaved_stats)
897 put_bits(pbc, length, (1 << length) - 1);
913 int hours, minutes, seconds;
926 minutes =
FFUDIV(seconds, 60); seconds =
FFUMOD(seconds, 60);
927 hours =
FFUDIV(minutes, 60); minutes =
FFUMOD(minutes, 60);
928 hours =
FFUMOD(hours , 24);
943 int profile_and_level_indication;
949 profile_and_level_indication = 0xF0;
951 profile_and_level_indication = 0x00;
955 profile_and_level_indication |= s->
avctx->
level;
957 profile_and_level_indication |= 1;
959 if (profile_and_level_indication >> 4 == 0xF)
969 put_bits(&s->
pb, 8, profile_and_level_indication);
991 if (!CONFIG_MPEG4_ENCODER)
1072 if (vo_ver_id != 1) {
1092 int time_div, time_mod;
1144 int level, uni_code, uni_len;
1146 for (level = -256; level < 256; level++) {
1157 l = (-
level) ^ ((1 << size) - 1);
1200 int slevel,
run, last;
1205 for (slevel = -64; slevel < 64; slevel++) {
1208 for (run = 0; run < 64; run++) {
1209 for (last = 0; last <= 1; last++) {
1211 int level = slevel < 0 ? -slevel : slevel;
1212 int sign = slevel < 0 ? 1 : 0;
1216 len_tab[
index] = 100;
1222 bits = bits * 2 + sign;
1225 if (code != rl->
n && len < len_tab[index]) {
1240 bits = bits * 2 + sign;
1243 if (code != rl->
n && len < len_tab[index]) {
1251 bits = bits * 4 + 2;
1259 bits = bits * 2 + sign;
1262 if (code != rl->
n && len < len_tab[index]) {
1270 bits = bits * 4 + 3;
1272 bits = bits * 2 + last;
1274 bits = bits * 64 +
run;
1276 bits = bits * 2 + 1;
1278 bits = bits * 4096 + (slevel & 0xfff);
1280 bits = bits * 2 + 1;
1283 if (len < len_tab[index]) {
1296 static int done = 0;
1298 if (avctx->
width >= (1<<13) || avctx->
height >= (1<<13)) {
1348 int pb_size = (((intptr_t)start + size / 3) & (~3)) - (intptr_t)start;
1349 int tex_size = (size - 2 * pb_size) & (~3);
1394 #define OFFSET(x) offsetof(MpegEncContext, x)
1395 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1397 {
"data_partitioning",
"Use data partitioning.",
OFFSET(data_partitioning),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1398 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },