47 #define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) * 128 + (level))
64 int block_last_index,
uint8_t scantable[64])
70 for (j = 1; j <= block_last_index; j++) {
71 const int index = scantable[j];
75 if ((level & (~127)) == 0) {
76 if (j < block_last_index)
99 const int dir[6],
uint8_t *st[6],
100 const int zigzag_last_index[6])
105 for (n = 0; n < 6; n++) {
111 for (i = 1; i < 8; i++)
115 for (i = 1; i < 8; i++)
130 const int dir[6],
uint8_t *st[6],
131 int zigzag_last_index[6])
139 for (n = 0; n < 6; n++) {
140 int16_t *ac_val, *ac_val1;
151 if (s->
mb_y == 0 || s->
qscale == qscale_table[xy] || n == 2 || n == 3) {
153 for (i = 1; i < 8; i++) {
157 ac_val1[i + 8] =
level;
161 for (i = 1; i < 8; i++) {
165 ac_val1[i + 8] =
level;
173 if (s->
mb_x == 0 || s->
qscale == qscale_table[xy] || n == 1 || n == 3) {
175 for (i = 1; i < 8; i++) {
183 for (i = 1; i < 8; i++) {
193 for (i = 63; i > 0; i--)
194 if (block[n][st[n][i]])
224 for (i = 0; i < s->
mb_num; i++) {
226 odd += qscale_table[mb_xy] & 1;
234 for (i = 0; i < s->
mb_num; i++) {
236 if ((qscale_table[mb_xy] & 1) != odd)
237 qscale_table[mb_xy]++;
238 if (qscale_table[mb_xy] > 31)
239 qscale_table[mb_xy] = 31;
242 for (i = 1; i < s->
mb_num; i++) {
244 if (qscale_table[mb_xy] != qscale_table[s->
mb_index2xy[i - 1]] &&
289 level = (-
level) ^ ((1 << size) - 1);
310 int16_t *
block,
int n,
int intra_dc,
314 int i, last_non_zero;
336 last_non_zero = i - 1;
337 for (; i < last_index; i++) {
338 int level = block[scan_table[i]];
340 int run = i - last_non_zero - 1;
342 if ((level & (~127)) == 0) {
344 put_bits(ac_pb, len_tab[index], bits_tab[index]);
347 7 + 2 + 1 + 6 + 1 + 12 + 1,
348 (3 << 23) + (3 << 21) + (0 << 20) + (run << 14) +
349 (1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
355 int level = block[scan_table[i]];
356 int run = i - last_non_zero - 1;
358 if ((level & (~127)) == 0) {
360 put_bits(ac_pb, len_tab[index], bits_tab[index]);
363 7 + 2 + 1 + 6 + 1 + 12 + 1,
364 (3 << 23) + (3 << 21) + (1 << 20) + (run << 14) +
365 (1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
372 int intra_dc,
uint8_t *scan_table)
374 int i, last_non_zero;
394 last_non_zero = i - 1;
395 for (; i < last_index; i++) {
396 int level = block[scan_table[i]];
398 int run = i - last_non_zero - 1;
400 if ((level & (~127)) == 0) {
402 len += len_tab[
index];
404 len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
410 int level = block[scan_table[i]];
411 int run = i - last_non_zero - 1;
413 if ((level & (~127)) == 0) {
415 len += len_tab[
index];
417 len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
425 int intra_dc[6],
uint8_t **scan_table,
433 for (i = 0; i < 6; i++)
436 intra_dc[i], scan_table[i]));
439 for (i = 0; i < 6; i++)
441 intra_dc[i], scan_table[i], dc_pb, ac_pb);
445 for (i = 0; i < 6; i++)
451 for (i = 0; i < 6; i++)
459 int motion_x,
int motion_y,
int mb_type)
467 for (i = 0; i < 6; i++) {
476 if ((motion_x | motion_y | s->
dquant | mb_type) == 0)
479 zero_score *= lambda;
480 if (zero_score <= score)
484 for (i = 0; i < 6; i++) {
491 for (i = 0; i < 6; i++) {
503 int motion_x,
int motion_y)
505 int cbpc, cbpy, pred_x, pred_y;
516 static const int mb_type_table[8] = { -1, 3, 2, 1, -1, -1, -1, 0 };
517 int mb_type = mb_type_table[s->
mv_dir];
520 for (i = 0; i < 2; i++)
545 cbp =
get_b_cbp(s, block, motion_x, motion_y, mb_type);
547 if ((cbp | motion_x | motion_y | mb_type) == 0) {
553 if (interleaved_stats) {
567 if (cbp && mb_type) {
582 if (interleaved_stats)
625 for (i = 0; i < 2; i++) {
628 s->
mv[0][i][1] - s->
last_mv[0][i][1] / 2,
631 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
636 for (i = 0; i < 2; i++) {
639 s->
mv[1][i][1] - s->
last_mv[1][i][1] / 2,
642 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
649 if (interleaved_stats)
654 if (interleaved_stats)
657 cbp =
get_p_cbp(s, block, motion_x, motion_y);
659 if ((cbp | motion_x | motion_y | s->
dquant) == 0 &&
693 for (y1 = 0; y1 < ye; y1++) {
694 for (x1 = 0; x1 < xe; x1++) {
698 diff = diff * 256 / (xe * ye);
702 if (diff > s->
qscale * 70) {
714 if (interleaved_stats) {
745 if (interleaved_stats)
771 if (interleaved_stats)
782 s->
mv[0][0][0] - pred_x,
783 s->
mv[0][0][1] - pred_y,
786 s->
mv[0][1][0] - pred_x,
787 s->
mv[0][1][1] - pred_y,
799 if (interleaved_stats)
802 for (i = 0; i < 4; i++) {
813 if (interleaved_stats)
818 if (interleaved_stats)
827 int zigzag_last_index[6];
831 for (i = 0; i < 6; i++)
837 for (i = 0; i < 6; i++)
843 for (i = 0; i < 6; i++)
871 if (interleaved_stats)
876 if (interleaved_stats)
896 put_bits(pbc, length, (1 << length) - 1);
912 int hours, minutes, seconds;
925 minutes =
FFUDIV(seconds, 60); seconds =
FFUMOD(seconds, 60);
926 hours =
FFUDIV(minutes, 60); minutes =
FFUMOD(minutes, 60);
927 hours =
FFUMOD(hours , 24);
942 int profile_and_level_indication;
948 profile_and_level_indication = 0xF0;
950 profile_and_level_indication = 0x00;
954 profile_and_level_indication |= s->
avctx->
level;
956 profile_and_level_indication |= 1;
958 if (profile_and_level_indication >> 4 == 0xF)
968 put_bits(&s->
pb, 8, profile_and_level_indication);
990 if (!CONFIG_MPEG4_ENCODER)
1071 if (vo_ver_id != 1) {
1091 int time_div, time_mod;
1143 int level, uni_code, uni_len;
1145 for (level = -256; level < 256; level++) {
1156 l = (-
level) ^ ((1 << size) - 1);
1199 int slevel,
run, last;
1204 for (slevel = -64; slevel < 64; slevel++) {
1207 for (run = 0; run < 64; run++) {
1208 for (last = 0; last <= 1; last++) {
1210 int level = slevel < 0 ? -slevel : slevel;
1211 int sign = slevel < 0 ? 1 : 0;
1215 len_tab[
index] = 100;
1221 bits = bits * 2 + sign;
1224 if (code != rl->
n && len < len_tab[index]) {
1239 bits = bits * 2 + sign;
1242 if (code != rl->
n && len < len_tab[index]) {
1250 bits = bits * 4 + 2;
1258 bits = bits * 2 + sign;
1261 if (code != rl->
n && len < len_tab[index]) {
1269 bits = bits * 4 + 3;
1271 bits = bits * 2 + last;
1273 bits = bits * 64 +
run;
1275 bits = bits * 2 + 1;
1277 bits = bits * 4096 + (slevel & 0xfff);
1279 bits = bits * 2 + 1;
1282 if (len < len_tab[index]) {
1295 static int done = 0;
1297 if (avctx->
width >= (1<<13) || avctx->
height >= (1<<13)) {
1347 int pb_size = (((intptr_t)start + size / 3) & (~3)) - (intptr_t)start;
1348 int tex_size = (size - 2 * pb_size) & (~3);
1393 #define OFFSET(x) offsetof(MpegEncContext, x)
1394 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1396 {
"data_partitioning",
"Use data partitioning.",
OFFSET(data_partitioning),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1397 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },