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++){
3401 for(i=1; i<context_count; i++){
3405 for(i=1; i<context_count; i++){
3418 for(i=0; i<64; i++){
3419 int level= block[i];
3425 if(level<0) level=0;
3429 if(level>0) level=0;
3437 int16_t *
block,
int n,
3438 int qscale,
int *overflow){
3443 unsigned int threshold1, threshold2;
3455 int coeff_count[64];
3456 int qmul, qadd, start_i, last_non_zero, i,
dc;
3467 qadd= ((qscale-1)|1)*8;
3484 block[0] = (block[0] + (q >> 1)) / q;
3502 threshold2= (threshold1<<1);
3504 for(i=63; i>=start_i; i--) {
3505 const int j = scantable[i];
3506 int level = block[j] * qmat[j];
3508 if(((
unsigned)(level+threshold1))>threshold2){
3514 for(i=start_i; i<=last_non_zero; i++) {
3515 const int j = scantable[i];
3516 int level = block[j] * qmat[j];
3520 if(((
unsigned)(level+threshold1))>threshold2){
3524 coeff[1][i]= level-1;
3528 coeff[0][i]= -
level;
3529 coeff[1][i]= -level+1;
3532 coeff_count[i]=
FFMIN(level, 2);
3533 assert(coeff_count[i]);
3536 coeff[0][i]= (level>>31)|1;
3543 if(last_non_zero < start_i){
3544 memset(block + start_i, 0, (64-start_i)*
sizeof(int16_t));
3545 return last_non_zero;
3548 score_tab[start_i]= 0;
3549 survivor[0]= start_i;
3552 for(i=start_i; i<=last_non_zero; i++){
3553 int level_index, j, zero_distortion;
3554 int dct_coeff=
FFABS(block[ scantable[i] ]);
3555 int best_score=256*256*256*120;
3559 zero_distortion= dct_coeff*dct_coeff;
3561 for(level_index=0; level_index < coeff_count[i]; level_index++){
3563 int level= coeff[level_index][i];
3564 const int alevel=
FFABS(level);
3570 unquant_coeff= alevel*qmul + qadd;
3574 unquant_coeff = (int)( alevel * qscale * s->
intra_matrix[j]) >> 3;
3575 unquant_coeff = (unquant_coeff - 1) | 1;
3577 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[j])) >> 4;
3578 unquant_coeff = (unquant_coeff - 1) | 1;
3583 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
3585 if((level&(~127)) == 0){
3586 for(j=survivor_count-1; j>=0; j--){
3587 int run= i - survivor[j];
3589 score += score_tab[i-
run];
3591 if(score < best_score){
3594 level_tab[i+1]= level-64;
3599 for(j=survivor_count-1; j>=0; j--){
3600 int run= i - survivor[j];
3602 score += score_tab[i-
run];
3603 if(score < last_score){
3606 last_level= level-64;
3612 distortion += esc_length*
lambda;
3613 for(j=survivor_count-1; j>=0; j--){
3614 int run= i - survivor[j];
3615 int score= distortion + score_tab[i-
run];
3617 if(score < best_score){
3620 level_tab[i+1]= level-64;
3625 for(j=survivor_count-1; j>=0; j--){
3626 int run= i - survivor[j];
3627 int score= distortion + score_tab[i-
run];
3628 if(score < last_score){
3631 last_level= level-64;
3639 score_tab[i+1]= best_score;
3642 if(last_non_zero <= 27){
3643 for(; survivor_count; survivor_count--){
3644 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
3648 for(; survivor_count; survivor_count--){
3649 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
3654 survivor[ survivor_count++ ]= i+1;
3658 last_score= 256*256*256*120;
3659 for(i= survivor[0]; i<=last_non_zero + 1; i++){
3660 int score= score_tab[i];
3661 if(i) score += lambda*2;
3663 if(score < last_score){
3666 last_level= level_tab[i];
3667 last_run= run_tab[i];
3674 dc=
FFABS(block[0]);
3675 last_non_zero= last_i - 1;
3676 memset(block + start_i, 0, (64-start_i)*
sizeof(int16_t));
3678 if(last_non_zero < start_i)
3679 return last_non_zero;
3681 if(last_non_zero == 0 && start_i == 0){
3683 int best_score= dc *
dc;
3685 for(i=0; i<coeff_count[0]; i++){
3686 int level= coeff[i][0];
3687 int alevel=
FFABS(level);
3688 int unquant_coeff, score, distortion;
3691 unquant_coeff= (alevel*qmul + qadd)>>3;
3693 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[0])) >> 4;
3694 unquant_coeff = (unquant_coeff - 1) | 1;
3696 unquant_coeff = (unquant_coeff + 4) >> 3;
3697 unquant_coeff<<= 3 + 3;
3699 distortion= (unquant_coeff -
dc) * (unquant_coeff - dc);
3702 else score= distortion + esc_length*
lambda;
3704 if(score < best_score){
3706 best_level= level - 64;
3709 block[0]= best_level;
3711 if(best_level == 0)
return -1;
3712 else return last_non_zero;
3718 block[ perm_scantable[last_non_zero] ]= last_level;
3721 for(; i>start_i; i -= run_tab[i] + 1){
3722 block[ perm_scantable[i-1] ]= level_tab[i];
3725 return last_non_zero;
3740 int perm_index= perm[
index];
3741 if(i==0) s*= sqrt(0.5);
3742 if(j==0) s*= sqrt(0.5);
3743 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)));
3751 int16_t *
block, int16_t *weight, int16_t *orig,
3762 int qmul, qadd, start_i, last_non_zero, i,
dc;
3766 int rle_index,
run, q = 1, sum;
3769 static int after_last=0;
3770 static int to_zero=0;
3771 static int from_zero=0;
3774 static int messed_sign=0;
3777 if(basis[0][0] == 0)
3814 for(i=0; i<64; i++){
3821 for(i=0; i<64; i++){
3826 w=
FFABS(weight[i]) + qns*one;
3827 w= 15 + (48*qns*one + w/2)/w;
3842 for(i=start_i; i<=last_non_zero; i++){
3843 int j= perm_scantable[i];
3844 const int level= block[j];
3848 if(level<0) coeff= qmul*level - qadd;
3849 else coeff= qmul*level + qadd;
3850 run_tab[rle_index++]=
run;
3859 if(last_non_zero>0){
3870 int run2, best_unquant_change=0, analyze_gradient;
3876 if(analyze_gradient){
3880 for(i=0; i<64; i++){
3896 const int level= block[0];
3897 int change, old_coeff;
3903 for(change=-1; change<=1; change+=2){
3904 int new_level= level + change;
3905 int score, new_coeff;
3907 new_coeff= q*new_level;
3908 if(new_coeff >= 2048 || new_coeff < 0)
3911 score= s->
dsp.
try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
3912 if(score<best_score){
3915 best_change= change;
3916 best_unquant_change= new_coeff - old_coeff;
3923 run2= run_tab[rle_index++];
3927 for(i=start_i; i<64; i++){
3928 int j= perm_scantable[i];
3929 const int level= block[j];
3930 int change, old_coeff;
3936 if(level<0) old_coeff= qmul*level - qadd;
3937 else old_coeff= qmul*level + qadd;
3938 run2= run_tab[rle_index++];
3942 assert(run2>=0 || i >= last_non_zero );
3945 for(change=-1; change<=1; change+=2){
3946 int new_level= level + change;
3947 int score, new_coeff, unquant_change;
3954 if(new_level<0) new_coeff= qmul*new_level - qadd;
3955 else new_coeff= qmul*new_level + qadd;
3956 if(new_coeff >= 2048 || new_coeff <= -2048)
3961 if(level < 63 && level > -63){
3962 if(i < last_non_zero)
3970 assert(
FFABS(new_level)==1);
3972 if(analyze_gradient){
3973 int g= d1[ scantable[i] ];
3974 if(g && (g^new_level) >= 0)
3978 if(i < last_non_zero){
3979 int next_i= i + run2 + 1;
3980 int next_level= block[ perm_scantable[next_i] ] + 64;
3982 if(next_level&(~127))
3985 if(next_i < last_non_zero)
4003 assert(
FFABS(level)==1);
4005 if(i < last_non_zero){
4006 int next_i= i + run2 + 1;
4007 int next_level= block[ perm_scantable[next_i] ] + 64;
4009 if(next_level&(~127))
4012 if(next_i < last_non_zero)
4031 unquant_change= new_coeff - old_coeff;
4032 assert((score < 100*lambda && score > -100*lambda) || lambda==0);
4035 if(score<best_score){
4038 best_change= change;
4039 best_unquant_change= unquant_change;
4043 prev_level= level + 64;
4044 if(prev_level&(~127))
4057 int j= perm_scantable[ best_coeff ];
4059 block[j] += best_change;
4061 if(best_coeff > last_non_zero){
4062 last_non_zero= best_coeff;
4070 if(block[j] - best_change){
4071 if(
FFABS(block[j]) >
FFABS(block[j] - best_change)){
4083 for(; last_non_zero>=start_i; last_non_zero--){
4084 if(block[perm_scantable[last_non_zero]])
4090 if(256*256*256*64 % count == 0){
4091 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);
4096 for(i=start_i; i<=last_non_zero; i++){
4097 int j= perm_scantable[i];
4098 const int level= block[j];
4101 run_tab[rle_index++]=
run;
4114 if(last_non_zero>0){
4120 return last_non_zero;
4124 int16_t *
block,
int n,
4125 int qscale,
int *overflow)
4127 int i, j,
level, last_non_zero, q, start_i;
4132 unsigned int threshold1, threshold2;
4151 block[0] = (block[0] + (q >> 1)) / q;
4163 threshold2= (threshold1<<1);
4164 for(i=63;i>=start_i;i--) {
4166 level = block[j] * qmat[j];
4168 if(((
unsigned)(level+threshold1))>threshold2){
4175 for(i=start_i; i<=last_non_zero; i++) {
4177 level = block[j] * qmat[j];
4181 if(((
unsigned)(level+threshold1))>threshold2){
4200 return last_non_zero;
4203 #define OFFSET(x) offsetof(MpegEncContext, x)
4204 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4208 {
"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 },
4265 .
name =
"msmpeg4v2",
4274 .priv_class = &msmpeg4v2_class,
4289 .priv_class = &msmpeg4v3_class,
4304 .priv_class = &wmv1_class,