72 uint16_t (*qmat16)[2][64],
73 const uint16_t *quant_matrix,
74 int bias,
int qmin,
int qmax,
int intra)
79 for (qscale = qmin; qscale <= qmax; qscale++) {
84 for (i = 0; i < 64; i++) {
93 (qscale * quant_matrix[j]));
96 for (i = 0; i < 64; i++) {
109 for (i = 0; i < 64; i++) {
117 (qscale * quant_matrix[j]));
121 (qscale * quant_matrix[j]);
123 if (qmat16[qscale][0][i] == 0 ||
124 qmat16[qscale][0][i] == 128 * 256)
125 qmat16[
qscale][0][i] = 128 * 256 - 1;
128 qmat16[qscale][0][i]);
132 for (i = intra; i < 64; i++) {
137 while (((max * qmat[qscale][i]) >> shift) > INT_MAX) {
144 "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
165 for (i = 0; i < 64; i++) {
180 for (i = 0; i < s->
mb_num; i++) {
191 #define COPY(a) dst->a= src->a
216 for (i = -16; i < 16; i++) {
239 "only YUV420 and YUV422 are supported\n");
278 "Warning keyframe interval too large! reducing it ...\n");
323 "a vbv buffer size is needed, "
324 "for encoding with a maximum bitrate\n");
330 "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
347 "impossible bitrate constraints, this will fail\n");
361 "bitrate tolerance too small for bitrate\n");
372 "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
373 "specified vbv buffer is too large for the given bitrate!\n");
385 "OBMC is only supported with simple mb decision\n");
408 "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
422 "mpeg2 style quantization not supported by codec\n");
440 "closed gop with scene change detection are not supported yet, "
441 "set threshold to 1000000000\n");
448 "low delay forcing is only available for mpeg2\n");
453 "b frames cannot be used with low delay\n");
459 if (avctx->
qmax > 12) {
461 "non linear quant only supports qmax <= 12 currently\n");
472 "multi threaded encoding not supported by codec\n");
478 "automatic thread number detection not supported by codec,"
491 i = (INT_MAX / 2 + 128) >> 8;
500 "notice: b_frame_strategy only affects the first pass\n");
531 "timebase %d/%d not supported by MPEG 4 standard, "
532 "the maximum admitted value for the timebase denominator "
565 "The specified picture size of %dx%d is not valid for the "
566 "H.261 codec.\nValid sizes are 176x144, 352x288\n",
580 "The specified picture size of %dx%d is not valid for "
581 "the H.263 codec.\nValid sizes are 128x96, 176x144, "
582 "352x288, 704x576, and 1408x1152."
694 (
MAX_RUN + 1) * 2 *
sizeof(
int), fail);
709 2 * 64 *
sizeof(uint16_t), fail);
741 for (i = 0; i < 64; i++) {
775 #if FF_API_ERROR_RATE
843 for (y = 0; y < 16; y++) {
844 for (x = 0; x < 16; x++) {
845 acc +=
FFABS(src[x + y * stride] - ref);
861 for (y = 0; y < h; y += 16) {
862 for (x = 0; x < w; x += 16) {
863 int offset = x + y *
stride;
866 int mean = (s->
dsp.
pix_sum(src + offset, stride) + 128) >> 8;
867 int sae =
get_sae(src + offset, mean, stride);
869 acc += sae + 500 < sad;
880 int i, display_picture_number = 0, ret;
896 "Error, Invalid timestamp=%"PRId64
", "
901 if (!s->
low_delay && display_picture_number == 1)
910 "Warning: AVFrame.pts=? trying to guess (%"PRId64
")\n",
913 pts = display_picture_number;
919 if (!pic_arg->
buf[0]);
961 int h_chroma_shift, v_chroma_shift;
966 for (i = 0; i < 3; i++) {
967 int src_stride = pic_arg->
linesize[i];
969 int h_shift = i ? h_chroma_shift : 0;
970 int v_shift = i ? v_chroma_shift : 0;
971 int w = s->
width >> h_shift;
972 int h = s->
height >> v_shift;
979 if (src_stride == dst_stride)
980 memcpy(dst, src, src_stride * h);
1012 int64_t score64 = 0;
1014 for (plane = 0; plane < 3; plane++) {
1016 const int bw = plane ? 1 : 2;
1017 for (y = 0; y < s->
mb_height * bw; y++) {
1018 for (x = 0; x < s->
mb_width * bw; x++) {
1025 case 0: score =
FFMAX(score, v);
break;
1026 case 1: score +=
FFABS(v);
break;
1027 case 2: score += v * v;
break;
1028 case 3: score64 +=
FFABS(v * v * (int64_t)v);
break;
1029 case 4: score64 += v * v * (int64_t)(v * v);
break;
1048 int ret, got_output;
1065 int i, j, out_size, p_lambda, b_lambda,
lambda2;
1066 int64_t best_rd = INT64_MAX;
1067 int best_b_count = -1;
1069 assert(scale >= 0 && scale <= 3);
1077 b_lambda = p_lambda;
1102 pre_input = *pre_input_ptr;
1104 if (!pre_input.
shared && i) {
1166 return best_b_count;
1239 b_frames =
FFMAX(0, i - 1);
1242 for (i = 0; i < b_frames + 1; i++) {
1254 for (i = b_frames - 1; i >= 0; i--) {
1262 "warning, too many b frames in a row\n");
1285 for (i = 0; i < b_frames; i++) {
1331 for (i = 0; i < 4; i++) {
1394 for (intra = 0; intra < 2; intra++) {
1396 for (i = 0; i < 64; i++) {
1402 for (i = 0; i < 64; i++) {
1453 for (i = 0; i < 4; i++) {
1484 const AVFrame *pic_arg,
int *got_packet)
1487 int i, stuffing_count, ret;
1511 for (i = 0; i < context_count; i++) {
1515 uint8_t *start = pkt->
data + (size_t)(((int64_t) pkt->
size) * start_y / h);
1516 uint8_t *end = pkt->
data + (size_t)(((int64_t) pkt->
size) * end_y / h);
1573 for (i = 0; i < context_count; i++) {
1586 for (i = 0; i < 4; i++) {
1599 if (stuffing_count) {
1601 stuffing_count + 50) {
1609 while (stuffing_count--) {
1616 stuffing_count -= 4;
1617 while (stuffing_count--) {
1634 int vbv_delay, min_delay;
1643 "Internal error, negative bits\n");
1651 vbv_delay =
FFMAX(vbv_delay, min_delay);
1653 assert(vbv_delay < 0xFFFF);
1684 *got_packet = !!pkt->
size;
1689 int n,
int threshold)
1691 static const char tab[64] = {
1692 3, 2, 2, 1, 1, 1, 1, 1,
1693 1, 1, 1, 1, 1, 1, 1, 1,
1694 1, 1, 1, 1, 1, 1, 1, 1,
1695 0, 0, 0, 0, 0, 0, 0, 0,
1696 0, 0, 0, 0, 0, 0, 0, 0,
1697 0, 0, 0, 0, 0, 0, 0, 0,
1698 0, 0, 0, 0, 0, 0, 0, 0,
1699 0, 0, 0, 0, 0, 0, 0, 0
1708 if (threshold < 0) {
1710 threshold = -threshold;
1715 if (last_index <= skip_dc - 1)
1718 for (i = 0; i <= last_index; i++) {
1722 if (skip_dc && i == 0)
1726 }
else if (level > 1) {
1732 if (score >= threshold)
1734 for (i = skip_dc; i <= last_index; i++) {
1757 for (; i <= last_index; i++) {
1759 int level = block[j];
1761 if (level > maxlevel) {
1764 }
else if (level < minlevel) {
1774 "warning, clipping %d dct coefficients to %d..%d\n",
1775 overflow, minlevel, maxlevel);
1782 for (y = 0; y < 8; y++) {
1783 for (x = 0; x < 8; x++) {
1789 for (y2 =
FFMAX(y - 1, 0); y2 <
FFMIN(8, y + 2); y2++) {
1790 for (x2=
FFMAX(x - 1, 0); x2 <
FFMIN(8, x + 2); x2++) {
1791 int v = ptr[x2 + y2 *
stride];
1797 weight[x + 8 * y]= (36 *
ff_sqrt(count * sqr - sum * sum)) / count;
1803 int motion_x,
int motion_y,
1804 int mb_block_height,
1807 int16_t weight[8][64];
1808 int16_t orig[8][64];
1814 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
1815 ptrdiff_t wrap_y, wrap_c;
1817 for (i = 0; i < mb_block_count; i++)
1821 const int last_qp = s->
qscale;
1822 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1853 (mb_y * 16 * wrap_y) + mb_x * 16;
1855 (mb_y * mb_block_height * wrap_c) + mb_x * 8;
1857 (mb_y * mb_block_height * wrap_c) + mb_x * 8;
1859 if (mb_x * 16 + 16 > s->
width || mb_y * 16 + 16 > s->
height) {
1863 16, 16, mb_x * 16, mb_y * 16,
1868 8, mb_block_height, mb_x * 8, mb_y * 8,
1870 ptr_cb = ebuf + 18 * wrap_y;
1873 8, mb_block_height, mb_x * 8, mb_y * 8,
1875 ptr_cr = ebuf + 18 * wrap_y + 8;
1880 int progressive_score, interlaced_score;
1886 NULL, wrap_y, 8) - 400;
1888 if (progressive_score > 0) {
1890 NULL, wrap_y * 2, 8) +
1892 NULL, wrap_y * 2, 8);
1893 if (progressive_score > interlaced_score) {
1896 dct_offset = wrap_y;
1917 ptr_cb + (dct_offset >> 1), wrap_c);
1919 ptr_cr + (dct_offset >> 1), wrap_c);
1925 uint8_t *dest_y, *dest_cb, *dest_cr;
1927 dest_y = s->
dest[0];
1928 dest_cb = s->
dest[1];
1929 dest_cr = s->
dest[2];
1953 int progressive_score, interlaced_score;
1960 ptr_y + wrap_y * 8, wrap_y,
1964 progressive_score -= 400;
1966 if (progressive_score > 0) {
1974 if (progressive_score > interlaced_score) {
1977 dct_offset = wrap_y;
1988 dest_y + dct_offset, wrap_y);
1990 dest_y + dct_offset + 8, wrap_y);
2000 dest_cb + (dct_offset >> 1), wrap_c);
2002 dest_cr + (dct_offset >> 1), wrap_c);
2010 wrap_y, 8) < 20 * s->
qscale)
2013 dest_y + 8, wrap_y, 8) < 20 * s->
qscale)
2016 dest_y + dct_offset, wrap_y, 8) < 20 * s->
qscale)
2018 if (s->
dsp.
sad[1](
NULL, ptr_y + dct_offset + 8,
2019 dest_y + dct_offset + 8,
2020 wrap_y, 8) < 20 * s->
qscale)
2023 wrap_c, 8) < 20 * s->
qscale)
2026 wrap_c, 8) < 20 * s->
qscale)
2029 if (s->
dsp.
sad[1](
NULL, ptr_cb + (dct_offset >> 1),
2030 dest_cb + (dct_offset >> 1),
2031 wrap_c, 8) < 20 * s->
qscale)
2033 if (s->
dsp.
sad[1](
NULL, ptr_cr + (dct_offset >> 1),
2034 dest_cr + (dct_offset >> 1),
2035 wrap_c, 8) < 20 * s->
qscale)
2062 memcpy(orig[0], s->
block[0],
sizeof(int16_t) * 64 * mb_block_count);
2068 for (i = 0; i < mb_block_count; i++) {
2083 for (i = 0; i < mb_block_count; i++) {
2093 for (i = 0; i < 4; i++)
2096 for (i = 4; i < mb_block_count; i++)
2100 for (i = 0; i < mb_block_count; i++) {
2116 for (i = 0; i < mb_block_count; i++) {
2119 for (j = 63; j > 0; j--) {
2207 memcpy(d->
mv, s->
mv, 2*4*2*
sizeof(
int));
2245 int *dmin,
int *next_block,
int motion_x,
int motion_y)
2253 s->
pb= pb[*next_block];
2255 s->
pb2 = pb2 [*next_block];
2256 s->
tex_pb= tex_pb[*next_block];
2260 memcpy(dest_backup, s->
dest,
sizeof(s->
dest));
2283 memcpy(s->
dest, dest_backup,
sizeof(s->
dest));
2301 else if(w==8 && h==8)
2391 for(mb_x=0; mb_x < s->
mb_width; mb_x++) {
2435 bytestream_put_le32(&ptr, offset);
2436 bytestream_put_byte(&ptr, s->
qscale);
2437 bytestream_put_byte(&ptr, gobn);
2438 bytestream_put_le16(&ptr, mba);
2439 bytestream_put_byte(&ptr, pred_x);
2440 bytestream_put_byte(&ptr, pred_y);
2442 bytestream_put_byte(&ptr, 0);
2443 bytestream_put_byte(&ptr, 0);
2534 for(mb_x=0; mb_x < s->
mb_width; mb_x++) {
2565 int current_packet_size, is_gob_start;
2571 if(s->
start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
2580 if(s->
mb_x==0 && s->
mb_y!=0) is_gob_start=1;
2602 current_packet_size=0;
2660 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
2677 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,
2678 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2689 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,
2690 &dmin, &next_block, 0, 0);
2698 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,
2699 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2709 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
2710 &dmin, &next_block, 0, 0);
2718 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,
2719 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2727 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,
2728 &dmin, &next_block, s->
mv[1][0][0], s->
mv[1][0][1]);
2738 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,
2739 &dmin, &next_block, 0, 0);
2750 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,
2751 &dmin, &next_block, 0, 0);
2762 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb,
2763 &dmin, &next_block, 0, 0);
2769 for(dir=0; dir<2; dir++){
2776 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb,
2777 &dmin, &next_block, 0, 0);
2785 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb,
2786 &dmin, &next_block, 0, 0);
2797 const int last_qp= backup_s.
qscale;
2801 static const int dquant_tab[4]={-1,1,-2,2};
2803 assert(backup_s.
dquant == 0);
2809 s->
mv[0][0][0] = best_s.
mv[0][0][0];
2810 s->
mv[0][0][1] = best_s.
mv[0][0][1];
2811 s->
mv[1][0][0] = best_s.
mv[1][0][0];
2812 s->
mv[1][0][1] = best_s.
mv[1][0][1];
2815 for(; qpi<4; qpi++){
2816 int dquant= dquant_tab[qpi];
2828 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,
2829 &dmin, &next_block, s->
mv[mvdir][0][0], s->
mv[mvdir][0][1]);
2849 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2850 &dmin, &next_block, mx, my);
2857 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2858 &dmin, &next_block, 0, 0);
2866 memcpy(s->
mv, best_s.
mv,
sizeof(s->
mv));
2887 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,
2888 &dmin, &next_block, mx, my);
2928 int motion_x = 0, motion_y = 0;
2936 motion_x= s->
mv[0][0][0] = 0;
2937 motion_y= s->
mv[0][0][1] = 0;
3024 for(dir=0; dir<2; dir++){
3098 #define MERGE(field) dst->field += src->field; src->field=0
3125 for(i=0; i<64; i++){
3232 for(i=1; i<context_count; i++){
3262 for(i=1; i<context_count; i++){
3273 av_dlog(s,
"Scene change detected, encoding as I Frame %d %d\n",
3317 for(dir=0; dir<2; dir++){
3398 for(i=1; i<context_count; i++){
3402 for(i=1; i<context_count; i++){
3415 for(i=0; i<64; i++){
3416 int level= block[i];
3422 if(level<0) level=0;
3426 if(level>0) level=0;
3434 int16_t *
block,
int n,
3435 int qscale,
int *overflow){
3440 unsigned int threshold1, threshold2;
3452 int coeff_count[64];
3453 int qmul, qadd, start_i, last_non_zero, i,
dc;
3464 qadd= ((qscale-1)|1)*8;
3481 block[0] = (block[0] + (q >> 1)) / q;
3499 threshold2= (threshold1<<1);
3501 for(i=63; i>=start_i; i--) {
3502 const int j = scantable[i];
3503 int level = block[j] * qmat[j];
3505 if(((
unsigned)(level+threshold1))>threshold2){
3511 for(i=start_i; i<=last_non_zero; i++) {
3512 const int j = scantable[i];
3513 int level = block[j] * qmat[j];
3517 if(((
unsigned)(level+threshold1))>threshold2){
3521 coeff[1][i]= level-1;
3525 coeff[0][i]= -
level;
3526 coeff[1][i]= -level+1;
3529 coeff_count[i]=
FFMIN(level, 2);
3530 assert(coeff_count[i]);
3533 coeff[0][i]= (level>>31)|1;
3540 if(last_non_zero < start_i){
3541 memset(block + start_i, 0, (64-start_i)*
sizeof(int16_t));
3542 return last_non_zero;
3545 score_tab[start_i]= 0;
3546 survivor[0]= start_i;
3549 for(i=start_i; i<=last_non_zero; i++){
3550 int level_index, j, zero_distortion;
3551 int dct_coeff=
FFABS(block[ scantable[i] ]);
3552 int best_score=256*256*256*120;
3556 zero_distortion= dct_coeff*dct_coeff;
3558 for(level_index=0; level_index < coeff_count[i]; level_index++){
3560 int level= coeff[level_index][i];
3561 const int alevel=
FFABS(level);
3567 unquant_coeff= alevel*qmul + qadd;
3571 unquant_coeff = (int)( alevel * qscale * s->
intra_matrix[j]) >> 3;
3572 unquant_coeff = (unquant_coeff - 1) | 1;
3574 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[j])) >> 4;
3575 unquant_coeff = (unquant_coeff - 1) | 1;
3580 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
3582 if((level&(~127)) == 0){
3583 for(j=survivor_count-1; j>=0; j--){
3584 int run= i - survivor[j];
3586 score += score_tab[i-
run];
3588 if(score < best_score){
3591 level_tab[i+1]= level-64;
3596 for(j=survivor_count-1; j>=0; j--){
3597 int run= i - survivor[j];
3599 score += score_tab[i-
run];
3600 if(score < last_score){
3603 last_level= level-64;
3609 distortion += esc_length*
lambda;
3610 for(j=survivor_count-1; j>=0; j--){
3611 int run= i - survivor[j];
3612 int score= distortion + score_tab[i-
run];
3614 if(score < best_score){
3617 level_tab[i+1]= level-64;
3622 for(j=survivor_count-1; j>=0; j--){
3623 int run= i - survivor[j];
3624 int score= distortion + score_tab[i-
run];
3625 if(score < last_score){
3628 last_level= level-64;
3636 score_tab[i+1]= best_score;
3639 if(last_non_zero <= 27){
3640 for(; survivor_count; survivor_count--){
3641 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
3645 for(; survivor_count; survivor_count--){
3646 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
3651 survivor[ survivor_count++ ]= i+1;
3655 last_score= 256*256*256*120;
3656 for(i= survivor[0]; i<=last_non_zero + 1; i++){
3657 int score= score_tab[i];
3658 if(i) score += lambda*2;
3660 if(score < last_score){
3663 last_level= level_tab[i];
3664 last_run= run_tab[i];
3671 dc=
FFABS(block[0]);
3672 last_non_zero= last_i - 1;
3673 memset(block + start_i, 0, (64-start_i)*
sizeof(int16_t));
3675 if(last_non_zero < start_i)
3676 return last_non_zero;
3678 if(last_non_zero == 0 && start_i == 0){
3680 int best_score= dc *
dc;
3682 for(i=0; i<coeff_count[0]; i++){
3683 int level= coeff[i][0];
3684 int alevel=
FFABS(level);
3685 int unquant_coeff, score, distortion;
3688 unquant_coeff= (alevel*qmul + qadd)>>3;
3690 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[0])) >> 4;
3691 unquant_coeff = (unquant_coeff - 1) | 1;
3693 unquant_coeff = (unquant_coeff + 4) >> 3;
3694 unquant_coeff<<= 3 + 3;
3696 distortion= (unquant_coeff -
dc) * (unquant_coeff - dc);
3699 else score= distortion + esc_length*
lambda;
3701 if(score < best_score){
3703 best_level= level - 64;
3706 block[0]= best_level;
3708 if(best_level == 0)
return -1;
3709 else return last_non_zero;
3715 block[ perm_scantable[last_non_zero] ]= last_level;
3718 for(; i>start_i; i -= run_tab[i] + 1){
3719 block[ perm_scantable[i-1] ]= level_tab[i];
3722 return last_non_zero;
3737 int perm_index= perm[
index];
3738 if(i==0) s*= sqrt(0.5);
3739 if(j==0) s*= sqrt(0.5);
3740 basis[perm_index][8*x + y]=
lrintf(s * cos((M_PI/8.0)*i*(x+0.5)) * cos((M_PI/8.0)*j*(y+0.5)));
3748 int16_t *
block, int16_t *weight, int16_t *orig,
3759 int qmul, qadd, start_i, last_non_zero, i,
dc;
3763 int rle_index,
run, q = 1, sum;
3766 static int after_last=0;
3767 static int to_zero=0;
3768 static int from_zero=0;
3771 static int messed_sign=0;
3774 if(basis[0][0] == 0)
3811 for(i=0; i<64; i++){
3818 for(i=0; i<64; i++){
3823 w=
FFABS(weight[i]) + qns*one;
3824 w= 15 + (48*qns*one + w/2)/w;
3839 for(i=start_i; i<=last_non_zero; i++){
3840 int j= perm_scantable[i];
3841 const int level= block[j];
3845 if(level<0) coeff= qmul*level - qadd;
3846 else coeff= qmul*level + qadd;
3847 run_tab[rle_index++]=
run;
3856 if(last_non_zero>0){
3867 int run2, best_unquant_change=0, analyze_gradient;
3873 if(analyze_gradient){
3877 for(i=0; i<64; i++){
3893 const int level= block[0];
3894 int change, old_coeff;
3900 for(change=-1; change<=1; change+=2){
3901 int new_level= level + change;
3902 int score, new_coeff;
3904 new_coeff= q*new_level;
3905 if(new_coeff >= 2048 || new_coeff < 0)
3908 score= s->
dsp.
try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
3909 if(score<best_score){
3912 best_change= change;
3913 best_unquant_change= new_coeff - old_coeff;
3920 run2= run_tab[rle_index++];
3924 for(i=start_i; i<64; i++){
3925 int j= perm_scantable[i];
3926 const int level= block[j];
3927 int change, old_coeff;
3933 if(level<0) old_coeff= qmul*level - qadd;
3934 else old_coeff= qmul*level + qadd;
3935 run2= run_tab[rle_index++];
3939 assert(run2>=0 || i >= last_non_zero );
3942 for(change=-1; change<=1; change+=2){
3943 int new_level= level + change;
3944 int score, new_coeff, unquant_change;
3951 if(new_level<0) new_coeff= qmul*new_level - qadd;
3952 else new_coeff= qmul*new_level + qadd;
3953 if(new_coeff >= 2048 || new_coeff <= -2048)
3958 if(level < 63 && level > -63){
3959 if(i < last_non_zero)
3967 assert(
FFABS(new_level)==1);
3969 if(analyze_gradient){
3970 int g= d1[ scantable[i] ];
3971 if(g && (g^new_level) >= 0)
3975 if(i < last_non_zero){
3976 int next_i= i + run2 + 1;
3977 int next_level= block[ perm_scantable[next_i] ] + 64;
3979 if(next_level&(~127))
3982 if(next_i < last_non_zero)
4000 assert(
FFABS(level)==1);
4002 if(i < last_non_zero){
4003 int next_i= i + run2 + 1;
4004 int next_level= block[ perm_scantable[next_i] ] + 64;
4006 if(next_level&(~127))
4009 if(next_i < last_non_zero)
4028 unquant_change= new_coeff - old_coeff;
4029 assert((score < 100*lambda && score > -100*lambda) || lambda==0);
4032 if(score<best_score){
4035 best_change= change;
4036 best_unquant_change= unquant_change;
4040 prev_level= level + 64;
4041 if(prev_level&(~127))
4054 int j= perm_scantable[ best_coeff ];
4056 block[j] += best_change;
4058 if(best_coeff > last_non_zero){
4059 last_non_zero= best_coeff;
4067 if(block[j] - best_change){
4068 if(
FFABS(block[j]) >
FFABS(block[j] - best_change)){
4080 for(; last_non_zero>=start_i; last_non_zero--){
4081 if(block[perm_scantable[last_non_zero]])
4087 if(256*256*256*64 % count == 0){
4088 printf(
"after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero,
raise, lower, messed_sign, s->
mb_x, s->
mb_y, s->
picture_number);
4093 for(i=start_i; i<=last_non_zero; i++){
4094 int j= perm_scantable[i];
4095 const int level= block[j];
4098 run_tab[rle_index++]=
run;
4111 if(last_non_zero>0){
4117 return last_non_zero;
4121 int16_t *
block,
int n,
4122 int qscale,
int *overflow)
4124 int i, j,
level, last_non_zero, q, start_i;
4129 unsigned int threshold1, threshold2;
4148 block[0] = (block[0] + (q >> 1)) / q;
4160 threshold2= (threshold1<<1);
4161 for(i=63;i>=start_i;i--) {
4163 level = block[j] * qmat[j];
4165 if(((
unsigned)(level+threshold1))>threshold2){
4172 for(i=start_i; i<=last_non_zero; i++) {
4174 level = block[j] * qmat[j];
4178 if(((
unsigned)(level+threshold1))>threshold2){
4197 return last_non_zero;
4200 #define OFFSET(x) offsetof(MpegEncContext, x)
4201 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4205 {
"mb_info",
"emit macroblock info for RFC 2190 packetization, the parameter value is the maximum payload size",
OFFSET(
mb_info),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
4262 .
name =
"msmpeg4v2",
4271 .priv_class = &msmpeg4v2_class,
4286 .priv_class = &msmpeg4v3_class,
4301 .priv_class = &wmv1_class,