Go to the documentation of this file.
34 #include "config_components.h"
82 #define QUANT_BIAS_SHIFT 8
84 #define QMAT_SHIFT_MMX 16
92 int16_t *
block,
int n,
112 uint16_t (*
qmat16)[2][64],
113 const uint16_t *quant_matrix,
114 int bias,
int qmin,
int qmax,
int intra)
125 else qscale2 =
qscale << 1;
132 for (
i = 0;
i < 64;
i++) {
133 const int j =
s->idsp.idct_permutation[
i];
144 for (
i = 0;
i < 64;
i++) {
145 const int j =
s->idsp.idct_permutation[
i];
156 for (
i = 0;
i < 64;
i++) {
157 const int j =
s->idsp.idct_permutation[
i];
181 for (
i = intra;
i < 64;
i++) {
193 "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
200 if (
s->q_scale_type == 1 && 0) {
202 int bestdiff=INT_MAX;
210 if (
diff < bestdiff) {
219 s->qscale =
av_clip(
s->qscale,
s->avctx->qmin,
s->vbv_ignore_qmax ? 31 :
s->avctx->qmax);
232 for (
i = 0;
i < 64;
i++) {
244 int8_t *
const qscale_table =
s->cur_pic.qscale_table;
247 for (
i = 0;
i <
s->mb_num;
i++) {
248 unsigned int lam =
s->lambda_table[
s->mb_index2xy[
i]];
250 qscale_table[
s->mb_index2xy[
i]] =
av_clip(qp,
s->avctx->qmin,
258 #define COPY(a) dst->a= src->a
273 for (
int i = -16;
i < 16;
i++)
291 s->input_picture_number = 0;
292 s->picture_in_gop_number = 0;
306 if (
s->avctx->trellis)
323 s->frame_skip_cmp_fn = me_cmp[1];
328 if (!me_cmp[0] || !me_cmp[4])
330 s->ildct_cmp[0] = me_cmp[0];
331 s->ildct_cmp[1] = me_cmp[4];
336 s->sse_cmp[0] = mecc.
sse[0];
337 s->sse_cmp[1] = mecc.
sse[1];
338 s->sad_cmp[0] = mecc.
sad[0];
339 s->sad_cmp[1] = mecc.
sad[1];
341 s->n_sse_cmp[0] = mecc.
nsse[0];
342 s->n_sse_cmp[1] = mecc.
nsse[1];
344 s->n_sse_cmp[0] = mecc.
sse[0];
345 s->n_sse_cmp[1] = mecc.
sse[1];
351 #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p))))
354 const int nb_matrices = 1 + (
s->out_format ==
FMT_MJPEG) + !
s->intra_only;
363 s->q_chroma_intra_matrix =
s->q_intra_matrix + 32;
364 s->q_chroma_intra_matrix16 =
s->q_intra_matrix16 + 32;
370 s->q_chroma_intra_matrix =
s->q_intra_matrix;
371 s->q_chroma_intra_matrix16 =
s->q_intra_matrix16;
373 if (!
s->intra_only) {
374 s->q_inter_matrix =
s->q_intra_matrix + 32;
375 s->q_inter_matrix16 =
s->q_intra_matrix16 + 32;
396 for (
int i = 0;
i < 64;
i++) {
397 int j =
s->idsp.idct_permutation[
i];
411 if (
s->q_inter_matrix)
425 int mb_array_size, mv_table_size;
453 "keyframe interval too large!, reducing it from %d to %d\n",
465 "max b frames must be 0 or positive for mpegvideo based encoders\n");
476 s->rtp_mode = !!
s->rtp_payload_size;
480 if (
s->intra_dc_precision < 0) {
481 s->intra_dc_precision += 8;
482 }
else if (
s->intra_dc_precision >= 8)
483 s->intra_dc_precision -= 8;
485 if (
s->intra_dc_precision < 0) {
487 "intra dc precision must be positive, note some applications use"
488 " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n");
498 if (
s->gop_size <= 1) {
552 "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
569 "impossible bitrate constraints, this will fail\n");
579 if (!
s->fixed_qscale &&
585 if (nbt <= INT_MAX) {
600 "OBMC is only supported with simple mb decision\n");
615 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
674 if (
s->scenechange_threshold < 1000000000 &&
677 "closed gop with scene change detection are not supported yet, "
678 "set threshold to 1000000000\n");
686 "low delay forcing is only available for mpeg2, "
687 "set strict_std_compliance to 'unofficial' or lower in order to allow it\n");
690 if (
s->max_b_frames != 0) {
692 "B-frames cannot be used with low delay\n");
705 "notice: b_frame_strategy only affects the first pass\n");
706 s->b_frame_strategy = 0;
720 s->inter_quant_bias = 0;
722 s->intra_quant_bias = 0;
737 "timebase %d/%d not supported by MPEG 4 standard, "
738 "the maximum admitted value for the timebase denominator "
746 #if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
753 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
757 #if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
771 if (!CONFIG_SPEEDHQ_ENCODER)
779 if (!CONFIG_H261_ENCODER)
790 if (!CONFIG_H263_ENCODER)
793 s->width,
s->height) == 8) {
795 "The specified picture size of %dx%d is not valid for "
796 "the H.263 codec.\nValid sizes are 128x96, 176x144, "
797 "352x288, 704x576, and 1408x1152. "
798 "Try H.263+.\n",
s->width,
s->height);
810 s->modified_quant =
s->h263_aic;
812 s->unrestricted_mv =
s->obmc ||
s->loop_filter ||
s->umvplus;
813 s->flipflop_rounding = 1;
823 s->unrestricted_mv = 1;
837 s->modified_quant = 1;
841 s->unrestricted_mv = 0;
846 s->unrestricted_mv = 1;
847 s->flipflop_rounding = 1;
848 s->low_delay =
s->max_b_frames ? 0 : 1;
849 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
854 s->unrestricted_mv = 1;
862 s->unrestricted_mv = 1;
864 s->flipflop_rounding = 1;
871 s->unrestricted_mv = 1;
873 s->flipflop_rounding = 1;
880 s->unrestricted_mv = 1;
882 s->flipflop_rounding = 1;
894 s->progressive_frame =
899 if (
s->lmin >
s->lmax) {
929 mv_table_size = (
s->mb_height + 2) *
s->mb_stride + 1;
937 s->p_mv_table =
s->p_mv_table_base +
s->mb_stride + 1;
938 s->b_forw_mv_table =
s->b_forw_mv_table_base +
s->mb_stride + 1;
939 s->b_back_mv_table =
s->b_back_mv_table_base +
s->mb_stride + 1;
940 s->b_bidir_forw_mv_table =
s->b_bidir_forw_mv_table_base +
s->mb_stride + 1;
941 s->b_bidir_back_mv_table =
s->b_bidir_back_mv_table_base +
s->mb_stride + 1;
942 s->b_direct_mv_table =
s->b_direct_mv_table_base +
s->mb_stride + 1;
945 mb_array_size =
s->mb_stride *
s->mb_height;
957 if (!(tmp1 =
ALLOCZ_ARRAYS(
s->b_field_mv_table_base, 8, mv_table_size)) ||
958 !(tmp2 =
ALLOCZ_ARRAYS(
s->b_field_select_table[0][0], 2 * 4, mv_table_size)) ||
962 s->p_field_select_table[1] =
s->p_field_select_table[0] + 2 * mv_table_size;
963 tmp1 +=
s->mb_stride + 1;
965 for (
int i = 0;
i < 2;
i++) {
966 for (
int j = 0; j < 2; j++) {
967 for (
int k = 0; k < 2; k++) {
968 s->b_field_mv_table[
i][j][k] = tmp1;
969 tmp1 += mv_table_size;
971 s->b_field_select_table[
i][j] = tmp2;
972 tmp2 += 2 * mv_table_size;
977 if (
s->noise_reduction) {
985 s->dct_unquantize_intra =
s->dct_unquantize_mpeg2_intra;
986 s->dct_unquantize_inter =
s->dct_unquantize_mpeg2_inter;
988 s->dct_unquantize_intra =
s->dct_unquantize_h263_intra;
989 s->dct_unquantize_inter =
s->dct_unquantize_h263_inter;
991 s->dct_unquantize_intra =
s->dct_unquantize_mpeg1_intra;
992 s->dct_unquantize_inter =
s->dct_unquantize_mpeg1_inter;
995 if (
s->slice_context_count > 1) {
999 s->h263_slice_structured = 1;
1002 if (CONFIG_H263_ENCODER &&
s->out_format ==
FMT_H263) {
1004 #if CONFIG_MSMPEG4ENC
1013 if (
s->b_frame_strategy == 2) {
1014 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1016 if (!
s->tmp_frames[
i])
1020 s->tmp_frames[
i]->width =
s->width >>
s->brd_scale;
1021 s->tmp_frames[
i]->height =
s->height >>
s->brd_scale;
1050 if (
s->input_picture &&
s->reordered_input_picture) {
1066 av_freep(&
s->b_bidir_forw_mv_table_base);
1067 av_freep(&
s->b_bidir_back_mv_table_base);
1070 av_freep(&
s->b_field_select_table[0][0]);
1099 if (
s->block_last_index[
i] >= 0) {
1114 for (
int i = 0;
i < 6;
i++) {
1115 for (
int j = 0; j < 64; j++) {
1117 block[
i][
s->idsp.idct_permutation[j]]);
1126 uint8_t *dest_y =
s->dest[0], *dest_cb =
s->dest[1], *dest_cr =
s->dest[2];
1128 const int linesize =
s->cur_pic.linesize[0];
1130 const int block_size = 8;
1132 dct_linesize =
linesize <<
s->interlaced_dct;
1143 if (
s->chroma_y_shift) {
1158 put_dct(
s,
block[1], 1, dest_y + block_size, dct_linesize,
s->qscale);
1163 if (
s->chroma_y_shift) {
1169 put_dct(
s,
block[4], 4, dest_cb, dct_linesize,
s->chroma_qscale);
1170 put_dct(
s,
block[5], 5, dest_cr, dct_linesize,
s->chroma_qscale);
1184 for (y = 0; y < 16; y++) {
1185 for (x = 0; x < 16; x++) {
1200 h =
s->height & ~15;
1202 for (y = 0; y <
h; y += 16) {
1203 for (x = 0; x <
w; x += 16) {
1210 acc += sae + 500 < sad;
1236 for (
int i = 0;
f->data[
i];
i++) {
1256 int display_picture_number = 0,
ret;
1257 int encoding_delay =
s->max_b_frames ?
s->max_b_frames
1258 : (
s->low_delay ? 0 : 1);
1259 int flush_offset = 1;
1266 display_picture_number =
s->input_picture_number++;
1270 int64_t last =
s->user_specified_pts;
1274 "Invalid pts (%"PRId64
") <= last (%"PRId64
")\n",
1279 if (!
s->low_delay && display_picture_number == 1)
1280 s->dts_delta =
pts - last;
1282 s->user_specified_pts =
pts;
1285 s->user_specified_pts =
1286 pts =
s->user_specified_pts + 1;
1288 "Warning: AVFrame.pts=? trying to guess (%"PRId64
")\n",
1291 pts = display_picture_number;
1295 if (pic_arg->
linesize[0] !=
s->linesize ||
1296 pic_arg->
linesize[1] !=
s->uvlinesize ||
1299 if ((
s->width & 15) || (
s->height & 15))
1307 pic_arg->
linesize[1],
s->linesize,
s->uvlinesize);
1322 for (
int i = 0;
i < 3;
i++) {
1323 ptrdiff_t src_stride = pic_arg->
linesize[
i];
1324 ptrdiff_t dst_stride =
i ?
s->uvlinesize :
s->linesize;
1325 int h_shift =
i ?
s->chroma_x_shift : 0;
1326 int v_shift =
i ?
s->chroma_y_shift : 0;
1329 const uint8_t *
src = pic_arg->
data[
i];
1334 && !
s->progressive_sequence
1335 &&
FFALIGN(
s->height, 32) -
s->height > 16)
1338 if (!
s->avctx->rc_buffer_size)
1341 if (src_stride == dst_stride)
1342 memcpy(
dst,
src, src_stride *
h - src_stride +
w);
1345 uint8_t *dst2 =
dst;
1347 memcpy(dst2,
src,
w);
1352 if ((
s->width & 15) || (
s->height & (vpad-1))) {
1353 s->mpvencdsp.draw_edges(
dst, dst_stride,
1365 }
else if (!
s->reordered_input_picture[1]) {
1371 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)
1372 if (
s->input_picture[flush_offset])
1375 encoding_delay -= flush_offset - 1;
1380 s->input_picture[
i - flush_offset] =
s->input_picture[
i];
1382 s->input_picture[
i] =
NULL;
1384 s->input_picture[encoding_delay] = pic;
1398 for (plane = 0; plane < 3; plane++) {
1400 const int bw = plane ? 1 : 2;
1401 for (y = 0; y <
s->mb_height * bw; y++) {
1402 for (x = 0; x <
s->mb_width * bw; x++) {
1403 int off = p->
shared ? 0 : 16;
1404 const uint8_t *dptr = p->
f->
data[plane] + 8 * (x + y *
stride) + off;
1405 const uint8_t *rptr =
ref->f->data[plane] + 8 * (x + y *
stride);
1406 int v =
s->frame_skip_cmp_fn(
s, dptr, rptr,
stride, 8);
1408 switch (
FFABS(
s->frame_skip_exp)) {
1409 case 0: score =
FFMAX(score, v);
break;
1410 case 1: score +=
FFABS(v);
break;
1411 case 2: score64 += v * (
int64_t)v;
break;
1422 if (
s->frame_skip_exp < 0)
1423 score64 = pow(score64 / (
double)(
s->mb_width *
s->mb_height),
1424 -1.0/
s->frame_skip_exp);
1428 if (score64 < ((
s->frame_skip_factor * (
int64_t)
s->lambda) >> 8))
1457 const int scale =
s->brd_scale;
1462 int best_b_count = -1;
1476 b_lambda = p_lambda;
1480 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1481 const MPVPicture *pre_input_ptr =
i ?
s->input_picture[
i - 1] :
1484 if (pre_input_ptr) {
1485 const uint8_t *
data[4];
1488 if (!pre_input_ptr->
shared &&
i) {
1494 s->mpvencdsp.shrink[
scale](
s->tmp_frames[
i]->data[0],
1495 s->tmp_frames[
i]->linesize[0],
1499 s->mpvencdsp.shrink[
scale](
s->tmp_frames[
i]->data[1],
1500 s->tmp_frames[
i]->linesize[1],
1504 s->mpvencdsp.shrink[
scale](
s->tmp_frames[
i]->data[2],
1505 s->tmp_frames[
i]->linesize[2],
1512 for (j = 0; j <
s->max_b_frames + 1; j++) {
1516 if (!
s->input_picture[j])
1529 c->mb_decision =
s->avctx->mb_decision;
1530 c->me_cmp =
s->avctx->me_cmp;
1531 c->mb_cmp =
s->avctx->mb_cmp;
1532 c->me_sub_cmp =
s->avctx->me_sub_cmp;
1534 c->time_base =
s->avctx->time_base;
1535 c->max_b_frames =
s->max_b_frames;
1553 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1554 int is_p =
i % (j + 1) == j ||
i ==
s->max_b_frames;
1556 s->tmp_frames[
i + 1]->pict_type = is_p ?
1558 s->tmp_frames[
i + 1]->quality = is_p ? p_lambda : b_lambda;
1577 rd +=
c->error[0] +
c->error[1] +
c->error[2];
1595 return best_b_count;
1609 if (
s->reordered_input_picture[0] || !
s->input_picture[0])
1613 if (
s->frame_skip_threshold ||
s->frame_skip_factor) {
1614 if (
s->picture_in_gop_number <
s->gop_size &&
1627 !
s->next_pic.ptr ||
s->intra_only) {
1628 s->reordered_input_picture[0] =
s->input_picture[0];
1629 s->input_picture[0] =
NULL;
1631 s->reordered_input_picture[0]->coded_picture_number =
1632 s->coded_picture_number++;
1637 for (
int i = 0;
i <
s->max_b_frames + 1;
i++) {
1638 int pict_num =
s->input_picture[0]->display_picture_number +
i;
1640 if (pict_num >=
s->rc_context.num_entries)
1642 if (!
s->input_picture[
i]) {
1647 s->input_picture[
i]->f->pict_type =
1648 s->rc_context.entry[pict_num].new_pict_type;
1652 if (
s->b_frame_strategy == 0) {
1653 b_frames =
s->max_b_frames;
1654 while (b_frames && !
s->input_picture[b_frames])
1656 }
else if (
s->b_frame_strategy == 1) {
1658 for (
i = 1;
i <
s->max_b_frames + 1;
i++) {
1659 if (
s->input_picture[
i] &&
1660 s->input_picture[
i]->b_frame_score == 0) {
1661 s->input_picture[
i]->b_frame_score =
1663 s->input_picture[
i ]->f->data[0],
1664 s->input_picture[
i - 1]->f->data[0],
1668 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1669 if (!
s->input_picture[
i] ||
1670 s->input_picture[
i]->b_frame_score - 1 >
1671 s->mb_num /
s->b_sensitivity)
1675 b_frames =
FFMAX(0,
i - 1);
1678 for (
i = 0;
i < b_frames + 1;
i++) {
1679 s->input_picture[
i]->b_frame_score = 0;
1681 }
else if (
s->b_frame_strategy == 2) {
1691 for (
int i = b_frames - 1;
i >= 0;
i--) {
1692 int type =
s->input_picture[
i]->f->pict_type;
1697 b_frames ==
s->max_b_frames) {
1699 "warning, too many B-frames in a row\n");
1702 if (
s->picture_in_gop_number + b_frames >=
s->gop_size) {
1704 s->gop_size >
s->picture_in_gop_number) {
1705 b_frames =
s->gop_size -
s->picture_in_gop_number - 1;
1717 s->reordered_input_picture[0] =
s->input_picture[b_frames];
1718 s->input_picture[b_frames] =
NULL;
1721 s->reordered_input_picture[0]->coded_picture_number =
1722 s->coded_picture_number++;
1723 for (
int i = 0;
i < b_frames;
i++) {
1724 s->reordered_input_picture[
i + 1] =
s->input_picture[
i];
1725 s->input_picture[
i] =
NULL;
1726 s->reordered_input_picture[
i + 1]->f->pict_type =
1728 s->reordered_input_picture[
i + 1]->coded_picture_number =
1729 s->coded_picture_number++;
1743 s->reordered_input_picture[
i - 1] =
s->reordered_input_picture[
i];
1753 if (
s->reordered_input_picture[0]) {
1754 s->reordered_input_picture[0]->reference =
1757 if (
s->reordered_input_picture[0]->shared ||
s->avctx->rc_buffer_size) {
1771 if (
s->new_pic->data[
i])
1775 s->cur_pic.ptr =
s->reordered_input_picture[0];
1776 s->reordered_input_picture[0] =
NULL;
1777 av_assert1(
s->mb_width ==
s->buffer_pools.alloc_mb_width);
1778 av_assert1(
s->mb_height ==
s->buffer_pools.alloc_mb_height);
1779 av_assert1(
s->mb_stride ==
s->buffer_pools.alloc_mb_stride);
1781 &
s->sc, &
s->buffer_pools,
s->mb_height);
1786 s->picture_number =
s->cur_pic.ptr->display_picture_number;
1797 if (
s->unrestricted_mv &&
1798 s->cur_pic.reference &&
1800 int hshift =
s->chroma_x_shift;
1801 int vshift =
s->chroma_y_shift;
1802 s->mpvencdsp.draw_edges(
s->cur_pic.data[0],
1803 s->cur_pic.linesize[0],
1804 s->h_edge_pos,
s->v_edge_pos,
1807 s->mpvencdsp.draw_edges(
s->cur_pic.data[1],
1808 s->cur_pic.linesize[1],
1809 s->h_edge_pos >> hshift,
1814 s->mpvencdsp.draw_edges(
s->cur_pic.data[2],
1815 s->cur_pic.linesize[2],
1816 s->h_edge_pos >> hshift,
1825 s->last_pict_type =
s->pict_type;
1826 s->last_lambda_for [
s->pict_type] =
s->cur_pic.ptr->f->quality;
1828 s->last_non_b_pict_type =
s->pict_type;
1835 for (intra = 0; intra < 2; intra++) {
1836 if (
s->dct_count[intra] > (1 << 16)) {
1837 for (
i = 0;
i < 64;
i++) {
1838 s->dct_error_sum[intra][
i] >>= 1;
1840 s->dct_count[intra] >>= 1;
1843 for (
i = 0;
i < 64;
i++) {
1844 s->dct_offset[intra][
i] = (
s->noise_reduction *
1845 s->dct_count[intra] +
1846 s->dct_error_sum[intra][
i] / 2) /
1847 (
s->dct_error_sum[intra][
i] + 1);
1854 s->cur_pic.ptr->f->pict_type =
s->pict_type;
1861 if (
s->dct_error_sum) {
1868 const AVFrame *pic_arg,
int *got_packet)
1871 int stuffing_count,
ret;
1872 int context_count =
s->slice_context_count;
1876 s->vbv_ignore_qmax = 0;
1878 s->picture_in_gop_number++;
1888 if (
s->new_pic->data[0]) {
1889 int growing_buffer = context_count == 1 && !
s->data_partitioning;
1890 size_t pkt_size = 10000 +
s->mb_width *
s->mb_height *
1903 s->mb_width*
s->mb_height*12);
1904 if (!
s->mb_info_ptr)
1906 s->prev_mb_info =
s->last_mb_info =
s->mb_info_size = 0;
1909 s->pict_type =
s->new_pic->pict_type;
1914 if (growing_buffer) {
1924 if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) &&
s->out_format ==
FMT_MJPEG)
1934 s->lambda <
s->lmax) {
1935 s->next_lambda =
FFMAX(
s->lambda + min_step,
s->lambda *
1936 (
s->qscale + 1) /
s->qscale);
1937 if (
s->adaptive_quant) {
1939 for (
i = 0;
i <
s->mb_height *
s->mb_stride;
i++)
1940 s->lambda_table[
i] =
1941 FFMAX(
s->lambda_table[
i] + min_step,
1942 s->lambda_table[
i] * (
s->qscale + 1) /
1948 s->no_rounding ^=
s->flipflop_rounding;
1951 s->time_base =
s->last_time_base;
1952 s->last_non_b_time =
s->time -
s->pp_time;
1954 s->vbv_ignore_qmax = 1;
1974 s->misc_bits +
s->i_tex_bits +
1980 s->stuffing_bits = 8*stuffing_count;
1981 if (stuffing_count) {
1987 switch (
s->codec_id) {
1990 while (stuffing_count--) {
1997 stuffing_count -= 4;
1998 while (stuffing_count--) {
2004 s->stuffing_bits = 0;
2019 int vbv_delay, min_delay;
2022 int minbits =
s->frame_bits - 8 *
2023 (
s->vbv_delay_pos - 1);
2024 double bits =
s->rc_context.buffer_index + minbits - inbits;
2025 uint8_t *
const vbv_delay_ptr =
s->pb.buf +
s->vbv_delay_pos;
2029 "Internal error, negative bits\n");
2037 vbv_delay =
FFMAX(vbv_delay, min_delay);
2041 vbv_delay_ptr[0] &= 0xF8;
2042 vbv_delay_ptr[0] |= vbv_delay >> 13;
2043 vbv_delay_ptr[1] = vbv_delay >> 5;
2044 vbv_delay_ptr[2] &= 0x07;
2045 vbv_delay_ptr[2] |= vbv_delay << 3;
2053 (uint8_t*)props, props_size);
2059 s->total_bits +=
s->frame_bits;
2061 pkt->
pts =
s->cur_pic.ptr->f->pts;
2064 if (!
s->cur_pic.ptr->coded_picture_number)
2097 int n,
int threshold)
2099 static const char tab[64] = {
2100 3, 2, 2, 1, 1, 1, 1, 1,
2101 1, 1, 1, 1, 1, 1, 1, 1,
2102 1, 1, 1, 1, 1, 1, 1, 1,
2103 0, 0, 0, 0, 0, 0, 0, 0,
2104 0, 0, 0, 0, 0, 0, 0, 0,
2105 0, 0, 0, 0, 0, 0, 0, 0,
2106 0, 0, 0, 0, 0, 0, 0, 0,
2107 0, 0, 0, 0, 0, 0, 0, 0
2112 int16_t *
block =
s->block[n];
2113 const int last_index =
s->block_last_index[n];
2116 if (threshold < 0) {
2118 threshold = -threshold;
2123 if (last_index <= skip_dc - 1)
2126 for (
i = 0;
i <= last_index;
i++) {
2127 const int j =
s->intra_scantable.permutated[
i];
2130 if (skip_dc &&
i == 0)
2134 }
else if (
level > 1) {
2140 if (score >= threshold)
2142 for (
i = skip_dc;
i <= last_index;
i++) {
2143 const int j =
s->intra_scantable.permutated[
i];
2147 s->block_last_index[n] = 0;
2149 s->block_last_index[n] = -1;
2156 const int maxlevel =
s->max_qcoeff;
2157 const int minlevel =
s->min_qcoeff;
2165 for (;
i <= last_index;
i++) {
2166 const int j =
s->intra_scantable.permutated[
i];
2169 if (
level > maxlevel) {
2172 }
else if (
level < minlevel) {
2182 "warning, clipping %d dct coefficients to %d..%d\n",
2190 for (y = 0; y < 8; y++) {
2191 for (x = 0; x < 8; x++) {
2197 for (y2 =
FFMAX(y - 1, 0); y2 <
FFMIN(8, y + 2); y2++) {
2198 for (x2=
FFMAX(x - 1, 0); x2 <
FFMIN(8, x + 2); x2++) {
2199 int v = ptr[x2 + y2 *
stride];
2211 int motion_x,
int motion_y,
2212 int mb_block_height,
2221 #define INTERLACED_DCT(s) ((chroma_format == CHROMA_420 || chroma_format == CHROMA_422) && \
2222 (s)->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
2224 int16_t orig[12][64];
2225 const int mb_x =
s->mb_x;
2226 const int mb_y =
s->mb_y;
2230 int uv_dct_offset =
s->uvlinesize * 8;
2231 const uint8_t *ptr_y, *ptr_cb, *ptr_cr;
2232 ptrdiff_t wrap_y, wrap_c;
2234 for (
i = 0;
i < mb_block_count;
i++)
2235 skip_dct[
i] =
s->skipdct;
2237 if (
s->adaptive_quant) {
2238 const int last_qp =
s->qscale;
2239 const int mb_xy =
mb_x +
mb_y *
s->mb_stride;
2241 s->lambda =
s->lambda_table[mb_xy];
2246 s->dquant =
s->cur_pic.qscale_table[mb_xy] - last_qp;
2267 wrap_y =
s->linesize;
2268 wrap_c =
s->uvlinesize;
2269 ptr_y =
s->new_pic->data[0] +
2271 ptr_cb =
s->new_pic->data[1] +
2272 (
mb_y * mb_block_height * wrap_c) +
mb_x * mb_block_width;
2273 ptr_cr =
s->new_pic->data[2] +
2274 (
mb_y * mb_block_height * wrap_c) +
mb_x * mb_block_width;
2277 uint8_t *ebuf =
s->sc.edge_emu_buffer + 38 * wrap_y;
2280 s->vdsp.emulated_edge_mc(ebuf, ptr_y,
2283 s->width,
s->height);
2285 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y, ptr_cb,
2287 mb_block_width, mb_block_height,
2288 mb_x * mb_block_width,
mb_y * mb_block_height,
2290 ptr_cb = ebuf + 16 * wrap_y;
2291 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y + 16, ptr_cr,
2293 mb_block_width, mb_block_height,
2294 mb_x * mb_block_width,
mb_y * mb_block_height,
2296 ptr_cr = ebuf + 16 * wrap_y + 16;
2301 int progressive_score, interlaced_score;
2303 s->interlaced_dct = 0;
2304 progressive_score =
s->ildct_cmp[1](
s, ptr_y,
NULL, wrap_y, 8) +
2305 s->ildct_cmp[1](
s, ptr_y + wrap_y * 8,
2306 NULL, wrap_y, 8) - 400;
2308 if (progressive_score > 0) {
2309 interlaced_score =
s->ildct_cmp[1](
s, ptr_y,
2310 NULL, wrap_y * 2, 8) +
2311 s->ildct_cmp[1](
s, ptr_y + wrap_y,
2312 NULL, wrap_y * 2, 8);
2313 if (progressive_score > interlaced_score) {
2314 s->interlaced_dct = 1;
2317 uv_dct_offset = wrap_c;
2326 s->pdsp.get_pixels(
s->block[0], ptr_y, wrap_y);
2327 s->pdsp.get_pixels(
s->block[1], ptr_y + 8, wrap_y);
2328 s->pdsp.get_pixels(
s->block[2], ptr_y +
dct_offset, wrap_y);
2329 s->pdsp.get_pixels(
s->block[3], ptr_y +
dct_offset + 8, wrap_y);
2335 s->pdsp.get_pixels(
s->block[4], ptr_cb, wrap_c);
2336 s->pdsp.get_pixels(
s->block[5], ptr_cr, wrap_c);
2338 s->pdsp.get_pixels(
s->block[6], ptr_cb + uv_dct_offset, wrap_c);
2339 s->pdsp.get_pixels(
s->block[7], ptr_cr + uv_dct_offset, wrap_c);
2341 s->pdsp.get_pixels(
s->block[ 6], ptr_cb + 8, wrap_c);
2342 s->pdsp.get_pixels(
s->block[ 7], ptr_cr + 8, wrap_c);
2343 s->pdsp.get_pixels(
s->block[ 8], ptr_cb + uv_dct_offset, wrap_c);
2344 s->pdsp.get_pixels(
s->block[ 9], ptr_cr + uv_dct_offset, wrap_c);
2345 s->pdsp.get_pixels(
s->block[10], ptr_cb + uv_dct_offset + 8, wrap_c);
2346 s->pdsp.get_pixels(
s->block[11], ptr_cr + uv_dct_offset + 8, wrap_c);
2352 uint8_t *dest_y, *dest_cb, *dest_cr;
2354 dest_y =
s->dest[0];
2355 dest_cb =
s->dest[1];
2356 dest_cr =
s->dest[2];
2359 op_pix =
s->hdsp.put_pixels_tab;
2360 op_qpix =
s->qdsp.put_qpel_pixels_tab;
2362 op_pix =
s->hdsp.put_no_rnd_pixels_tab;
2363 op_qpix =
s->qdsp.put_no_rnd_qpel_pixels_tab;
2370 op_pix =
s->hdsp.avg_pixels_tab;
2371 op_qpix =
s->qdsp.avg_qpel_pixels_tab;
2380 int progressive_score, interlaced_score;
2382 s->interlaced_dct = 0;
2383 progressive_score =
s->ildct_cmp[0](
s, dest_y, ptr_y, wrap_y, 8) +
2384 s->ildct_cmp[0](
s, dest_y + wrap_y * 8,
2389 progressive_score -= 400;
2391 if (progressive_score > 0) {
2392 interlaced_score =
s->ildct_cmp[0](
s, dest_y, ptr_y,
2394 s->ildct_cmp[0](
s, dest_y + wrap_y,
2398 if (progressive_score > interlaced_score) {
2399 s->interlaced_dct = 1;
2402 uv_dct_offset = wrap_c;
2410 s->pdsp.diff_pixels(
s->block[0], ptr_y, dest_y, wrap_y);
2411 s->pdsp.diff_pixels(
s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
2414 s->pdsp.diff_pixels(
s->block[3], ptr_y +
dct_offset + 8,
2421 s->pdsp.diff_pixels(
s->block[4], ptr_cb, dest_cb, wrap_c);
2422 s->pdsp.diff_pixels(
s->block[5], ptr_cr, dest_cr, wrap_c);
2424 s->pdsp.diff_pixels(
s->block[6], ptr_cb + uv_dct_offset,
2425 dest_cb + uv_dct_offset, wrap_c);
2426 s->pdsp.diff_pixels(
s->block[7], ptr_cr + uv_dct_offset,
2427 dest_cr + uv_dct_offset, wrap_c);
2431 if (
s->mc_mb_var[
s->mb_stride *
mb_y +
mb_x] < 2 *
s->qscale *
s->qscale) {
2433 if (
s->sad_cmp[1](
NULL, ptr_y, dest_y, wrap_y, 8) < 20 *
s->qscale)
2435 if (
s->sad_cmp[1](
NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 *
s->qscale)
2438 wrap_y, 8) < 20 *
s->qscale)
2441 wrap_y, 8) < 20 *
s->qscale)
2443 if (
s->sad_cmp[1](
NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 *
s->qscale)
2445 if (
s->sad_cmp[1](
NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 *
s->qscale)
2448 if (
s->sad_cmp[1](
NULL, ptr_cb + uv_dct_offset,
2449 dest_cb + uv_dct_offset,
2450 wrap_c, 8) < 20 *
s->qscale)
2452 if (
s->sad_cmp[1](
NULL, ptr_cr + uv_dct_offset,
2453 dest_cr + uv_dct_offset,
2454 wrap_c, 8) < 20 *
s->qscale)
2460 if (
s->quantizer_noise_shaping) {
2481 memcpy(orig[0],
s->block[0],
sizeof(int16_t) * 64 * mb_block_count);
2487 for (
i = 0;
i < mb_block_count;
i++) {
2490 s->block_last_index[
i] =
s->dct_quantize(
s,
s->block[
i],
i,
s->qscale, &
overflow);
2499 s->block_last_index[
i] = -1;
2501 if (
s->quantizer_noise_shaping) {
2502 for (
i = 0;
i < mb_block_count;
i++) {
2504 s->block_last_index[
i] =
2506 orig[
i],
i,
s->qscale);
2511 if (
s->luma_elim_threshold && !
s->mb_intra)
2512 for (
i = 0;
i < 4;
i++)
2514 if (
s->chroma_elim_threshold && !
s->mb_intra)
2515 for (
i = 4;
i < mb_block_count;
i++)
2519 for (
i = 0;
i < mb_block_count;
i++) {
2520 if (
s->block_last_index[
i] == -1)
2521 s->coded_score[
i] = INT_MAX / 256;
2527 s->block_last_index[4] =
2528 s->block_last_index[5] = 0;
2530 s->block[5][0] = (1024 +
s->c_dc_scale / 2) /
s->c_dc_scale;
2532 for (
i=6;
i<12;
i++) {
2533 s->block_last_index[
i] = 0;
2534 s->block[
i][0] =
s->block[4][0];
2541 for (
i = 0;
i < mb_block_count;
i++) {
2543 if (
s->block_last_index[
i] > 0) {
2544 for (j = 63; j > 0; j--) {
2545 if (
s->block[
i][
s->intra_scantable.permutated[j]])
2548 s->block_last_index[
i] = j;
2554 switch(
s->codec_id){
2557 if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
2561 if (CONFIG_MPEG4_ENCODER)
2567 if (CONFIG_MSMPEG4ENC)
2571 if (CONFIG_WMV2_ENCODER)
2575 if (CONFIG_H261_ENCODER)
2583 if (CONFIG_H263_ENCODER)
2586 #if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
2593 if (CONFIG_SPEEDHQ_ENCODER)
2616 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2643 memcpy(d->
mv,
s->mv, 2*4*2*
sizeof(
int));
2644 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2663 if(
s->data_partitioning){
2678 int *dmin,
int *next_block,
int motion_x,
int motion_y)
2681 uint8_t *dest_backup[3];
2685 s->block=
s->blocks[*next_block];
2686 s->pb=
pb[*next_block];
2687 if(
s->data_partitioning){
2688 s->pb2 =
pb2 [*next_block];
2689 s->tex_pb=
tex_pb[*next_block];
2693 memcpy(dest_backup,
s->dest,
sizeof(
s->dest));
2694 s->dest[0] =
s->sc.rd_scratchpad;
2695 s->dest[1] =
s->sc.rd_scratchpad + 16*
s->linesize;
2696 s->dest[2] =
s->sc.rd_scratchpad + 16*
s->linesize + 8;
2703 if(
s->data_partitioning){
2711 score *=
s->lambda2;
2716 memcpy(
s->dest, dest_backup,
sizeof(
s->dest));
2734 else if(
w==8 &&
h==8)
2751 int chroma_mb_w =
w >>
s->chroma_x_shift;
2752 int chroma_mb_h =
h >>
s->chroma_y_shift;
2754 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
2755 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
2758 return s->n_sse_cmp[0](
s,
s->new_pic->data[0] +
s->mb_x * 16 +
s->mb_y *
s->linesize * 16,
2759 s->dest[0],
s->linesize, 16) +
2760 s->n_sse_cmp[1](
s,
s->new_pic->data[1] +
s->mb_x * chroma_mb_w +
s->mb_y *
s->uvlinesize * chroma_mb_h,
2761 s->dest[1],
s->uvlinesize, chroma_mb_h) +
2762 s->n_sse_cmp[1](
s,
s->new_pic->data[2] +
s->mb_x * chroma_mb_w +
s->mb_y *
s->uvlinesize * chroma_mb_h,
2763 s->dest[2],
s->uvlinesize, chroma_mb_h);
2765 return sse(
s,
s->new_pic->data[0] +
s->mb_x * 16 +
s->mb_y *
s->linesize * 16,
2766 s->dest[0],
w,
h,
s->linesize) +
2767 sse(
s,
s->new_pic->data[1] +
s->mb_x * chroma_mb_w +
s->mb_y *
s->uvlinesize * chroma_mb_h,
2768 s->dest[1],
w >>
s->chroma_x_shift,
h >>
s->chroma_y_shift,
s->uvlinesize) +
2769 sse(
s,
s->new_pic->data[2] +
s->mb_x * chroma_mb_w +
s->mb_y *
s->uvlinesize * chroma_mb_h,
2770 s->dest[2],
w >>
s->chroma_x_shift,
h >>
s->chroma_y_shift,
s->uvlinesize);
2778 s->me.dia_size=
s->avctx->pre_dia_size;
2779 s->first_slice_line=1;
2780 for(
s->mb_y=
s->end_mb_y-1;
s->mb_y >=
s->start_mb_y;
s->mb_y--) {
2781 for(
s->mb_x=
s->mb_width-1;
s->mb_x >=0 ;
s->mb_x--) {
2784 s->first_slice_line=0;
2795 s->me.dia_size=
s->avctx->dia_size;
2796 s->first_slice_line=1;
2797 for(
s->mb_y=
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2800 for(
s->mb_x=0;
s->mb_x <
s->mb_width;
s->mb_x++) {
2801 s->block_index[0]+=2;
2802 s->block_index[1]+=2;
2803 s->block_index[2]+=2;
2804 s->block_index[3]+=2;
2812 s->first_slice_line=0;
2825 const uint8_t *pix =
s->new_pic->data[0] + (yy *
s->linesize) + xx;
2827 int sum =
s->mpvencdsp.pix_sum(pix,
s->linesize);
2829 varc = (
s->mpvencdsp.pix_norm1(pix,
s->linesize) -
2830 (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
2832 s->mb_var [
s->mb_stride *
mb_y +
mb_x] = varc;
2833 s->mb_mean[
s->mb_stride *
mb_y +
mb_x] = (sum+128)>>8;
2834 s->me.mb_var_sum_temp += varc;
2842 if(
s->partitioned_frame){
2847 }
else if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) &&
2850 }
else if (CONFIG_SPEEDHQ_ENCODER &&
s->out_format ==
FMT_SPEEDHQ) {
2862 uint8_t *ptr =
s->mb_info_ptr +
s->mb_info_size - 12;
2864 int mba =
s->mb_x +
s->mb_width * (
s->mb_y %
s->gob_index);
2865 int gobn =
s->mb_y /
s->gob_index;
2867 if (CONFIG_H263_ENCODER)
2869 bytestream_put_le32(&ptr,
offset);
2870 bytestream_put_byte(&ptr,
s->qscale);
2871 bytestream_put_byte(&ptr, gobn);
2872 bytestream_put_le16(&ptr, mba);
2873 bytestream_put_byte(&ptr, pred_x);
2874 bytestream_put_byte(&ptr, pred_y);
2876 bytestream_put_byte(&ptr, 0);
2877 bytestream_put_byte(&ptr, 0);
2885 s->mb_info_size += 12;
2886 s->prev_mb_info =
s->last_mb_info;
2898 if (!
s->mb_info_size)
2899 s->mb_info_size += 12;
2906 &&
s->slice_context_count == 1
2907 &&
s->pb.buf ==
s->avctx->internal->byte_buffer) {
2908 int lastgob_pos =
s->ptr_lastgob -
s->pb.buf;
2910 uint8_t *new_buffer =
NULL;
2911 int new_buffer_size = 0;
2913 if ((
s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) {
2921 s->avctx->internal->byte_buffer_size + size_increase);
2925 memcpy(new_buffer,
s->avctx->internal->byte_buffer,
s->avctx->internal->byte_buffer_size);
2926 av_free(
s->avctx->internal->byte_buffer);
2927 s->avctx->internal->byte_buffer = new_buffer;
2928 s->avctx->internal->byte_buffer_size = new_buffer_size;
2930 s->ptr_lastgob =
s->pb.buf + lastgob_pos;
2940 int chr_h= 16>>
s->chroma_y_shift;
2964 s->last_dc[
i] = 128 <<
s->intra_dc_precision;
2966 s->encoding_error[
i] = 0;
2969 s->last_dc[0] = 128*8/13;
2970 s->last_dc[1] = 128*8/14;
2971 s->last_dc[2] = 128*8/14;
2974 memset(
s->last_mv, 0,
sizeof(
s->last_mv));
2978 switch(
s->codec_id){
2982 if (CONFIG_H263_ENCODER)
2986 if(CONFIG_MPEG4_ENCODER &&
s->partitioned_frame)
2993 s->first_slice_line = 1;
2994 s->ptr_lastgob =
s->pb.buf;
2995 for (mb_y_order =
s->start_mb_y; mb_y_order < s->
end_mb_y; mb_y_order++) {
2999 if (first_in_slice && mb_y_order !=
s->start_mb_y)
3001 s->last_dc[0] =
s->last_dc[1] =
s->last_dc[2] = 1024 <<
s->intra_dc_precision;
3017 int size_increase =
s->avctx->internal->byte_buffer_size/4
3025 if(
s->data_partitioning){
3039 xy=
s->mb_y*
s->mb_stride +
s->mb_x;
3045 int current_packet_size, is_gob_start;
3048 - (
s->ptr_lastgob -
s->pb.buf);
3050 is_gob_start =
s->rtp_payload_size &&
3051 current_packet_size >=
s->rtp_payload_size &&
3054 if(
s->start_mb_y ==
mb_y &&
mb_y > 0 &&
mb_x==0) is_gob_start=1;
3056 switch(
s->codec_id){
3059 if(!
s->h263_slice_structured)
3060 if(
s->mb_x ||
s->mb_y%
s->gob_index) is_gob_start=0;
3063 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3065 if(
s->mb_skip_run) is_gob_start=0;
3068 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3084 if (
s->error_rate &&
s->resync_mb_x +
s->resync_mb_y > 0) {
3086 int d = 100 /
s->error_rate;
3088 current_packet_size=0;
3089 s->pb.buf_ptr=
s->ptr_lastgob;
3094 switch(
s->codec_id){
3096 if (CONFIG_MPEG4_ENCODER) {
3103 if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) {
3110 if (CONFIG_H263_ENCODER) {
3119 s->misc_bits+=
bits -
s->last_bits;
3123 s->ptr_lastgob += current_packet_size;
3124 s->first_slice_line=1;
3125 s->resync_mb_x=
mb_x;
3126 s->resync_mb_y=
mb_y;
3130 if( (
s->resync_mb_x ==
s->mb_x)
3131 &&
s->resync_mb_y+1 ==
s->mb_y){
3132 s->first_slice_line=0;
3142 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
3148 if(
s->data_partitioning){
3149 backup_s.pb2=
s->pb2;
3150 backup_s.tex_pb=
s->tex_pb;
3157 s->mv[0][0][0] =
s->p_mv_table[xy][0];
3158 s->mv[0][0][1] =
s->p_mv_table[xy][1];
3160 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3167 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3168 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3169 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3172 &dmin, &next_block, 0, 0);
3181 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3188 s->mv[0][
i][0] =
s->cur_pic.motion_val[0][
s->block_index[
i]][0];
3189 s->mv[0][
i][1] =
s->cur_pic.motion_val[0][
s->block_index[
i]][1];
3192 &dmin, &next_block, 0, 0);
3198 s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3199 s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3201 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3207 s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3208 s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3210 &dmin, &next_block,
s->mv[1][0][0],
s->mv[1][0][1]);
3216 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3217 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3218 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3219 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3221 &dmin, &next_block, 0, 0);
3228 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3229 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3230 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3233 &dmin, &next_block, 0, 0);
3240 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3241 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3242 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3245 &dmin, &next_block, 0, 0);
3251 for(dir=0; dir<2; dir++){
3253 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3254 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3255 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3259 &dmin, &next_block, 0, 0);
3268 &dmin, &next_block, 0, 0);
3269 s->mbintra_table[xy] = 1;
3274 const int last_qp= backup_s.qscale;
3278 static const int dquant_tab[4]={-1,1,-2,2};
3279 int storecoefs =
s->mb_intra &&
s->dc_val[0];
3287 s->mv[0][0][0] = best_s.
mv[0][0][0];
3288 s->mv[0][0][1] = best_s.
mv[0][0][1];
3289 s->mv[1][0][0] = best_s.
mv[1][0][0];
3290 s->mv[1][0][1] = best_s.
mv[1][0][1];
3293 for(; qpi<4; qpi++){
3294 int dquant= dquant_tab[qpi];
3296 if(qp < s->
avctx->
qmin || qp >
s->avctx->qmax)
3301 dc[
i]=
s->dc_val[0][
s->block_index[
i] ];
3302 memcpy(ac[
i],
s->ac_val[0][
s->block_index[
i]],
sizeof(int16_t)*16);
3307 &dmin, &next_block,
s->mv[mvdir][0][0],
s->mv[mvdir][0][1]);
3311 s->dc_val[0][
s->block_index[
i] ]=
dc[
i];
3312 memcpy(
s->ac_val[0][
s->block_index[
i]], ac[
i],
sizeof(int16_t)*16);
3320 int mx=
s->b_direct_mv_table[xy][0];
3321 int my=
s->b_direct_mv_table[xy][1];
3323 backup_s.dquant = 0;
3328 &dmin, &next_block,
mx,
my);
3331 backup_s.dquant = 0;
3336 &dmin, &next_block, 0, 0);
3341 coded |=
s->block_last_index[
i];
3344 memcpy(
s->mv, best_s.
mv,
sizeof(
s->mv));
3366 &dmin, &next_block,
mx,
my);
3375 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
3378 if(
s->data_partitioning){
3381 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
3382 s->pb2= backup_s.pb2;
3386 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
3387 s->tex_pb= backup_s.tex_pb;
3391 if (CONFIG_H263_ENCODER &&
3396 s->hdsp.put_pixels_tab[0][0](
s->dest[0],
s->sc.rd_scratchpad ,
s->linesize ,16);
3397 s->hdsp.put_pixels_tab[1][0](
s->dest[1],
s->sc.rd_scratchpad + 16*
s->linesize ,
s->uvlinesize, 8);
3398 s->hdsp.put_pixels_tab[1][0](
s->dest[2],
s->sc.rd_scratchpad + 16*
s->linesize + 8,
s->uvlinesize, 8);
3404 int motion_x = 0, motion_y = 0;
3412 motion_x=
s->mv[0][0][0] = 0;
3413 motion_y=
s->mv[0][0][1] = 0;
3414 s->mbintra_table[xy] = 1;
3419 motion_x=
s->mv[0][0][0] =
s->p_mv_table[xy][0];
3420 motion_y=
s->mv[0][0][1] =
s->p_mv_table[xy][1];
3427 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3428 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3429 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3437 s->mv[0][
i][0] =
s->cur_pic.motion_val[0][
s->block_index[
i]][0];
3438 s->mv[0][
i][1] =
s->cur_pic.motion_val[0][
s->block_index[
i]][1];
3442 if (CONFIG_MPEG4_ENCODER) {
3445 motion_x=
s->b_direct_mv_table[xy][0];
3446 motion_y=
s->b_direct_mv_table[xy][1];
3451 if (CONFIG_MPEG4_ENCODER) {
3460 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3461 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3462 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3463 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3468 motion_x=
s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3469 motion_y=
s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3474 motion_x=
s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3475 motion_y=
s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3482 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3483 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3484 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3492 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3493 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3494 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3501 for(dir=0; dir<2; dir++){
3503 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3504 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3505 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3516 s->last_mv_dir =
s->mv_dir;
3518 if (CONFIG_H263_ENCODER &&
3525 s->cur_pic.qscale_table[xy] =
s->qscale;
3529 s->p_mv_table[xy][0]=0;
3530 s->p_mv_table[xy][1]=0;
3531 }
else if ((
s->h263_pred ||
s->h263_aic) &&
s->mbintra_table[xy])
3538 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
3539 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
3541 s->encoding_error[0] +=
sse(
3542 s,
s->new_pic->data[0] +
s->mb_x*16 +
s->mb_y*
s->linesize*16,
3543 s->dest[0],
w,
h,
s->linesize);
3544 s->encoding_error[1] +=
sse(
3545 s,
s->new_pic->data[1] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3546 s->dest[1],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3547 s->encoding_error[2] +=
sse(
3548 s,
s->new_pic->data[2] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3549 s->dest[2],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3552 if(CONFIG_H263_ENCODER &&
s->out_format ==
FMT_H263)
3555 ff_dlog(
s->avctx,
"MB %d %d bits\n",
3560 #if CONFIG_MSMPEG4ENC
3572 #define MERGE(field) dst->field += src->field; src->field=0
3593 if (
dst->noise_reduction){
3594 for(
i=0;
i<64;
i++){
3607 if (
s->next_lambda){
3608 s->cur_pic.ptr->f->quality =
s->next_lambda;
3609 if(!dry_run)
s->next_lambda= 0;
3610 }
else if (!
s->fixed_qscale) {
3612 s->cur_pic.ptr->f->quality =
quality;
3613 if (
s->cur_pic.ptr->f->quality < 0)
3617 if(
s->adaptive_quant){
3620 switch(
s->codec_id){
3622 if (CONFIG_MPEG4_ENCODER)
3628 if (CONFIG_H263_ENCODER)
3633 s->lambda=
s->lambda_table[0];
3636 s->lambda =
s->cur_pic.ptr->f->quality;
3644 s->time =
s->cur_pic.ptr->f->pts *
s->avctx->time_base.num;
3647 s->pb_time=
s->pp_time - (
s->last_non_b_time -
s->time);
3650 s->pp_time=
s->time -
s->last_non_b_time;
3651 s->last_non_b_time=
s->time;
3660 int context_count =
s->slice_context_count;
3663 s->me.mb_var_sum_temp =
3664 s->me.mc_mb_var_sum_temp = 0;
3673 s->me.scene_change_score=0;
3678 s->no_rounding =
s->msmpeg4_version >=
MSMP4_V3;
3680 s->no_rounding ^=
s->flipflop_rounding;
3689 s->lambda=
s->last_lambda_for[
s->pict_type];
3691 s->lambda=
s->last_lambda_for[
s->last_non_b_pict_type];
3698 for (
int i = 0;
i < context_count;
i++) {
3700 uint8_t *start, *end;
3719 s->lambda = (
s->lambda *
s->me_penalty_compensation + 128) >> 8;
3720 s->lambda2 = (
s->lambda2 * (
int64_t)
s->me_penalty_compensation + 128) >> 8;
3731 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3734 if(!
s->fixed_qscale){
3736 s->avctx->execute(
s->avctx,
mb_var_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
3739 for(
i=1;
i<context_count;
i++){
3742 s->mc_mb_var_sum =
s->me.mc_mb_var_sum_temp;
3743 s->mb_var_sum =
s->me. mb_var_sum_temp;
3746 if (
s->me.scene_change_score >
s->scenechange_threshold &&
3749 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3753 ff_dlog(
s->avctx,
"Scene change detected, encoding as I Frame %"PRId64
" %"PRId64
"\n",
3754 s->mb_var_sum,
s->mc_mb_var_sum);
3795 for(dir=0; dir<2; dir++){
3801 s->b_field_mv_table[dir][
i][j], dir ?
s->b_code :
s->f_code,
type, 1);
3812 if (
s->qscale < 3 &&
s->max_qcoeff <= 128 &&
3826 if (
s->avctx->intra_matrix) {
3828 luma_matrix =
s->avctx->intra_matrix;
3830 if (
s->avctx->chroma_intra_matrix)
3831 chroma_matrix =
s->avctx->chroma_intra_matrix;
3834 for (
int i = 1;
i < 64;
i++) {
3835 int j =
s->idsp.idct_permutation[
i];
3837 s->chroma_intra_matrix[j] =
av_clip_uint8((chroma_matrix[
i] *
s->qscale) >> 3);
3840 s->y_dc_scale_table =
3842 s->chroma_intra_matrix[0] =
3845 static const uint8_t y[32] = {13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13};
3846 static const uint8_t
c[32] = {14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14};
3847 for (
int i = 1;
i < 64;
i++) {
3853 s->y_dc_scale_table = y;
3854 s->c_dc_scale_table =
c;
3855 s->intra_matrix[0] = 13;
3856 s->chroma_intra_matrix[0] = 14;
3859 s->intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3861 s->chroma_intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3870 s->cur_pic.ptr->f->pict_type =
s->pict_type;
3873 s->picture_in_gop_number=0;
3875 s->mb_x =
s->mb_y = 0;
3877 switch(
s->out_format) {
3878 #if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
3884 if (CONFIG_SPEEDHQ_ENCODER)
3888 if (CONFIG_H261_ENCODER)
3894 #if CONFIG_MSMPEG4ENC
3898 else if (CONFIG_MPEG4_ENCODER &&
s->h263_pred) {
3911 else if (CONFIG_H263_ENCODER)
3915 if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
3922 s->header_bits=
bits -
s->last_bits;
3924 for(
i=1;
i<context_count;
i++){
3927 s->avctx->execute(
s->avctx,
encode_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
3928 for(
i=1;
i<context_count;
i++){
3929 if (
s->pb.buf_end ==
s->thread_context[
i]->pb.buf)
3938 const int intra=
s->mb_intra;
3941 s->dct_count[intra]++;
3943 for(
i=0;
i<64;
i++){
3948 s->dct_error_sum[intra][
i] +=
level;
3949 level -=
s->dct_offset[intra][
i];
3952 s->dct_error_sum[intra][
i] -=
level;
3953 level +=
s->dct_offset[intra][
i];
3962 int16_t *
block,
int n,
3966 const uint8_t *scantable;
3967 const uint8_t *perm_scantable;
3969 unsigned int threshold1, threshold2;
3981 int coeff_count[64];
3982 int qmul, qadd, start_i, last_non_zero,
i,
dc;
3983 const int esc_length=
s->ac_esc_length;
3984 const uint8_t *length, *last_length;
3990 if(
s->dct_error_sum)
3996 else mpeg2_qscale =
qscale << 1;
4000 scantable=
s->intra_scantable.scantable;
4001 perm_scantable=
s->intra_scantable.permutated;
4018 qmat = n < 4 ?
s->q_intra_matrix[
qscale] :
s->q_chroma_intra_matrix[
qscale];
4019 matrix = n < 4 ?
s->intra_matrix :
s->chroma_intra_matrix;
4023 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4024 length =
s->intra_chroma_ac_vlc_length;
4025 last_length=
s->intra_chroma_ac_vlc_last_length;
4027 length =
s->intra_ac_vlc_length;
4028 last_length=
s->intra_ac_vlc_last_length;
4031 scantable=
s->inter_scantable.scantable;
4032 perm_scantable=
s->inter_scantable.permutated;
4035 qmat =
s->q_inter_matrix[
qscale];
4037 length =
s->inter_ac_vlc_length;
4038 last_length=
s->inter_ac_vlc_last_length;
4043 threshold2= (threshold1<<1);
4045 for(
i=63;
i>=start_i;
i--) {
4046 const int j = scantable[
i];
4049 if(((uint64_t)(
level+threshold1))>threshold2){
4055 for(
i=start_i;
i<=last_non_zero;
i++) {
4056 const int j = scantable[
i];
4061 if(((uint64_t)(
level+threshold1))>threshold2){
4084 if(last_non_zero < start_i){
4085 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4086 return last_non_zero;
4089 score_tab[start_i]= 0;
4090 survivor[0]= start_i;
4093 for(
i=start_i;
i<=last_non_zero;
i++){
4094 int level_index, j, zero_distortion;
4096 int best_score=256*256*256*120;
4100 zero_distortion= dct_coeff*dct_coeff;
4102 for(level_index=0; level_index < coeff_count[
i]; level_index++){
4111 unquant_coeff= alevel*qmul + qadd;
4113 j =
s->idsp.idct_permutation[scantable[
i]];
4114 unquant_coeff = alevel *
matrix[j] * 8;
4116 j =
s->idsp.idct_permutation[scantable[
i]];
4118 unquant_coeff = (int)( alevel * mpeg2_qscale *
matrix[j]) >> 4;
4119 unquant_coeff = (unquant_coeff - 1) | 1;
4121 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((int)
matrix[j])) >> 5;
4122 unquant_coeff = (unquant_coeff - 1) | 1;
4127 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
4129 if((
level&(~127)) == 0){
4130 for(j=survivor_count-1; j>=0; j--){
4131 int run=
i - survivor[j];
4133 score += score_tab[
i-
run];
4135 if(score < best_score){
4138 level_tab[
i+1]=
level-64;
4143 for(j=survivor_count-1; j>=0; j--){
4144 int run=
i - survivor[j];
4146 score += score_tab[
i-
run];
4147 if(score < last_score){
4150 last_level=
level-64;
4156 distortion += esc_length*
lambda;
4157 for(j=survivor_count-1; j>=0; j--){
4158 int run=
i - survivor[j];
4159 int score= distortion + score_tab[
i-
run];
4161 if(score < best_score){
4164 level_tab[
i+1]=
level-64;
4169 for(j=survivor_count-1; j>=0; j--){
4170 int run=
i - survivor[j];
4171 int score= distortion + score_tab[
i-
run];
4172 if(score < last_score){
4175 last_level=
level-64;
4183 score_tab[
i+1]= best_score;
4186 if(last_non_zero <= 27){
4187 for(; survivor_count; survivor_count--){
4188 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
4192 for(; survivor_count; survivor_count--){
4193 if(score_tab[ survivor[survivor_count-1] ] <= best_score +
lambda)
4198 survivor[ survivor_count++ ]=
i+1;
4202 last_score= 256*256*256*120;
4203 for(
i= survivor[0];
i<=last_non_zero + 1;
i++){
4204 int score= score_tab[
i];
4208 if(score < last_score){
4211 last_level= level_tab[
i];
4212 last_run= run_tab[
i];
4217 s->coded_score[n] = last_score;
4220 last_non_zero= last_i - 1;
4221 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4223 if(last_non_zero < start_i)
4224 return last_non_zero;
4226 if(last_non_zero == 0 && start_i == 0){
4228 int best_score=
dc *
dc;
4230 for(
i=0;
i<coeff_count[0];
i++){
4233 int unquant_coeff, score, distortion;
4236 unquant_coeff= (alevel*qmul + qadd)>>3;
4238 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((int)
matrix[0])) >> 5;
4239 unquant_coeff = (unquant_coeff - 1) | 1;
4241 unquant_coeff = (unquant_coeff + 4) >> 3;
4242 unquant_coeff<<= 3 + 3;
4244 distortion= (unquant_coeff -
dc) * (unquant_coeff -
dc);
4247 else score= distortion + esc_length*
lambda;
4249 if(score < best_score){
4251 best_level=
level - 64;
4254 block[0]= best_level;
4255 s->coded_score[n] = best_score -
dc*
dc;
4256 if(best_level == 0)
return -1;
4257 else return last_non_zero;
4263 block[ perm_scantable[last_non_zero] ]= last_level;
4266 for(;
i>start_i;
i -= run_tab[
i] + 1){
4267 block[ perm_scantable[
i-1] ]= level_tab[
i];
4270 return last_non_zero;
4285 if(
i==0)
s*= sqrt(0.5);
4286 if(j==0)
s*= sqrt(0.5);
4299 const uint8_t *scantable;
4300 const uint8_t *perm_scantable;
4306 int qmul, qadd, start_i, last_non_zero,
i,
dc;
4307 const uint8_t *length;
4308 const uint8_t *last_length;
4310 int rle_index,
run, q = 1, sum;
4312 if(
basis[0][0] == 0)
4318 scantable=
s->intra_scantable.scantable;
4319 perm_scantable=
s->intra_scantable.permutated;
4337 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4338 length =
s->intra_chroma_ac_vlc_length;
4339 last_length=
s->intra_chroma_ac_vlc_last_length;
4341 length =
s->intra_ac_vlc_length;
4342 last_length=
s->intra_ac_vlc_last_length;
4345 scantable=
s->inter_scantable.scantable;
4346 perm_scantable=
s->inter_scantable.permutated;
4349 length =
s->inter_ac_vlc_length;
4350 last_length=
s->inter_ac_vlc_last_length;
4352 last_non_zero =
s->block_last_index[n];
4355 for(
i=0;
i<64;
i++){
4360 for(
i=0;
i<64;
i++){
4366 w= 15 + (48*qns*one +
w/2)/
w;
4379 for(
i=start_i;
i<=last_non_zero;
i++){
4380 int j= perm_scantable[
i];
4387 run_tab[rle_index++]=
run;
4397 int best_score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0], 0);
4400 int run2, best_unquant_change=0, analyze_gradient;
4401 analyze_gradient = last_non_zero > 2 ||
s->quantizer_noise_shaping >= 3;
4403 if(analyze_gradient){
4404 for(
i=0;
i<64;
i++){
4414 int change, old_coeff;
4420 for(change=-1; change<=1; change+=2){
4421 int new_level=
level + change;
4422 int score, new_coeff;
4424 new_coeff= q*new_level;
4425 if(new_coeff >= 2048 || new_coeff < 0)
4428 score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0],
4429 new_coeff - old_coeff);
4430 if(score<best_score){
4433 best_change= change;
4434 best_unquant_change= new_coeff - old_coeff;
4441 run2= run_tab[rle_index++];
4445 for(
i=start_i;
i<64;
i++){
4446 int j= perm_scantable[
i];
4448 int change, old_coeff;
4450 if(
s->quantizer_noise_shaping < 3 &&
i > last_non_zero + 1)
4455 else old_coeff= qmul*
level + qadd;
4456 run2= run_tab[rle_index++];
4463 for(change=-1; change<=1; change+=2){
4464 int new_level=
level + change;
4465 int score, new_coeff, unquant_change;
4472 if(new_level<0) new_coeff= qmul*new_level - qadd;
4473 else new_coeff= qmul*new_level + qadd;
4474 if(new_coeff >= 2048 || new_coeff <= -2048)
4479 if(level < 63 && level > -63){
4480 if(
i < last_non_zero)
4490 if(analyze_gradient){
4491 int g= d1[ scantable[
i] ];
4492 if(
g && (
g^new_level) >= 0)
4496 if(
i < last_non_zero){
4497 int next_i=
i + run2 + 1;
4498 int next_level=
block[ perm_scantable[next_i] ] + 64;
4500 if(next_level&(~127))
4503 if(next_i < last_non_zero)
4523 if(
i < last_non_zero){
4524 int next_i=
i + run2 + 1;
4525 int next_level=
block[ perm_scantable[next_i] ] + 64;
4527 if(next_level&(~127))
4530 if(next_i < last_non_zero)
4549 unquant_change= new_coeff - old_coeff;
4552 score +=
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[j],
4554 if(score<best_score){
4557 best_change= change;
4558 best_unquant_change= unquant_change;
4562 prev_level=
level + 64;
4563 if(prev_level&(~127))
4573 int j= perm_scantable[ best_coeff ];
4575 block[j] += best_change;
4577 if(best_coeff > last_non_zero){
4578 last_non_zero= best_coeff;
4581 for(; last_non_zero>=start_i; last_non_zero--){
4582 if(
block[perm_scantable[last_non_zero]])
4589 for(
i=start_i;
i<=last_non_zero;
i++){
4590 int j= perm_scantable[
i];
4594 run_tab[rle_index++]=
run;
4601 s->mpvencdsp.add_8x8basis(rem,
basis[j], best_unquant_change);
4607 return last_non_zero;
4622 const uint8_t *scantable,
int last)
4633 for (
i = 0;
i <= last;
i++) {
4634 const int j = scantable[
i];
4639 for (
i = 0;
i <= last;
i++) {
4640 const int j = scantable[
i];
4641 const int perm_j = permutation[j];
4647 int16_t *
block,
int n,
4650 int i, last_non_zero, q, start_i;
4652 const uint8_t *scantable;
4655 unsigned int threshold1, threshold2;
4659 if(
s->dct_error_sum)
4663 scantable=
s->intra_scantable.scantable;
4678 qmat = n < 4 ?
s->q_intra_matrix[
qscale] :
s->q_chroma_intra_matrix[
qscale];
4681 scantable=
s->inter_scantable.scantable;
4684 qmat =
s->q_inter_matrix[
qscale];
4688 threshold2= (threshold1<<1);
4689 for(
i=63;
i>=start_i;
i--) {
4690 const int j = scantable[
i];
4693 if(((uint64_t)(
level+threshold1))>threshold2){
4700 for(
i=start_i;
i<=last_non_zero;
i++) {
4701 const int j = scantable[
i];
4706 if(((uint64_t)(
level+threshold1))>threshold2){
4724 scantable, last_non_zero);
4726 return last_non_zero;
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
static int encode_frame(AVCodecContext *c, const AVFrame *frame, AVPacket *pkt)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
#define FF_MATRIX_TYPE_INTRA
Check if the elements of codec context matrices (intra_matrix, inter_matrix or chroma_intra_matrix) a...
void ff_speedhq_end_slice(MpegEncContext *s)
int ff_encode_reordered_opaque(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
Propagate user opaque values from the frame to avctx/pkt as needed.
int mb_skipped
MUST BE SET only during DECODING.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int encode_picture(MpegEncContext *s, const AVPacket *pkt)
uint16_t * mb_type
Table for candidate MB types for encoding (defines in mpegvideoenc.h)
#define CANDIDATE_MB_TYPE_BIDIR
#define MV_TYPE_16X16
1 vector for the whole mb
#define AV_LOG_WARNING
Something somehow does not look correct.
av_cold int ff_speedhq_encode_init(MpegEncContext *s)
const AVClass ff_mpv_enc_class
int data_partitioning
data partitioning flag from header
static void set_frame_distances(MpegEncContext *s)
static int get_bits_diff(MpegEncContext *s)
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
unsigned int lambda
Lagrange multiplier used in rate distortion.
#define H263_GOB_HEIGHT(h)
av_cold int ff_h261_encode_init(MpegEncContext *s)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void ff_mpv_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int dir, uint8_t *const *ref_picture, const op_pixels_func(*pix_op)[4], const qpel_mc_func(*qpix_op)[16])
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is actually possible in MPEG-4
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], int motion_x, int motion_y)
int b_code
backward MV resolution for B-frames (MPEG-4)
av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, const MECmpContext *mecc, int mpvenc)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int64_t rc_min_rate
minimum bitrate
void ff_fix_long_p_mvs(MpegEncContext *s, int type)
void ff_speedhq_encode_picture_header(MpegEncContext *s)
int ff_wmv2_encode_picture_header(MpegEncContext *s)
#define AVERROR_EOF
End of file.
void ff_h261_encode_picture_header(MpegEncContext *s)
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
static int sse_mb(MpegEncContext *s)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int16_t basis[64][64]
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
static const uint8_t mv_bits[2][16][10]
static int estimate_motion_thread(AVCodecContext *c, void *arg)
float lumi_masking
luminance masking (0-> disabled)
static void update_noise_reduction(MpegEncContext *s)
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int partitioned_frame
is current frame partitioned
#define CANDIDATE_MB_TYPE_INTER
uint16_t(* dct_offset)[64]
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define INTERLACED_DCT(s)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int capabilities
Codec capabilities.
static const int32_t qmat16[MAT_SIZE]
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
static void put_dct(MpegEncContext *s, int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Shrink the already allocated side data buffer.
static int put_bytes_count(const PutBitContext *s, int round_up)
int last_dc[3]
last DC values for MPEG-1
const uint8_t ff_mpeg2_non_linear_qscale[32]
static int prepare_picture(MpegEncContext *s, AVFrame *f, const AVFrame *props_frame)
Allocates new buffers for an AVFrame and copies the properties from another AVFrame.
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac for the current non-intra MB.
#define AV_LOG_VERBOSE
Detailed information.
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
void ff_init_block_index(MpegEncContext *s)
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define FF_MPV_FLAG_SKIP_RD
const uint8_t ff_mpeg12_dc_scale_table[4][32]
struct AVCodecContext * avctx
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
av_cold int ff_rate_control_init(MpegEncContext *s)
static double sqr(double in)
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
static int pre_estimate_motion_thread(AVCodecContext *c, void *arg)
static void get_visual_weight(int16_t *weight, const uint8_t *ptr, int stride)
PutBitContext pb
bit output
int mb_decision
macroblock decision mode
int qmax
maximum quantizer
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
void ff_flv_encode_picture_header(MpegEncContext *s)
#define AV_CODEC_FLAG_4MV
4 MV per MB allowed / advanced prediction for H.263.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int mb_cmp
macroblock comparison function (not supported yet)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
#define CANDIDATE_MB_TYPE_BACKWARD_I
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int(* sum_abs_dctelem)(const int16_t *block)
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
#define FF_MPV_COMMON_MOTION_EST_OPTS
uint64_t encoding_error[MPV_MAX_PLANES]
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
static int skip_check(MpegEncContext *s, const MPVPicture *p, const MPVPicture *ref)
#define FF_MPV_COMMON_OPTS
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
static int estimate_qp(MpegEncContext *s, int dry_run)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
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.
const struct AVCodec * codec
static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
static void frame_start(MpegEncContext *s)
av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
static const struct twinvq_data tab
ptrdiff_t linesize
line size, in bytes, may be different from width
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
int flags
AV_CODEC_FLAG_*.
#define CANDIDATE_MB_TYPE_SKIPPED
const h264_weight_func weight
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define FF_MPV_FLAG_CBP_RD
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static void mpv_encode_init_static(void)
static int put_bytes_left(const PutBitContext *s, int round_up)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define CANDIDATE_MB_TYPE_DIRECT
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
#define CANDIDATE_MB_TYPE_INTER_I
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
void ff_mpv_common_end(MpegEncContext *s)
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static void update_mb_info(MpegEncContext *s, int startcode)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
static uint8_t default_fcode_tab[MAX_MV *2+1]
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Performs dequantization and IDCT (if necessary)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
static void build_basis(uint8_t *perm)
int has_b_frames
Size of the frame reordering buffer in the decoder.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
static int get_sae(const uint8_t *src, int ref, int stride)
static void rebase_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Rebase the bit writer onto a reallocated buffer.
#define AV_CEIL_RSHIFT(a, b)
void ff_mpeg4_stuffing(PutBitContext *pbc)
add MPEG-4 stuffing bits (01...1)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define LOCAL_ALIGNED_16(t, v,...)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
static void init_qscale_tab(MpegEncContext *s)
init s->cur_pic.qscale_table from s->lambda_table
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int64_t rc_max_rate
maximum bitrate
void ff_block_permute(int16_t *block, const uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block according to permutation.
uint64_t error[AV_NUM_DATA_POINTERS]
error
This structure describes the bitrate properties of an encoded bitstream.
static int ff_speedhq_mb_y_order_to_mb(int mb_y_order, int mb_height, int *first_in_slice)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define CANDIDATE_MB_TYPE_FORWARD
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
float p_masking
p block masking (0-> disabled)
static int mb_var_thread(AVCodecContext *c, void *arg)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_mpv_unref_picture(MPVWorkPicture *pic)
static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
int rc_buffer_size
decoder bitstream buffer size
PutBitContext pb2
used for data partitioned VOPs
#define LIBAVUTIL_VERSION_INT
void ff_write_pass1_stats(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_FORWARD_I
void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Describe the class of an AVClass context structure.
#define PTRDIFF_SPECIFIER
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void write_mb_info(MpegEncContext *s)
int f_code
forward MV resolution
static int bias(int x, int c)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
av_cold void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
#define CANDIDATE_MB_TYPE_BACKWARD
struct AVCodecInternal * internal
Private context used for internal data.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int64_t bit_rate
the average bitrate
int display_picture_number
#define ROUNDED_DIV(a, b)
void ff_faandct(int16_t *data)
uint16_t inter_matrix[64]
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static void update_duplicate_context_after_me(MpegEncContext *dst, const MpegEncContext *src)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
av_cold void ff_dct_encode_init(MpegEncContext *s)
static int dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
#define AV_CODEC_FLAG_AC_PRED
H.263 advanced intra coding / MPEG-4 AC prediction.
int ildct_cmp
interlaced DCT comparison function
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
int ff_vbv_update(MpegEncContext *s, int frame_size)
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
#define FF_MB_DECISION_SIMPLE
uses mb_cmp
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int trellis
trellis RD quantization
void ff_mpeg4_init_partitions(MpegEncContext *s)
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
int ff_mpeg4_encode_picture_header(MpegEncContext *s)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void ff_mpeg1_encode_init(MpegEncContext *s)
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
void ff_clean_h263_qscales(MpegEncContext *s)
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
float temporal_cplx_masking
temporary complexity masking (0-> disabled)
static void mpv_encode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for encoding.
static void denoise_dct_c(MpegEncContext *s, int16_t *block)
static void set_put_bits_buffer_size(PutBitContext *s, int size)
Change the end of the buffer.
void ff_mpeg4_merge_partitions(MpegEncContext *s)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
#define FF_DEBUG_DCT_COEFF
void ff_dct_encode_init_x86(MpegEncContext *s)
char * stats_out
pass1 encoding statistics output buffer
static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_width, int mb_block_count, int chroma_x_shift, int chroma_y_shift, int chroma_format)
#define AV_CODEC_FLAG_QPEL
Use qpel MC.
static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
void ff_mpeg4_clean_buffers(MpegEncContext *s)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
static int shift(int a, int b)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
int ff_pre_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
void ff_mpeg1_clean_buffers(MpegEncContext *s)
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
#define CANDIDATE_MB_TYPE_DIRECT0
const int16_t ff_mpeg4_default_intra_matrix[64]
void ff_msmpeg4_encode_ext_header(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_INTRA
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const AVOption mpv_generic_options[]
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
#define FF_MPV_FLAG_QP_RD
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
const uint16_t ff_mpeg1_default_intra_matrix[256]
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
av_cold int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type, int mpvenc)
Fill the function pointer array cmp[6] with me_cmp_funcs from c based upon type.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define FF_COMPLIANCE_NORMAL
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
const int16_t ff_mpeg4_default_non_intra_matrix[64]
#define ALLOCZ_ARRAYS(p, mult, numb)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
void ff_me_init_pic(MpegEncContext *s)
#define MV_TYPE_FIELD
2 vectors, one per field
void ff_h263_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
unsigned int byte_buffer_size
uint8_t * scratchpad_buf
the other *_scratchpad point into this buffer
#define UNI_AC_ENC_INDEX(run, level)
#define CANDIDATE_MB_TYPE_BIDIR_I
#define AV_LOG_INFO
Standard information.
av_cold void ff_mpvenc_dct_init_mips(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_INTER4V
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static void update_qscale(MpegEncContext *s)
int ff_mjpeg_add_icc_profile_size(AVCodecContext *avctx, const AVFrame *frame, size_t *max_pkt_size)
void ff_msmpeg4_encode_picture_header(MpegEncContext *s)
uint64_t vbv_delay
The delay between the time the packet this structure is associated with is received and the time when...
int block_last_index[12]
last non zero coefficient in block
void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64])
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
@ AV_PKT_DATA_H263_MB_INFO
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int put_bits_count(PutBitContext *s)
static int dct_quantize_trellis_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
static int get_intra_count(MpegEncContext *s, const uint8_t *src, const uint8_t *ref, int stride)
static int encode_thread(AVCodecContext *c, void *arg)
void ff_jpeg_fdct_islow_8(int16_t *data)
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
const uint32_t ff_square_tab[512]
#define FF_MATRIX_TYPE_CHROMA_INTRA
static int estimate_best_b_count(MpegEncContext *s)
int intra_dc_precision
precision of the intra DC coefficient - 8
PutBitContext tex_pb
used for data partitioned VOPs
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
void ff_h261_reorder_mb_index(MpegEncContext *s)
void ff_jpeg_fdct_islow_10(int16_t *data)
void ff_h263_encode_init(MpegEncContext *s)
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
const uint16_t ff_h263_format[8][2]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void copy_context_before_encode(MpegEncContext *d, const MpegEncContext *s)
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
double buffer_index
amount of bits in the video/audio buffer
const uint8_t ff_zigzag_direct[64]
static int vshift(enum AVPixelFormat fmt, int plane)
#define AV_CODEC_FLAG_CLOSED_GOP
int(* me_cmp_func)(struct MpegEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
void ff_fdct_ifast(int16_t *data)
const uint16_t ff_inv_aanscales[64]
static void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], int *dmin, int *next_block, int motion_x, int motion_y)
void ff_h263_loop_filter(MpegEncContext *s)
void ff_mpeg1_encode_picture_header(MpegEncContext *s)
#define AV_INPUT_BUFFER_PADDING_SIZE
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free.
void ff_set_mpeg4_time(MpegEncContext *s)
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)
int16_t(* block)[64]
points to one of the following blocks
int dquant
qscale difference to prev qscale
float dark_masking
darkness masking (0-> disabled)
main external API structure.
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
int last_bits
temp var used for calculating the above vars
int qmin
minimum quantizer
static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
static int select_input_picture(MpegEncContext *s)
static int set_bframe_chain_length(MpegEncContext *s)
Determines whether an input picture is discarded or not and if not determines the length of the next ...
float spatial_cplx_masking
spatial complexity masking (0-> disabled)
static void frame_end(MpegEncContext *s)
static void add_dequant_dct(MpegEncContext *s, int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
static int ref[MAX_W *MAX_W]
int ff_mpv_pic_check_linesize(void *logctx, const AVFrame *f, ptrdiff_t *linesizep, ptrdiff_t *uvlinesizep)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static float mean(const float *input, int size)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define FF_MB_DECISION_RD
rate distortion
void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src)
void ff_h263_encode_picture_header(MpegEncContext *s)
@ AV_PICTURE_TYPE_P
Predicted.
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
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...
void ff_convert_matrix(MpegEncContext *s, int(*qmat)[64], uint16_t(*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
Undefined Behavior In the C some operations are like signed integer overflow
void(* fdct)(int16_t *block)
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
float rc_max_available_vbv_use
Ratecontrol attempt to use, at maximum, of what can be used without an underflow.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int dct_quantize_refine(MpegEncContext *s, int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale)
int ff_rv10_encode_picture_header(MpegEncContext *s)
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static void copy_context_after_encode(MpegEncContext *d, const MpegEncContext *s)
int slices
Number of slices.
void ff_h263_update_mb(MpegEncContext *s)
#define FF_MB_DECISION_BITS
chooses the one which needs the fewest bits
This structure stores compressed data.
static void clip_coeffs(MpegEncContext *s, int16_t *block, int last_index)
uint16_t * inter_matrix
custom inter quantization matrix Must be allocated with the av_malloc() family of functions,...
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
int width
picture width / height.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static const double coeff[2][5]
The exact code depends on how similar the blocks are and how related they are to the block
static int sse(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
int misc_bits
cbp, mb_type
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
void ff_get_2pass_fcode(MpegEncContext *s)
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define FF_MPV_FLAG_STRICT_GOP
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
static const uint8_t sp5x_qscale_five_quant_table[][64]
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVWorkPicture *wpic, ScratchpadContext *sc, BufferPoolContext *pools, int mb_height)
Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself) and set the MPVWorkPicture...
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
av_cold AVRefStructPool * ff_mpv_alloc_pic_pool(int init_progress)
Allocate a pool of MPVPictures.
void ff_rv20_encode_picture_header(MpegEncContext *s)
int ff_get_best_fcode(MpegEncContext *s, const int16_t(*mv_table)[2], int type)
const uint16_t ff_aanscales[64]
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
int ff_check_codec_matrices(AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max)
#define FF_MATRIX_TYPE_INTER
static void write_slice_end(MpegEncContext *s)
av_cold void ff_rate_control_uninit(RateControlContext *rcc)