73 uint16_t (*qmat16)[2][64],
74 const uint16_t *quant_matrix,
75 int bias,
int qmin,
int qmax,
int intra)
80 for (qscale = qmin; qscale <= qmax; qscale++) {
85 for (i = 0; i < 64; i++) {
94 (qscale * quant_matrix[j]));
97 for (i = 0; i < 64; i++) {
110 for (i = 0; i < 64; i++) {
118 (qscale * quant_matrix[j]));
122 (qscale * quant_matrix[j]);
124 if (qmat16[qscale][0][i] == 0 ||
125 qmat16[qscale][0][i] == 128 * 256)
126 qmat16[
qscale][0][i] = 128 * 256 - 1;
129 qmat16[qscale][0][i]);
133 for (i = intra; i < 64; i++) {
138 while (((max * qmat[qscale][i]) >> shift) > INT_MAX) {
145 "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
166 for (i = 0; i < 64; i++) {
181 for (i = 0; i < s->
mb_num; i++) {
213 "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
219 for (i = 0; i < 2; i++) {
227 2 * stride * height *
sizeof(int16_t));
240 #define COPY(a) dst->a= src->a
265 for (i = -16; i < 16; i++) {
277 int chroma_h_shift, chroma_v_shift;
286 "only YUV420 and YUV422 are supported\n");
338 "Warning keyframe interval too large! reducing it ...\n");
347 #if FF_API_MPV_GLOBAL_OPTS
348 if (avctx->luma_elim_threshold)
350 if (avctx->chroma_elim_threshold)
372 #if FF_API_MPV_GLOBAL_OPTS
390 "a vbv buffer size is needed, "
391 "for encoding with a maximum bitrate\n");
397 "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
414 "impossible bitrate constraints, this will fail\n");
428 "bitrate tolerance too small for bitrate\n");
439 "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
440 "specified vbv buffer is too large for the given bitrate!\n");
452 "OBMC is only supported with simple mb decision\n");
475 "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
489 "mpeg2 style quantization not supported by codec\n");
493 #if FF_API_MPV_GLOBAL_OPTS
512 "closed gop with scene change detection are not supported yet, "
513 "set threshold to 1000000000\n");
520 "low delay forcing is only available for mpeg2\n");
525 "b frames cannot be used with low delay\n");
531 if (avctx->
qmax > 12) {
533 "non linear quant only supports qmax <= 12 currently\n");
544 "multi threaded encoding not supported by codec\n");
550 "automatic thread number detection not supported by codec,"
563 i = (INT_MAX / 2 + 128) >> 8;
577 "notice: b_frame_strategy only affects the first pass\n");
611 "timebase %d/%d not supported by MPEG 4 standard, "
612 "the maximum admitted value for the timebase denominator "
619 #if FF_API_MPV_GLOBAL_OPTS
624 if (avctx->quantizer_noise_shaping)
668 "The specified picture size of %dx%d is not valid for the "
669 "H.261 codec.\nValid sizes are 176x144, 352x288\n",
683 "The specified picture size of %dx%d is not valid for "
684 "the H.263 codec.\nValid sizes are 128x96, 176x144, "
685 "352x288, 704x576, and 1408x1152."
819 for (i = 0; i < 64; i++) {
877 for (y = 0; y < 16; y++) {
878 for (x = 0; x < 16; x++) {
879 acc +=
FFABS(src[x + y * stride] - ref);
895 for (y = 0; y < h; y += 16) {
896 for (x = 0; x < w; x += 16) {
897 int offset = x + y *
stride;
900 int mean = (s->
dsp.
pix_sum(src + offset, stride) + 128) >> 8;
901 int sae =
get_sae(src + offset, mean, stride);
903 acc += sae + 500 < sad;
930 "Error, Invalid timestamp=%"PRId64
", "
944 "Warning: AVFrame.pts=? trying to guess (%"PRId64
")\n",
973 for (i = 0; i < 4; i++) {
997 int h_chroma_shift, v_chroma_shift;
1002 for (i = 0; i < 3; i++) {
1003 int src_stride = pic_arg->
linesize[i];
1005 int h_shift = i ? h_chroma_shift : 0;
1006 int v_shift = i ? v_chroma_shift : 0;
1007 int w = s->
width >> h_shift;
1008 int h = s->
height >> v_shift;
1015 if (src_stride == dst_stride)
1016 memcpy(dst, src, src_stride * h);
1019 memcpy(dst, src, w);
1044 int64_t score64 = 0;
1046 for (plane = 0; plane < 3; plane++) {
1048 const int bw = plane ? 1 : 2;
1049 for (y = 0; y < s->
mb_height * bw; y++) {
1050 for (x = 0; x < s->
mb_width * bw; x++) {
1057 case 0: score =
FFMAX(score, v);
break;
1058 case 1: score +=
FFABS(v);
break;
1059 case 2: score += v * v;
break;
1060 case 3: score64 +=
FFABS(v * v * (int64_t)v);
break;
1061 case 4: score64 += v * v * (int64_t)(v * v);
break;
1080 int ret, got_output;
1098 int i, j, out_size, p_lambda, b_lambda,
lambda2;
1099 int64_t best_rd = INT64_MAX;
1100 int best_b_count = -1;
1102 assert(scale >= 0 && scale <= 3);
1110 b_lambda = p_lambda;
1138 input[i].
data[1] = input[i].
data[0] + ysize;
1139 input[i].
data[2] = input[i].
data[1] + csize;
1145 pre_input = *pre_input_ptr;
1185 input[i + 1].
quality = is_p ? p_lambda : b_lambda;
1213 return best_b_count;
1240 for (i = 0; i < 4; i++)
1296 b_frames =
FFMAX(0, i - 1);
1299 for (i = 0; i < b_frames + 1; i++) {
1311 for (i = b_frames - 1; i >= 0; i--) {
1319 "warning, too many b frames in a row\n");
1342 for (i = 0; i < b_frames; i++) {
1379 for (i = 0; i < 4; i++)
1396 for (i = 0; i < 4; i++) {
1410 const AVFrame *pic_arg,
int *got_packet)
1413 int i, stuffing_count, ret;
1437 for (i = 0; i < context_count; i++) {
1441 uint8_t *start = pkt->
data + (size_t)(((int64_t) pkt->
size) * start_y / h);
1442 uint8_t *end = pkt->
data + (size_t)(((int64_t) pkt->
size) * end_y / h);
1497 for (i = 0; i < context_count; i++) {
1510 for (i = 0; i < 4; i++) {
1523 if (stuffing_count) {
1525 stuffing_count + 50) {
1533 while (stuffing_count--) {
1540 stuffing_count -= 4;
1541 while (stuffing_count--) {
1558 int vbv_delay, min_delay;
1567 "Internal error, negative bits\n");
1575 vbv_delay =
FFMAX(vbv_delay, min_delay);
1577 assert(vbv_delay < 0xFFFF);
1608 *got_packet = !!pkt->
size;
1613 int n,
int threshold)
1615 static const char tab[64] = {
1616 3, 2, 2, 1, 1, 1, 1, 1,
1617 1, 1, 1, 1, 1, 1, 1, 1,
1618 1, 1, 1, 1, 1, 1, 1, 1,
1619 0, 0, 0, 0, 0, 0, 0, 0,
1620 0, 0, 0, 0, 0, 0, 0, 0,
1621 0, 0, 0, 0, 0, 0, 0, 0,
1622 0, 0, 0, 0, 0, 0, 0, 0,
1623 0, 0, 0, 0, 0, 0, 0, 0
1632 if (threshold < 0) {
1634 threshold = -threshold;
1639 if (last_index <= skip_dc - 1)
1642 for (i = 0; i <= last_index; i++) {
1646 if (skip_dc && i == 0)
1650 }
else if (level > 1) {
1656 if (score >= threshold)
1658 for (i = skip_dc; i <= last_index; i++) {
1681 for (; i <= last_index; i++) {
1683 int level = block[j];
1685 if (level > maxlevel) {
1688 }
else if (level < minlevel) {
1698 "warning, clipping %d dct coefficients to %d..%d\n",
1699 overflow, minlevel, maxlevel);
1706 for (y = 0; y < 8; y++) {
1707 for (x = 0; x < 8; x++) {
1713 for (y2 =
FFMAX(y - 1, 0); y2 <
FFMIN(8, y + 2); y2++) {
1714 for (x2=
FFMAX(x - 1, 0); x2 <
FFMIN(8, x + 2); x2++) {
1715 int v = ptr[x2 + y2 *
stride];
1721 weight[x + 8 * y]= (36 *
ff_sqrt(count * sqr - sum * sum)) / count;
1727 int motion_x,
int motion_y,
1728 int mb_block_height,
1731 int16_t weight[8][64];
1738 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
1741 for (i = 0; i < mb_block_count; i++)
1745 const int last_qp = s->
qscale;
1746 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1777 (mb_y * 16 * wrap_y) + mb_x * 16;
1779 (mb_y * mb_block_height * wrap_c) + mb_x * 8;
1781 (mb_y * mb_block_height * wrap_c) + mb_x * 8;
1783 if (mb_x * 16 + 16 > s->
width || mb_y * 16 + 16 > s->
height) {
1789 mb_block_height, mb_x * 8, mb_y * 8,
1791 ptr_cb = ebuf + 18 * wrap_y;
1793 mb_block_height, mb_x * 8, mb_y * 8,
1795 ptr_cr = ebuf + 18 * wrap_y + 8;
1800 int progressive_score, interlaced_score;
1806 NULL, wrap_y, 8) - 400;
1808 if (progressive_score > 0) {
1810 NULL, wrap_y * 2, 8) +
1812 NULL, wrap_y * 2, 8);
1813 if (progressive_score > interlaced_score) {
1816 dct_offset = wrap_y;
1837 ptr_cb + (dct_offset >> 1), wrap_c);
1839 ptr_cr + (dct_offset >> 1), wrap_c);
1845 uint8_t *dest_y, *dest_cb, *dest_cr;
1847 dest_y = s->
dest[0];
1848 dest_cb = s->
dest[1];
1849 dest_cr = s->
dest[2];
1873 int progressive_score, interlaced_score;
1880 ptr_y + wrap_y * 8, wrap_y,
1884 progressive_score -= 400;
1886 if (progressive_score > 0) {
1894 if (progressive_score > interlaced_score) {
1897 dct_offset = wrap_y;
1908 dest_y + dct_offset, wrap_y);
1910 dest_y + dct_offset + 8, wrap_y);
1920 dest_cb + (dct_offset >> 1), wrap_c);
1922 dest_cr + (dct_offset >> 1), wrap_c);
1930 wrap_y, 8) < 20 * s->
qscale)
1933 dest_y + 8, wrap_y, 8) < 20 * s->
qscale)
1936 dest_y + dct_offset, wrap_y, 8) < 20 * s->
qscale)
1938 if (s->
dsp.
sad[1](
NULL, ptr_y + dct_offset + 8,
1939 dest_y + dct_offset + 8,
1940 wrap_y, 8) < 20 * s->
qscale)
1943 wrap_c, 8) < 20 * s->
qscale)
1946 wrap_c, 8) < 20 * s->
qscale)
1949 if (s->
dsp.
sad[1](
NULL, ptr_cb + (dct_offset >> 1),
1950 dest_cb + (dct_offset >> 1),
1951 wrap_c, 8) < 20 * s->
qscale)
1953 if (s->
dsp.
sad[1](
NULL, ptr_cr + (dct_offset >> 1),
1954 dest_cr + (dct_offset >> 1),
1955 wrap_c, 8) < 20 * s->
qscale)
1982 memcpy(orig[0], s->
block[0],
sizeof(
DCTELEM) * 64 * mb_block_count);
1988 for (i = 0; i < mb_block_count; i++) {
2003 for (i = 0; i < mb_block_count; i++) {
2013 for (i = 0; i < 4; i++)
2016 for (i = 4; i < mb_block_count; i++)
2020 for (i = 0; i < mb_block_count; i++) {
2036 for (i = 0; i < mb_block_count; i++) {
2039 for (j = 63; j > 0; j--) {
2127 memcpy(d->
mv, s->
mv, 2*4*2*
sizeof(
int));
2165 int *dmin,
int *next_block,
int motion_x,
int motion_y)
2173 s->
pb= pb[*next_block];
2175 s->
pb2 = pb2 [*next_block];
2176 s->
tex_pb= tex_pb[*next_block];
2180 memcpy(dest_backup, s->
dest,
sizeof(s->
dest));
2203 memcpy(s->
dest, dest_backup,
sizeof(s->
dest));
2221 else if(w==8 && h==8)
2311 for(mb_x=0; mb_x < s->
mb_width; mb_x++) {
2355 bytestream_put_le32(&ptr, offset);
2356 bytestream_put_byte(&ptr, s->
qscale);
2357 bytestream_put_byte(&ptr, gobn);
2358 bytestream_put_le16(&ptr, mba);
2359 bytestream_put_byte(&ptr, pred_x);
2360 bytestream_put_byte(&ptr, pred_y);
2362 bytestream_put_byte(&ptr, 0);
2363 bytestream_put_byte(&ptr, 0);
2454 for(mb_x=0; mb_x < s->
mb_width; mb_x++) {
2485 int current_packet_size, is_gob_start;
2491 if(s->
start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
2500 if(s->
mb_x==0 && s->
mb_y!=0) is_gob_start=1;
2522 current_packet_size=0;
2580 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
2597 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,
2598 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2609 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,
2610 &dmin, &next_block, 0, 0);
2618 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,
2619 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2629 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
2630 &dmin, &next_block, 0, 0);
2638 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,
2639 &dmin, &next_block, s->
mv[0][0][0], s->
mv[0][0][1]);
2647 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,
2648 &dmin, &next_block, s->
mv[1][0][0], s->
mv[1][0][1]);
2658 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,
2659 &dmin, &next_block, 0, 0);
2670 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,
2671 &dmin, &next_block, 0, 0);
2682 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb,
2683 &dmin, &next_block, 0, 0);
2689 for(dir=0; dir<2; dir++){
2696 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb,
2697 &dmin, &next_block, 0, 0);
2705 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb,
2706 &dmin, &next_block, 0, 0);
2717 const int last_qp= backup_s.
qscale;
2721 static const int dquant_tab[4]={-1,1,-2,2};
2723 assert(backup_s.
dquant == 0);
2729 s->
mv[0][0][0] = best_s.
mv[0][0][0];
2730 s->
mv[0][0][1] = best_s.
mv[0][0][1];
2731 s->
mv[1][0][0] = best_s.
mv[1][0][0];
2732 s->
mv[1][0][1] = best_s.
mv[1][0][1];
2735 for(; qpi<4; qpi++){
2736 int dquant= dquant_tab[qpi];
2748 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,
2749 &dmin, &next_block, s->
mv[mvdir][0][0], s->
mv[mvdir][0][1]);
2769 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2770 &dmin, &next_block, mx, my);
2777 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
2778 &dmin, &next_block, 0, 0);
2786 memcpy(s->
mv, best_s.
mv,
sizeof(s->
mv));
2807 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER , pb, pb2, tex_pb,
2808 &dmin, &next_block, mx, my);
2848 int motion_x = 0, motion_y = 0;
2856 motion_x= s->
mv[0][0][0] = 0;
2857 motion_y= s->
mv[0][0][1] = 0;
2944 for(dir=0; dir<2; dir++){
3018 #define MERGE(field) dst->field += src->field; src->field=0
3045 for(i=0; i<64; i++){
3152 for(i=1; i<context_count; i++){
3182 for(i=1; i<context_count; i++){
3193 av_dlog(s,
"Scene change detected, encoding as I Frame %d %d\n",
3237 for(dir=0; dir<2; dir++){
3319 for(i=1; i<context_count; i++){
3323 for(i=1; i<context_count; i++){
3336 for(i=0; i<64; i++){
3337 int level= block[i];
3343 if(level<0) level=0;
3347 if(level>0) level=0;
3356 int qscale,
int *overflow){
3361 unsigned int threshold1, threshold2;
3373 int coeff_count[64];
3374 int qmul, qadd, start_i, last_non_zero, i, dc;
3385 qadd= ((qscale-1)|1)*8;
3402 block[0] = (block[0] + (q >> 1)) / q;
3420 threshold2= (threshold1<<1);
3422 for(i=63; i>=start_i; i--) {
3423 const int j = scantable[i];
3424 int level = block[j] * qmat[j];
3426 if(((
unsigned)(level+threshold1))>threshold2){
3432 for(i=start_i; i<=last_non_zero; i++) {
3433 const int j = scantable[i];
3434 int level = block[j] * qmat[j];
3438 if(((
unsigned)(level+threshold1))>threshold2){
3442 coeff[1][i]= level-1;
3446 coeff[0][i]= -
level;
3447 coeff[1][i]= -level+1;
3450 coeff_count[i]=
FFMIN(level, 2);
3451 assert(coeff_count[i]);
3454 coeff[0][i]= (level>>31)|1;
3461 if(last_non_zero < start_i){
3462 memset(block + start_i, 0, (64-start_i)*
sizeof(
DCTELEM));
3463 return last_non_zero;
3466 score_tab[start_i]= 0;
3467 survivor[0]= start_i;
3470 for(i=start_i; i<=last_non_zero; i++){
3471 int level_index, j, zero_distortion;
3472 int dct_coeff=
FFABS(block[ scantable[i] ]);
3473 int best_score=256*256*256*120;
3477 zero_distortion= dct_coeff*dct_coeff;
3479 for(level_index=0; level_index < coeff_count[i]; level_index++){
3481 int level= coeff[level_index][i];
3482 const int alevel=
FFABS(level);
3488 unquant_coeff= alevel*qmul + qadd;
3492 unquant_coeff = (int)( alevel * qscale * s->
intra_matrix[j]) >> 3;
3493 unquant_coeff = (unquant_coeff - 1) | 1;
3495 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[j])) >> 4;
3496 unquant_coeff = (unquant_coeff - 1) | 1;
3501 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
3503 if((level&(~127)) == 0){
3504 for(j=survivor_count-1; j>=0; j--){
3505 int run= i - survivor[j];
3507 score += score_tab[i-
run];
3509 if(score < best_score){
3512 level_tab[i+1]= level-64;
3517 for(j=survivor_count-1; j>=0; j--){
3518 int run= i - survivor[j];
3520 score += score_tab[i-
run];
3521 if(score < last_score){
3524 last_level= level-64;
3530 distortion += esc_length*
lambda;
3531 for(j=survivor_count-1; j>=0; j--){
3532 int run= i - survivor[j];
3533 int score= distortion + score_tab[i-
run];
3535 if(score < best_score){
3538 level_tab[i+1]= level-64;
3543 for(j=survivor_count-1; j>=0; j--){
3544 int run= i - survivor[j];
3545 int score= distortion + score_tab[i-
run];
3546 if(score < last_score){
3549 last_level= level-64;
3557 score_tab[i+1]= best_score;
3560 if(last_non_zero <= 27){
3561 for(; survivor_count; survivor_count--){
3562 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
3566 for(; survivor_count; survivor_count--){
3567 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
3572 survivor[ survivor_count++ ]= i+1;
3576 last_score= 256*256*256*120;
3577 for(i= survivor[0]; i<=last_non_zero + 1; i++){
3578 int score= score_tab[i];
3579 if(i) score += lambda*2;
3581 if(score < last_score){
3584 last_level= level_tab[i];
3585 last_run= run_tab[i];
3592 dc=
FFABS(block[0]);
3593 last_non_zero= last_i - 1;
3594 memset(block + start_i, 0, (64-start_i)*
sizeof(
DCTELEM));
3596 if(last_non_zero < start_i)
3597 return last_non_zero;
3599 if(last_non_zero == 0 && start_i == 0){
3601 int best_score= dc * dc;
3603 for(i=0; i<coeff_count[0]; i++){
3604 int level= coeff[i][0];
3605 int alevel=
FFABS(level);
3606 int unquant_coeff, score, distortion;
3609 unquant_coeff= (alevel*qmul + qadd)>>3;
3611 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->
inter_matrix[0])) >> 4;
3612 unquant_coeff = (unquant_coeff - 1) | 1;
3614 unquant_coeff = (unquant_coeff + 4) >> 3;
3615 unquant_coeff<<= 3 + 3;
3617 distortion= (unquant_coeff - dc) * (unquant_coeff - dc);
3620 else score= distortion + esc_length*
lambda;
3622 if(score < best_score){
3624 best_level= level - 64;
3627 block[0]= best_level;
3629 if(best_level == 0)
return -1;
3630 else return last_non_zero;
3636 block[ perm_scantable[last_non_zero] ]= last_level;
3639 for(; i>start_i; i -= run_tab[i] + 1){
3640 block[ perm_scantable[i-1] ]= level_tab[i];
3643 return last_non_zero;
3658 int perm_index= perm[
index];
3659 if(i==0) s*= sqrt(0.5);
3660 if(j==0) s*= sqrt(0.5);
3661 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)));
3680 int qmul, qadd, start_i, last_non_zero, i, dc;
3684 int rle_index,
run, q = 1, sum;
3687 static int after_last=0;
3688 static int to_zero=0;
3689 static int from_zero=0;
3692 static int messed_sign=0;
3695 if(basis[0][0] == 0)
3732 for(i=0; i<64; i++){
3739 for(i=0; i<64; i++){
3744 w=
FFABS(weight[i]) + qns*one;
3745 w= 15 + (48*qns*one + w/2)/w;
3760 for(i=start_i; i<=last_non_zero; i++){
3761 int j= perm_scantable[i];
3762 const int level= block[j];
3766 if(level<0) coeff= qmul*level - qadd;
3767 else coeff= qmul*level + qadd;
3768 run_tab[rle_index++]=
run;
3777 if(last_non_zero>0){
3788 int run2, best_unquant_change=0, analyze_gradient;
3794 if(analyze_gradient){
3798 for(i=0; i<64; i++){
3814 const int level= block[0];
3815 int change, old_coeff;
3821 for(change=-1; change<=1; change+=2){
3822 int new_level= level + change;
3823 int score, new_coeff;
3825 new_coeff= q*new_level;
3826 if(new_coeff >= 2048 || new_coeff < 0)
3829 score= s->
dsp.
try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff);
3830 if(score<best_score){
3833 best_change= change;
3834 best_unquant_change= new_coeff - old_coeff;
3841 run2= run_tab[rle_index++];
3845 for(i=start_i; i<64; i++){
3846 int j= perm_scantable[i];
3847 const int level= block[j];
3848 int change, old_coeff;
3854 if(level<0) old_coeff= qmul*level - qadd;
3855 else old_coeff= qmul*level + qadd;
3856 run2= run_tab[rle_index++];
3860 assert(run2>=0 || i >= last_non_zero );
3863 for(change=-1; change<=1; change+=2){
3864 int new_level= level + change;
3865 int score, new_coeff, unquant_change;
3872 if(new_level<0) new_coeff= qmul*new_level - qadd;
3873 else new_coeff= qmul*new_level + qadd;
3874 if(new_coeff >= 2048 || new_coeff <= -2048)
3879 if(level < 63 && level > -63){
3880 if(i < last_non_zero)
3888 assert(
FFABS(new_level)==1);
3890 if(analyze_gradient){
3891 int g= d1[ scantable[i] ];
3892 if(g && (g^new_level) >= 0)
3896 if(i < last_non_zero){
3897 int next_i= i + run2 + 1;
3898 int next_level= block[ perm_scantable[next_i] ] + 64;
3900 if(next_level&(~127))
3903 if(next_i < last_non_zero)
3921 assert(
FFABS(level)==1);
3923 if(i < last_non_zero){
3924 int next_i= i + run2 + 1;
3925 int next_level= block[ perm_scantable[next_i] ] + 64;
3927 if(next_level&(~127))
3930 if(next_i < last_non_zero)
3949 unquant_change= new_coeff - old_coeff;
3950 assert((score < 100*lambda && score > -100*lambda) || lambda==0);
3953 if(score<best_score){
3956 best_change= change;
3957 best_unquant_change= unquant_change;
3961 prev_level= level + 64;
3962 if(prev_level&(~127))
3975 int j= perm_scantable[ best_coeff ];
3977 block[j] += best_change;
3979 if(best_coeff > last_non_zero){
3980 last_non_zero= best_coeff;
3988 if(block[j] - best_change){
3989 if(
FFABS(block[j]) >
FFABS(block[j] - best_change)){
4001 for(; last_non_zero>=start_i; last_non_zero--){
4002 if(block[perm_scantable[last_non_zero]])
4008 if(256*256*256*64 % count == 0){
4009 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);
4014 for(i=start_i; i<=last_non_zero; i++){
4015 int j= perm_scantable[i];
4016 const int level= block[j];
4019 run_tab[rle_index++]=
run;
4032 if(last_non_zero>0){
4038 return last_non_zero;
4043 int qscale,
int *overflow)
4045 int i, j,
level, last_non_zero, q, start_i;
4050 unsigned int threshold1, threshold2;
4069 block[0] = (block[0] + (q >> 1)) / q;
4081 threshold2= (threshold1<<1);
4082 for(i=63;i>=start_i;i--) {
4084 level = block[j] * qmat[j];
4086 if(((
unsigned)(level+threshold1))>threshold2){
4093 for(i=start_i; i<=last_non_zero; i++) {
4095 level = block[j] * qmat[j];
4099 if(((
unsigned)(level+threshold1))>threshold2){
4118 return last_non_zero;
4121 #define OFFSET(x) offsetof(MpegEncContext, x)
4122 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4126 {
"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 },
4183 .
name =
"msmpeg4v2",
4192 .priv_class = &msmpeg4v2_class,
4207 .priv_class = &msmpeg4v3_class,
4222 .priv_class = &wmv1_class,
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
#define CODEC_FLAG_INTERLACED_DCT
void ff_h263_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
int chroma_elim_threshold
static const AVOption h263_options[]
int frame_bits
bits used for the current frame
RateControlContext rc_context
contains stuff only accessed in ratecontrol.c
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define FF_MPV_FLAG_STRICT_GOP
#define CODEC_FLAG_CBP_RD
void ff_init_block_index(MpegEncContext *s)
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define MAX_PICTURE_COUNT
int(* dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)
#define CODEC_FLAG_CLOSED_GOP
const uint8_t ff_zigzag_direct[64]
me_cmp_func frame_skip_cmp[6]
void av_free_packet(AVPacket *pkt)
Free a packet.
static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride)
int time_increment_bits
number of bits to represent the fractional part of time
void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number)
This structure describes decoded (raw) audio or video data.
struct MpegEncContext MpegEncContext
MpegEncContext.
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
#define CODEC_FLAG_INTERLACED_ME
int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared)
Allocate a Picture.
int16_t(* p_mv_table)[2]
MV table (1MV per MB) p-frame encoding.
int mpeg_quant
0-> h263 quant 1-> mpeg quant
uint8_t * rd_scratchpad
scratchpad for rate distortion mb decision
uint8_t * fcode_tab
smallest fcode needed for each MV
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
#define MV_TYPE_FIELD
2 vectors, one per field
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
uint8_t * mb_mean
Table for MB luminance.
uint64_t error[AV_NUM_DATA_POINTERS]
error
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG1 & B-frame MPEG4
int pre_pass
= 1 for the pre pass
av_cold int ff_MPV_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
#define FF_MPV_FLAG_SKIP_RD
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
#define FF_MPV_GENERIC_CLASS(name)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
void(* shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
float border_masking
Border processing masking, raises the quantizer for mbs on the borders of the picture.
#define CANDIDATE_MB_TYPE_BACKWARD_I
void ff_h263_encode_init(MpegEncContext *s)
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
static void denoise_dct_c(MpegEncContext *s, DCTELEM *block)
void ff_init_qscale_tab(MpegEncContext *s)
init s->current_picture.qscale_table from s->lambda_table
uint16_t * mb_var
Table for MB variances.
static int estimate_qp(MpegEncContext *s, int dry_run)
#define CANDIDATE_MB_TYPE_BIDIR
void ff_MPV_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int dir, uint8_t **ref_picture, op_pixels_func(*pix_op)[4], qpel_mc_func(*qpix_op)[16])
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int16_t(*[3] ac_val)[16]
used for for mpeg4 AC prediction, all 3 arrays must be continuous
void ff_mpeg4_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
int mjpeg_hsample[3]
horizontal sampling factors, default = {2, 1, 1}
#define FF_MPV_COMMON_OPTS
int(* try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale)
#define CANDIDATE_MB_TYPE_INTRA
int msmpeg4_version
0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
void(* rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb)
void ff_get_2pass_fcode(MpegEncContext *s)
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
int obmc
overlapped block motion compensation
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
void ff_mpeg1_clean_buffers(MpegEncContext *s)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define CODEC_FLAG_LOOP_FILTER
int16_t(*[2][2] p_field_mv_table)[2]
MV table (2MV per MB) interlaced p-frame encoding.
static int select_input_picture(MpegEncContext *s)
int min_qcoeff
minimum encodable coefficient
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define CONFIG_MPEG2VIDEO_ENCODER
int ildct_cmp
interlaced DCT comparison function
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
int mpv_flags
flags set by private options
void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number)
int intra_quant_bias
intra quantizer bias
static const AVClass h263_class
uint8_t * intra_ac_vlc_length
int padding_bug_score
used to detect the VERY common padding bug in MPEG4
const uint16_t ff_h263_format[8][2]
#define UNI_AC_ENC_INDEX(run, level)
int mb_num
number of MBs of a picture
int lmax
maximum Lagrange multipler
int frame_skip_cmp
frame skip comparison function
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
static void write_mb_info(MpegEncContext *s)
int time_base
time in seconds of last I,P,S Frame
int h263_aic
Advanded INTRA Coding (AIC)
int16_t(* b_back_mv_table)[2]
MV table (1MV per MB) backward mode b-frame encoding.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
int encoding
true if we are encoding (vs decoding)
uint64_t vbv_delay
VBV delay coded in the last frame (in periods of a 27 MHz clock).
#define CODEC_FLAG_INPUT_PRESERVED
int scenechange_threshold
scene change detection threshold 0 is default, larger means fewer detected scene changes.
int(* pix_sum)(uint8_t *pix, int line_size)
void ff_mpeg4_merge_partitions(MpegEncContext *s)
static int mb_var_thread(AVCodecContext *c, void *arg)
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define FF_BUFFER_TYPE_INTERNAL
#define FF_MPV_FLAG_CBP_RD
int skipdct
skip dct and code zero residual
int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)
void ff_mpeg4_clean_buffers(MpegEncContext *s)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
float p_masking
p block masking (0-> disabled)
int picture_in_gop_number
0-> first pic in gop, ...
int alt_inter_vlc
alternative inter vlc
int64_t time
time of current frame
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, ptrdiff_t linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Copy a rectangular area of samples to a temporary buffer and replicate the border samples...
static int encode_picture(MpegEncContext *s, int picture_number)
#define CONFIG_WMV2_ENCODER
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4) ...
#define CODEC_FLAG2_STRICT_GOP
void ff_convert_matrix(DSPContext *dsp, int(*qmat)[64], uint16_t(*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
Picture ** input_picture
next pictures on display order for encoding
PutBitContext pb2
used for data partitioned VOPs
enum OutputFormat out_format
output format
void(* qpel_mc_func)(uint8_t *dst, uint8_t *src, int stride)
#define CONFIG_MJPEG_ENCODER
uint16_t(* dct_offset)[64]
static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale)
void(* get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size)
#define FF_MB_DECISION_BITS
int pre_dia_size
ME prepass diamond size & shape.
static const AVOption h263p_options[]
static int get_sae(uint8_t *src, int ref, int stride)
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
int misc_bits
cbp, mb_type
uint8_t motion_subsample_log2
log2 of the size of the block which a single vector in motion_val represents: (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
#define CODEC_FLAG_QSCALE
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
#define FF_MB_DECISION_SIMPLE
int me_cmp
motion estimation comparison function
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
Picture current_picture
copy of the current picture structure.
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
static double av_q2d(AVRational a)
Convert rational to double.
int16_t(* b_bidir_forw_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
static void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
const uint16_t ff_aanscales[64]
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
#define CONFIG_RV20_ENCODER
void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
int mb_threshold
Macroblock threshold below which the user specified macroblock types will be used.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
void ff_msmpeg4_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
uint16_t pp_time
time distance between the last 2 p,s,i frames
uint8_t idct_permutation[64]
idct input permutation.
#define CONFIG_H261_ENCODER
const uint8_t * scantable
int flags2
AVCodecContext.flags2.
int interlaced_frame
The content of the picture is interlaced.
int mb_height
number of MBs horizontally & vertically
#define LOCAL_ALIGNED_16(t, v,...)
void ff_MPV_frame_end(MpegEncContext *s)
float lumi_masking
luminance masking (0-> disabled)
int max_qcoeff
maximum encodable coefficient
void ff_h261_encode_init(MpegEncContext *s)
#define FF_MPV_FLAG_QP_RD
av_cold int ff_MPV_encode_end(AVCodecContext *avctx)
int dquant
qscale difference to prev qscale
int num_entries
number of RateControlEntries
int gop_picture_number
index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
static void ff_update_block_index(MpegEncContext *s)
static int init(AVCodecParserContext *s)
qpel_mc_func put_qpel_pixels_tab[2][16]
#define CANDIDATE_MB_TYPE_FORWARD
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
int(* q_inter_matrix)[64]
static int get_bits_diff(MpegEncContext *s)
int(* q_intra_matrix)[64]
precomputed matrix (combine qscale and DCT renorm)
int intra_only
if true, only intra pictures are generated
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
const uint16_t ff_mpeg1_default_intra_matrix[64]
int16_t * dc_val[3]
used for mpeg4 DC prediction, all 3 arrays must be continuous
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
int h263_plus
h263 plus headers
int slice_context_count
number of used thread_contexts
#define CANDIDATE_MB_TYPE_DIRECT
int last_non_b_pict_type
used for mpeg4 gmc b-frames & ratecontrol
int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
int has_b_frames
Size of the frame reordering buffer in the decoder.
static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count)
int last_dc[3]
last DC values for MPEG1
uint8_t * inter_ac_vlc_last_length
Multithreading support functions.
int mb_skipped
MUST BE SET only during DECODING.
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
int strict_std_compliance
strictly follow the std (MPEG4, ...)
int partitioned_frame
is current frame partitioned
qpel_mc_func avg_qpel_pixels_tab[2][16]
int frame_skip_threshold
frame skip threshold
int me_sub_cmp
subpixel motion estimation comparison function
int qmax
maximum quantizer
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
static void update_mb_info(MpegEncContext *s, int startcode)
void ff_write_pass1_stats(MpegEncContext *s)
int unrestricted_mv
mv can point outside of the coded picture
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int last_lambda_for[5]
last lambda for a specific pict type
static int sse_mb(MpegEncContext *s)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
int h263_slice_structured
#define CODEC_FLAG_LOW_DELAY
void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
int rc_max_rate
maximum bitrate
void ff_rate_control_uninit(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_INTER
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int ff_check_alignment(void)
int quarter_sample
1->qpel, 0->half pel ME/MC
uint16_t * mb_type
Table for candidate MB types for encoding.
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Shrink the already allocated side data buffer.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
int low_delay
no reordering needed / has no b-frames
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
#define CONFIG_LJPEG_ENCODER
uint8_t *[2][2] b_field_select_table
int flags
A combination of AV_PKT_FLAG values.
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int resync_mb_x
x position of last resync marker
int rc_buffer_size
decoder bitstream buffer size
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is acually possible in h263 (limit difference to -2..2)
int coded_picture_number
used to set pic->coded_picture_number, should not be used for/by anything else
static void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index)
static int estimate_best_b_count(MpegEncContext *s)
int intra_dc_precision
precision of the intra DC coefficient - 8
int me_penalty_compensation
uint8_t * intra_ac_vlc_last_length
void ff_h263_loop_filter(MpegEncContext *s)
uint32_t ff_squareTbl[512]
int bit_rate
the average bitrate
void ff_mjpeg_encode_picture_header(MpegEncContext *s)
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
int ff_h263_get_gob_height(MpegEncContext *s)
Get the GOB height based on picture height.
int display_picture_number
picture number in display order
uint16_t(* q_inter_matrix16)[2][64]
uint8_t * vbv_delay_ptr
pointer to vbv_delay in the bitstream
int fixed_qscale
fixed qscale if non zero
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is acually possible in mpeg4
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
int me_method
ME algorithm.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int umvplus
== H263+ && unrestricted_mv
Picture new_picture
copy of the source picture structure for encoding.
int intra_quant_bias
bias for the quantizer
void ff_fdct_ifast(DCTELEM *data)
int width
picture width / height.
int type
type of the buffer (to keep track of who has to deallocate data[*])
#define CONFIG_MPEG1VIDEO_ENCODER
Picture * current_picture_ptr
pointer to the current picture
void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64])
void ff_copy_picture(Picture *dst, Picture *src)
float rc_max_available_vbv_use
Ratecontrol attempt to use, at maximum, of what can be used without an underflow. ...
#define CANDIDATE_MB_TYPE_INTER4V
void ff_msmpeg4_encode_init(MpegEncContext *s)
float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
uint16_t(* q_intra_matrix16)[2][64]
identical to the above but for MMX & these are not permutated, second 64 entries are bias ...
static av_always_inline av_const long int lrintf(float x)
void ff_mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int block_last_index[12]
last non zero coefficient in block
void ff_wmv2_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
const int16_t ff_mpeg4_default_non_intra_matrix[64]
int mb_decision
macroblock decision mode
static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride)
uint8_t * mbintra_table
used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function for encode/decode called after coding/decoding the header and before a frame is code...
int ac_esc_length
num of bits needed to encode the longest esc
#define CANDIDATE_MB_TYPE_BACKWARD
#define CANDIDATE_MB_TYPE_SKIPPED
preferred ID for MPEG-1/2 video decoding
#define FF_COMPLIANCE_EXPERIMENTAL
#define CONFIG_MPEG4_ENCODER
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
int block_index[6]
index to current MB in block based arrays with edges
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
int inter_quant_bias
inter quantizer bias
static uint8_t default_fcode_tab[MAX_MV *2+1]
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
int mjpeg_vsample[3]
vertical sampling factors, default = {2, 1, 1}
static void build_basis(uint8_t *perm)
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
void ff_jpeg_fdct_islow_10(DCTELEM *data)
#define MV_TYPE_16X16
1 vector for the whole mb
int frame_skip_factor
frame skip factor
int first_slice_line
used in mpeg4 too to handle resync markers
uint16_t * mc_mb_var
Table for motion compensated MB variances.
void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_faandct(DCTELEM *data)
const uint8_t *const ff_mpeg2_dc_scale_table[4]
int coded_picture_number
picture number in bitstream order
uint16_t inter_matrix[64]
uint64_t error[AV_NUM_DATA_POINTERS]
error
int(* fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)
struct MpegEncContext * thread_context[MAX_THREADS]
#define CONFIG_MSMPEG4_ENCODER
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
double buffer_index
amount of bits in the video/audio buffer
int me_threshold
Motion estimation threshold below which no motion estimation is performed, but instead the user speci...
void ff_h263_update_motion_val(MpegEncContext *s)
int h263_flv
use flv h263 header
static const AVClass h263p_class
static av_const unsigned int ff_sqrt(unsigned int a)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
int idct_permutation_type
void(* denoise_dct)(struct MpegEncContext *s, DCTELEM *block)
const uint16_t ff_inv_aanscales[64]
int frame_bits
number of bits used for the previously encoded frame
void ff_mjpeg_encode_close(MpegEncContext *s)
main external API structure.
#define CONFIG_H263_ENCODER
void ff_MPV_encode_init_x86(MpegEncContext *s)
static void close(AVCodecParserContext *s)
void ff_h261_reorder_mb_index(MpegEncContext *s)
ScanTable intra_scantable
int pre_me
prepass for motion estimation
int qmin
minimum quantizer
int height
picture size. must be a multiple of 16
void(* diff_pixels)(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
void ff_mjpeg_encode_stuffing(PutBitContext *pbc)
static void write_slice_end(MpegEncContext *s)
int64_t dts_delta
pts difference between the first and second input frame, used for calculating dts of the first frame ...
void ff_mjpeg_encode_picture_trailer(MpegEncContext *s)
#define CODEC_FLAG2_SKIP_RD
int16_t(*[2] motion_val)[2]
motion vector table
int64_t user_specified_pts
last non zero pts from AVFrame which was passed into avcodec_encode_video()
int ff_h261_get_picture_format(int width, int height)
float spatial_cplx_masking
spatial complexity masking (0-> disabled)
void ff_fix_long_p_mvs(MpegEncContext *s)
Picture * picture
main picture buffer
int data_partitioning
data partitioning flag from header
uint8_t * inter_ac_vlc_length
uint16_t * intra_matrix
custom intra quantization matrix
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src)
Describe the class of an AVClass context structure.
int16_t(*[2][2][2] b_field_mv_table)[2]
MV table (4MV per MB) interlaced b-frame encoding.
#define FF_ARRAY_ELEMS(a)
static void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type)
#define ROUNDED_DIV(a, b)
int input_picture_number
used to set pic->display_picture_number, should not be used for/by anything else
void(* add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale)
int mb_info
interval for outputting info about mb offsets as side data
static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
void ff_set_mpeg4_time(MpegEncContext *s)
static void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type)
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
DSPContext dsp
pointers for accelerated dsp functions
int(* pix_norm1)(uint8_t *pix, int line_size)
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int frame_skip_exp
frame skip exponent
av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
const int16_t ff_mpeg4_default_intra_matrix[64]
int f_code
forward MV resolution
int ff_pre_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
#define CANDIDATE_MB_TYPE_BIDIR_I
static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
#define FF_BUFFER_TYPE_USER
uint16_t * inter_matrix
custom inter quantization matrix
int max_b_frames
max number of b-frames for encoding
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
#define CODEC_CAP_SLICE_THREADS
int bit_rate
wanted bit rate
DCTELEM(* block)[64]
points to one of the following blocks
static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
int last_mv_dir
last mv_dir, used for b frame encoding
#define CANDIDATE_MB_TYPE_FORWARD_I
int h263_pred
use mpeg4/h263 ac/dc predictions
int16_t(* b_bidir_back_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
float dark_masking
darkness masking (0-> disabled)
float temporal_cplx_masking
temporary complexity masking (0-> disabled)
int ff_init_me(MpegEncContext *s)
uint8_t *[2] p_field_select_table
int16_t(* b_direct_mv_table)[2]
MV table (1MV per MB) direct mode b-frame encoding.
static const uint16_t scale[4]
AAN (Arai Agui Nakajima) (I)DCT tables.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define FF_COMPLIANCE_UNOFFICIAL
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
int8_t * qscale_table
QP table.
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int16_t(* b_forw_mv_table)[2]
MV table (1MV per MB) forward mode b-frame encoding.
int noise_reduction
noise reduction strength
static int estimate_motion_thread(AVCodecContext *c, void *arg)
void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block.
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
PutBitContext pb
bit output
static int skip_check(MpegEncContext *s, Picture *p, Picture *ref)
static void update_qscale(MpegEncContext *s)
int mb_cmp
macroblock comparison function (not supported yet)
int quantizer_noise_shaping
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int pre_estimate_motion_thread(AVCodecContext *c, void *arg)
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
void ff_MPV_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding). ...
void ff_jpeg_fdct_islow_8(DCTELEM *data)
const uint8_t ff_h263_chroma_qscale_table[32]
void(* fdct)(DCTELEM *block)
int adaptive_quant
use adaptive quantization
static int16_t basis[64][64]
void ff_msmpeg4_encode_ext_header(MpegEncContext *s)
static int score_tab[256]
#define CODEC_FLAG_AC_PRED
Picture last_picture
copy of the previous picture structure.
int ff_rate_control_init(MpegEncContext *s)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
int64_t reordered_pts
reordered pts to be used as dts for the next output frame when there's a delay
int ff_vbv_update(MpegEncContext *s, int frame_size)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define CONFIG_H263P_ENCODER
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
const uint8_t * chroma_qscale_table
qscale -> chroma_qscale (h263)
AVCodec ff_msmpeg4v3_encoder
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
int trellis
trellis RD quantization
#define CANDIDATE_MB_TYPE_DIRECT0
void ff_mpeg4_stuffing(PutBitContext *pbc)
add mpeg4 stuffing bits (01...1)
const AVOption ff_mpv_generic_options[]
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
void ff_h261_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
#define CONFIG_FLV_ENCODER
int last_bits
temp var used for calculating the above vars
void ff_mpeg4_init_partitions(MpegEncContext *s)
int dia_size
ME diamond size & shape.
int b_sensitivity
Adjust sensitivity of b_frame_strategy 1.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
int top_field_first
If the content is interlaced, is top field displayed first.
static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src)
void ff_MPV_common_end(MpegEncContext *s)
int error_rate
Simulates errors in the bitstream to test error concealment.
int ff_get_best_fcode(MpegEncContext *s, int16_t(*mv_table)[2], int type)
int resync_mb_y
y position of last resync marker
void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number)
PutBitContext tex_pb
used for data partitioned VOPs
Picture next_picture
copy of the next picture structure.
int key_frame
1 -> keyframe, 0-> not
static void set_frame_distances(MpegEncContext *s)
int linesize
line size, in bytes, may be different from width
void ff_fix_long_mvs(MpegEncContext *s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)
Picture ** reordered_input_picture
pointer to the next pictures in codedorder for encoding
static const struct twinvq_data tab
void ff_mpeg1_encode_init(MpegEncContext *s)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int mb_var_sum
sum of MB variance for current frame
static int encode_thread(AVCodecContext *c, void *arg)
int flags
AVCodecContext.flags (HQ, MV4, ...)
int mc_mb_var_sum
motion compensated MB variance for current frame
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src)
#define FF_BUFFER_TYPE_SHARED
qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]
int inter_quant_bias
bias for the quantizer
#define FF_DEFAULT_QUANT_BIAS
int me_method
Motion estimation algorithm used for video coding.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
int ff_find_unused_picture(MpegEncContext *s, int shared)
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
int rc_min_rate
minimum bitrate
int b_code
backward MV resolution for B Frames (mpeg4)
static void MPV_encode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for encoding.
static int encode_frame(AVCodecContext *c, AVFrame *frame)
int uvlinesize
line size, for chroma in bytes, may be different from width
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define FF_MB_DECISION_RD
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define CONFIG_RV10_ENCODER
#define CANDIDATE_MB_TYPE_INTER_I
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
static void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], int *dmin, int *next_block, int motion_x, int motion_y)
unsigned int lambda
lagrange multipler used in rate distortion
AVCodec ff_msmpeg4v2_encoder
uint16_t pb_time
time distance between the last b and p,s,i frame
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)
int next_lambda
next lambda used for retrying to encode a frame