74 #define QUANT_BIAS_SHIFT 8
76 #define QMAT_SHIFT_MMX 16
95 const uint16_t *quant_matrix,
96 int bias,
int qmin,
int qmax,
int intra)
102 for (qscale = qmin; qscale <= qmax; qscale++) {
107 else qscale2 = qscale << 1;
114 for (
i = 0;
i < 64;
i++) {
115 const int j =
s->idsp.idct_permutation[
i];
126 for (
i = 0;
i < 64;
i++) {
127 const int j =
s->idsp.idct_permutation[
i];
135 qmat[qscale][
i] = (
int)((UINT64_C(2) << (
QMAT_SHIFT + 14)) / den);
138 for (
i = 0;
i < 64;
i++) {
139 const int j =
s->idsp.idct_permutation[
i];
151 if (
qmat16[qscale][0][
i] == 0 ||
152 qmat16[qscale][0][
i] == 128 * 256)
153 qmat16[qscale][0][
i] = 128 * 256 - 1;
160 for (
i = intra;
i < 64;
i++) {
165 while (((
max * qmat[qscale][
i]) >>
shift) > INT_MAX) {
172 "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
179 if (
s->q_scale_type == 1 && 0) {
181 int bestdiff=INT_MAX;
189 if (
diff < bestdiff) {
198 s->qscale =
av_clip(
s->qscale,
s->avctx->qmin,
s->vbv_ignore_qmax ? 31 :
s->avctx->qmax);
211 for (
i = 0;
i < 64;
i++) {
223 int8_t *
const qscale_table =
s->current_picture.qscale_table;
226 for (
i = 0;
i <
s->mb_num;
i++) {
227 unsigned int lam =
s->lambda_table[
s->mb_index2xy[
i]];
229 qscale_table[
s->mb_index2xy[
i]] =
av_clip(qp,
s->avctx->qmin,
237 #define COPY(a) dst->a= src->a
239 COPY(current_picture);
245 COPY(picture_in_gop_number);
246 COPY(gop_picture_number);
247 COPY(frame_pred_frame_dct);
248 COPY(progressive_frame);
249 COPY(partitioned_frame);
255 for (
int i = -16;
i < 16;
i++)
274 s->input_picture_number = 0;
275 s->picture_in_gop_number = 0;
285 if (!
s->dct_quantize)
289 s->fast_dct_quantize =
s->dct_quantize;
290 if (
s->avctx->trellis)
301 int i, ret, format_supported;
310 "only YUV420 and YUV422 are supported\n");
316 format_supported = 0;
325 format_supported = 1;
331 format_supported = 1;
333 if (!format_supported) {
343 "only YUV420/YUV422/YUV444 are supported (no alpha support yet)\n");
372 #if FF_API_PRIVATE_OPT
389 "keyframe interval too large!, reducing it from %d to %d\n",
404 s->rtp_mode = !!
s->rtp_payload_size;
408 if (
s->intra_dc_precision < 0) {
409 s->intra_dc_precision += 8;
410 }
else if (
s->intra_dc_precision >= 8)
411 s->intra_dc_precision -= 8;
413 if (
s->intra_dc_precision < 0) {
415 "intra dc precision must be positive, note some applications use"
416 " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n");
429 if (
s->gop_size <= 1) {
477 av_log(avctx,
AV_LOG_ERROR,
"Either both buffer size and max rate or neither must be specified\n");
483 "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
500 "impossible bitrate constraints, this will fail\n");
510 if (!
s->fixed_qscale &&
516 if (nbt <= INT_MAX) {
529 "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
530 "specified vbv buffer is too large for the given bitrate!\n");
542 "OBMC is only supported with simple mb decision\n");
551 if (
s->max_b_frames &&
558 if (
s->max_b_frames < 0) {
560 "max b frames must be 0 or positive for mpegvideo based encoders\n");
570 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
578 (avctx->
width > 2048 ||
584 (avctx->
width > 65535 ||
585 avctx->
height > 65535 )) {
591 ((avctx->
width &3) ||
598 (avctx->
width > 4095 ||
605 (avctx->
width > 16383 ||
606 avctx->
height > 16383 )) {
607 av_log(avctx,
AV_LOG_ERROR,
"MPEG-2 does not support resolutions above 16383x16383\n");
638 #if FF_API_PRIVATE_OPT
649 "mpeg2 style quantization not supported by codec\n");
669 "QP RD is no longer compatible with MJPEG or AMV\n");
673 #if FF_API_PRIVATE_OPT
680 if (
s->scenechange_threshold < 1000000000 &&
683 "closed gop with scene change detection are not supported yet, "
684 "set threshold to 1000000000\n");
692 "low delay forcing is only available for mpeg2, "
693 "set strict_std_compliance to 'unofficial' or lower in order to allow it\n");
696 if (
s->max_b_frames != 0) {
698 "B-frames cannot be used with low delay\n");
703 if (
s->q_scale_type == 1) {
704 if (avctx->
qmax > 28) {
706 "non linear quant only supports qmax <= 28 currently\n");
724 "multi threaded encoding not supported by codec\n");
730 "automatic thread number detection not supported by codec, "
740 #if FF_API_PRIVATE_OPT
751 "notice: b_frame_strategy only affects the first pass\n");
752 s->b_frame_strategy = 0;
766 s->inter_quant_bias = 0;
768 s->intra_quant_bias = 0;
774 av_log(avctx,
AV_LOG_ERROR,
"qmin and or qmax are invalid, they must be 0 < min <= max\n");
778 av_log(avctx,
AV_LOG_DEBUG,
"intra_quant_bias = %d inter_quant_bias = %d\n",
s->intra_quant_bias,
s->inter_quant_bias);
783 "timebase %d/%d not supported by MPEG 4 standard, "
784 "the maximum admitted value for the timebase denominator "
795 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
800 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
829 "The specified picture size of %dx%d is not valid for the "
830 "H.261 codec.\nValid sizes are 176x144, 352x288\n",
831 s->width,
s->height);
843 s->width,
s->height) == 8) {
845 "The specified picture size of %dx%d is not valid for "
846 "the H.263 codec.\nValid sizes are 128x96, 176x144, "
847 "352x288, 704x576, and 1408x1152. "
848 "Try H.263+.\n",
s->width,
s->height);
860 s->modified_quant =
s->h263_aic;
862 s->unrestricted_mv =
s->obmc ||
s->loop_filter ||
s->umvplus;
872 s->unrestricted_mv = 1;
886 s->modified_quant = 1;
890 s->unrestricted_mv = 0;
895 s->unrestricted_mv = 1;
896 s->low_delay =
s->max_b_frames ? 0 : 1;
897 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
902 s->unrestricted_mv = 1;
903 s->msmpeg4_version = 2;
910 s->unrestricted_mv = 1;
911 s->msmpeg4_version = 3;
912 s->flipflop_rounding = 1;
919 s->unrestricted_mv = 1;
920 s->msmpeg4_version = 4;
921 s->flipflop_rounding = 1;
928 s->unrestricted_mv = 1;
929 s->msmpeg4_version = 5;
930 s->flipflop_rounding = 1;
938 #if FF_API_PRIVATE_OPT
949 s->progressive_frame =
954 if (
s->lmin >
s->lmax) {
970 if (
s->msmpeg4_version) {
987 if (
s->noise_reduction) {
997 if (
s->slice_context_count > 1) {
1001 s->h263_slice_structured = 1;
1004 s->quant_precision = 5;
1006 #if FF_API_PRIVATE_OPT
1023 if (!
s->mecc.ildct_cmp[0] || !
s->mecc.ildct_cmp[4])
1026 ret =
ff_set_cmp(&
s->mecc,
s->mecc.frame_skip_cmp,
s->frame_skip_cmp);
1041 for (
i = 0;
i < 64;
i++) {
1042 int j =
s->idsp.idct_permutation[
i];
1048 s->intra_matrix[j] =
1051 s->intra_matrix[j] =
1055 s->chroma_intra_matrix[j] =
1073 s->intra_matrix,
s->intra_quant_bias, avctx->
qmin,
1076 s->inter_matrix,
s->inter_quant_bias, avctx->
qmin,
1083 #if FF_API_PRIVATE_OPT
1093 if (
s->b_frame_strategy == 2) {
1094 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1096 if (!
s->tmp_frames[
i])
1100 s->tmp_frames[
i]->width =
s->width >>
s->brd_scale;
1101 s->tmp_frames[
i]->height =
s->height >>
s->brd_scale;
1143 if(
s->q_chroma_intra_matrix !=
s->q_intra_matrix )
av_freep(&
s->q_chroma_intra_matrix);
1144 if(
s->q_chroma_intra_matrix16 !=
s->q_intra_matrix16)
av_freep(&
s->q_chroma_intra_matrix16);
1145 s->q_chroma_intra_matrix=
NULL;
1146 s->q_chroma_intra_matrix16=
NULL;
1163 for (y = 0; y < 16; y++) {
1164 for (x = 0; x < 16; x++) {
1179 h =
s->height & ~15;
1181 for (y = 0; y <
h; y += 16) {
1182 for (x = 0; x <
w; x += 16) {
1189 acc += sae + 500 < sad;
1198 s->chroma_x_shift,
s->chroma_y_shift,
s->out_format,
1199 s->mb_stride,
s->mb_width,
s->mb_height,
s->b8_stride,
1200 &
s->linesize, &
s->uvlinesize);
1207 int i, display_picture_number = 0, ret;
1208 int encoding_delay =
s->max_b_frames ?
s->max_b_frames
1209 : (
s->low_delay ? 0 : 1);
1210 int flush_offset = 1;
1215 display_picture_number =
s->input_picture_number++;
1219 int64_t last =
s->user_specified_pts;
1223 "Invalid pts (%"PRId64
") <= last (%"PRId64
")\n",
1228 if (!
s->low_delay && display_picture_number == 1)
1229 s->dts_delta =
pts - last;
1231 s->user_specified_pts =
pts;
1234 s->user_specified_pts =
1235 pts =
s->user_specified_pts + 1;
1237 "Warning: AVFrame.pts=? trying to guess (%"PRId64
")\n",
1240 pts = display_picture_number;
1244 if (!pic_arg->
buf[0] ||
1246 pic_arg->
linesize[1] !=
s->uvlinesize ||
1249 if ((
s->width & 15) || (
s->height & 15))
1257 pic_arg->
linesize[1],
s->linesize,
s->uvlinesize);
1263 pic = &
s->picture[
i];
1280 int h_chroma_shift, v_chroma_shift;
1285 for (
i = 0;
i < 3;
i++) {
1286 ptrdiff_t src_stride = pic_arg->
linesize[
i];
1287 ptrdiff_t dst_stride =
i ?
s->uvlinesize :
s->linesize;
1288 int h_shift =
i ? h_chroma_shift : 0;
1289 int v_shift =
i ? v_chroma_shift : 0;
1297 && !
s->progressive_sequence
1298 &&
FFALIGN(
s->height, 32) -
s->height > 16)
1301 if (!
s->avctx->rc_buffer_size)
1304 if (src_stride == dst_stride)
1305 memcpy(dst,
src, src_stride *
h - src_stride +
w);
1310 memcpy(dst2,
src,
w);
1315 if ((
s->width & 15) || (
s->height & (vpad-1))) {
1316 s->mpvencdsp.draw_edges(dst, dst_stride,
1335 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)
1336 if (
s->input_picture[flush_offset])
1339 if (flush_offset <= 1)
1342 encoding_delay = encoding_delay - flush_offset + 1;
1347 s->input_picture[
i - flush_offset] =
s->input_picture[
i];
1349 s->input_picture[
i] =
NULL;
1351 s->input_picture[encoding_delay] = (
Picture*) pic;
1362 for (plane = 0; plane < 3; plane++) {
1364 const int bw = plane ? 1 : 2;
1365 for (y = 0; y <
s->mb_height * bw; y++) {
1366 for (x = 0; x <
s->mb_width * bw; x++) {
1367 int off = p->
shared ? 0 : 16;
1370 int v =
s->mecc.frame_skip_cmp[1](
s, dptr, rptr,
stride, 8);
1372 switch (
FFABS(
s->frame_skip_exp)) {
1373 case 0: score =
FFMAX(score, v);
break;
1374 case 1: score +=
FFABS(v);
break;
1375 case 2: score64 += v * (
int64_t)v;
break;
1386 if (
s->frame_skip_exp < 0)
1387 score64 = pow(score64 / (
double)(
s->mb_width *
s->mb_height),
1388 -1.0/
s->frame_skip_exp);
1390 if (score64 < s->frame_skip_threshold)
1392 if (score64 < ((
s->frame_skip_factor * (
int64_t)
s->lambda) >> 8))
1422 const int scale =
s->brd_scale;
1423 int width =
s->width >> scale;
1424 int height =
s->height >> scale;
1425 int i, j,
out_size, p_lambda, b_lambda, lambda2;
1427 int best_b_count = -1;
1442 b_lambda = p_lambda;
1446 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1447 Picture pre_input, *pre_input_ptr =
i ?
s->input_picture[
i - 1] :
1448 s->next_picture_ptr;
1451 if (pre_input_ptr && (!
i ||
s->input_picture[
i - 1])) {
1452 pre_input = *pre_input_ptr;
1461 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[0],
1462 s->tmp_frames[
i]->linesize[0],
1466 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[1],
1467 s->tmp_frames[
i]->linesize[1],
1471 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[2],
1472 s->tmp_frames[
i]->linesize[2],
1479 for (j = 0; j <
s->max_b_frames + 1; j++) {
1483 if (!
s->input_picture[j])
1496 c->mb_decision =
s->avctx->mb_decision;
1497 c->me_cmp =
s->avctx->me_cmp;
1498 c->mb_cmp =
s->avctx->mb_cmp;
1499 c->me_sub_cmp =
s->avctx->me_sub_cmp;
1501 c->time_base =
s->avctx->time_base;
1502 c->max_b_frames =
s->max_b_frames;
1520 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1521 int is_p =
i % (j + 1) == j ||
i ==
s->max_b_frames;
1523 s->tmp_frames[
i + 1]->pict_type = is_p ?
1525 s->tmp_frames[
i + 1]->quality = is_p ? p_lambda : b_lambda;
1544 rd +=
c->error[0] +
c->error[1] +
c->error[2];
1562 return best_b_count;
1570 s->reordered_input_picture[
i - 1] =
s->reordered_input_picture[
i];
1574 if (!
s->reordered_input_picture[0] &&
s->input_picture[0]) {
1575 if (
s->frame_skip_threshold ||
s->frame_skip_factor) {
1576 if (
s->picture_in_gop_number <
s->gop_size &&
1577 s->next_picture_ptr &&
1589 !
s->next_picture_ptr ||
s->intra_only) {
1590 s->reordered_input_picture[0] =
s->input_picture[0];
1592 s->reordered_input_picture[0]->f->coded_picture_number =
1593 s->coded_picture_number++;
1598 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1599 int pict_num =
s->input_picture[0]->f->display_picture_number +
i;
1601 if (pict_num >=
s->rc_context.num_entries)
1603 if (!
s->input_picture[
i]) {
1608 s->input_picture[
i]->f->pict_type =
1609 s->rc_context.entry[pict_num].new_pict_type;
1613 if (
s->b_frame_strategy == 0) {
1614 b_frames =
s->max_b_frames;
1615 while (b_frames && !
s->input_picture[b_frames])
1617 }
else if (
s->b_frame_strategy == 1) {
1618 for (
i = 1;
i <
s->max_b_frames + 1;
i++) {
1619 if (
s->input_picture[
i] &&
1620 s->input_picture[
i]->b_frame_score == 0) {
1621 s->input_picture[
i]->b_frame_score =
1623 s->input_picture[
i ]->f->data[0],
1624 s->input_picture[
i - 1]->f->data[0],
1628 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1629 if (!
s->input_picture[
i] ||
1630 s->input_picture[
i]->b_frame_score - 1 >
1631 s->mb_num /
s->b_sensitivity)
1635 b_frames =
FFMAX(0,
i - 1);
1638 for (
i = 0;
i < b_frames + 1;
i++) {
1639 s->input_picture[
i]->b_frame_score = 0;
1641 }
else if (
s->b_frame_strategy == 2) {
1651 s->input_picture[b_frames]->f->pts *
s->avctx->time_base.num -
1652 s->last_non_b_time > UINT16_MAX)
1655 for (
i = b_frames - 1;
i >= 0;
i--) {
1656 int type =
s->input_picture[
i]->f->pict_type;
1661 b_frames ==
s->max_b_frames) {
1663 "warning, too many B-frames in a row\n");
1666 if (
s->picture_in_gop_number + b_frames >=
s->gop_size) {
1668 s->gop_size >
s->picture_in_gop_number) {
1669 b_frames =
s->gop_size -
s->picture_in_gop_number - 1;
1681 s->reordered_input_picture[0] =
s->input_picture[b_frames];
1684 s->reordered_input_picture[0]->f->coded_picture_number =
1685 s->coded_picture_number++;
1686 for (
i = 0;
i < b_frames;
i++) {
1687 s->reordered_input_picture[
i + 1] =
s->input_picture[
i];
1688 s->reordered_input_picture[
i + 1]->f->pict_type =
1690 s->reordered_input_picture[
i + 1]->f->coded_picture_number =
1691 s->coded_picture_number++;
1698 if (
s->reordered_input_picture[0]) {
1699 s->reordered_input_picture[0]->reference =
1700 s->reordered_input_picture[0]->f->pict_type !=
1706 if (
s->reordered_input_picture[0]->shared ||
s->avctx->rc_buffer_size) {
1714 pic = &
s->picture[
i];
1716 pic->
reference =
s->reordered_input_picture[0]->reference;
1727 s->reordered_input_picture[0]->shared = 0;
1729 s->current_picture_ptr = pic;
1732 s->current_picture_ptr =
s->reordered_input_picture[0];
1733 for (
i = 0;
i < 4;
i++) {
1734 if (
s->new_picture.f->data[
i])
1740 s->current_picture_ptr)) < 0)
1743 s->picture_number =
s->new_picture.f->display_picture_number;
1750 if (
s->unrestricted_mv &&
1751 s->current_picture.reference &&
1754 int hshift =
desc->log2_chroma_w;
1755 int vshift =
desc->log2_chroma_h;
1756 s->mpvencdsp.draw_edges(
s->current_picture.f->data[0],
1757 s->current_picture.f->linesize[0],
1758 s->h_edge_pos,
s->v_edge_pos,
1761 s->mpvencdsp.draw_edges(
s->current_picture.f->data[1],
1762 s->current_picture.f->linesize[1],
1763 s->h_edge_pos >> hshift,
1764 s->v_edge_pos >> vshift,
1768 s->mpvencdsp.draw_edges(
s->current_picture.f->data[2],
1769 s->current_picture.f->linesize[2],
1770 s->h_edge_pos >> hshift,
1771 s->v_edge_pos >> vshift,
1779 s->last_pict_type =
s->pict_type;
1780 s->last_lambda_for [
s->pict_type] =
s->current_picture_ptr->f->quality;
1782 s->last_non_b_pict_type =
s->pict_type;
1784 #if FF_API_CODED_FRAME
1790 #if FF_API_ERROR_FRAME
1792 memcpy(
s->current_picture.f->error,
s->current_picture.encoding_error,
1793 sizeof(
s->current_picture.encoding_error));
1802 for (intra = 0; intra < 2; intra++) {
1803 if (
s->dct_count[intra] > (1 << 16)) {
1804 for (
i = 0;
i < 64;
i++) {
1805 s->dct_error_sum[intra][
i] >>= 1;
1807 s->dct_count[intra] >>= 1;
1810 for (
i = 0;
i < 64;
i++) {
1811 s->dct_offset[intra][
i] = (
s->noise_reduction *
1812 s->dct_count[intra] +
1813 s->dct_error_sum[intra][
i] / 2) /
1814 (
s->dct_error_sum[intra][
i] + 1);
1825 s->last_picture_ptr !=
s->next_picture_ptr &&
1826 s->last_picture_ptr->f->buf[0]) {
1830 s->current_picture_ptr->f->pict_type =
s->pict_type;
1835 s->current_picture_ptr)) < 0)
1839 s->last_picture_ptr =
s->next_picture_ptr;
1841 s->next_picture_ptr =
s->current_picture_ptr;
1844 if (
s->last_picture_ptr) {
1846 if (
s->last_picture_ptr->f->buf[0] &&
1848 s->last_picture_ptr)) < 0)
1851 if (
s->next_picture_ptr) {
1853 if (
s->next_picture_ptr->f->buf[0] &&
1855 s->next_picture_ptr)) < 0)
1861 for (
i = 0;
i < 4;
i++) {
1863 s->current_picture.f->data[
i] +=
1864 s->current_picture.f->linesize[
i];
1866 s->current_picture.f->linesize[
i] *= 2;
1867 s->last_picture.f->linesize[
i] *= 2;
1868 s->next_picture.f->linesize[
i] *= 2;
1873 s->dct_unquantize_intra =
s->dct_unquantize_mpeg2_intra;
1874 s->dct_unquantize_inter =
s->dct_unquantize_mpeg2_inter;
1876 s->dct_unquantize_intra =
s->dct_unquantize_h263_intra;
1877 s->dct_unquantize_inter =
s->dct_unquantize_h263_inter;
1879 s->dct_unquantize_intra =
s->dct_unquantize_mpeg1_intra;
1880 s->dct_unquantize_inter =
s->dct_unquantize_mpeg1_inter;
1883 if (
s->dct_error_sum) {
1892 const AVFrame *pic_arg,
int *got_packet)
1895 int i, stuffing_count, ret;
1896 int context_count =
s->slice_context_count;
1898 s->vbv_ignore_qmax = 0;
1900 s->picture_in_gop_number++;
1910 if (
s->new_picture.f->data[0]) {
1911 int growing_buffer = context_count == 1 && !
pkt->
data && !
s->data_partitioning;
1920 s->mb_width*
s->mb_height*12);
1921 if (!
s->mb_info_ptr)
1923 s->prev_mb_info =
s->last_mb_info =
s->mb_info_size = 0;
1926 for (
i = 0;
i < context_count;
i++) {
1927 int start_y =
s->thread_context[
i]->start_mb_y;
1928 int end_y =
s->thread_context[
i]-> end_mb_y;
1929 int h =
s->mb_height;
1936 s->pict_type =
s->new_picture.f->pict_type;
1943 if (growing_buffer) {
1951 #if FF_API_STAT_BITS
1960 avctx->
p_count =
s->mb_num -
s->i_count -
s->skip_count;
1977 s->lambda <
s->lmax) {
1978 s->next_lambda =
FFMAX(
s->lambda + min_step,
s->lambda *
1979 (
s->qscale + 1) /
s->qscale);
1980 if (
s->adaptive_quant) {
1982 for (
i = 0;
i <
s->mb_height *
s->mb_stride;
i++)
1983 s->lambda_table[
i] =
1984 FFMAX(
s->lambda_table[
i] + min_step,
1985 s->lambda_table[
i] * (
s->qscale + 1) /
1991 if (
s->flipflop_rounding ||
1994 s->no_rounding ^= 1;
1997 s->time_base =
s->last_time_base;
1998 s->last_non_b_time =
s->time -
s->pp_time;
2000 for (
i = 0;
i < context_count;
i++) {
2004 s->vbv_ignore_qmax = 1;
2015 for (
i = 0;
i < 4;
i++) {
2016 s->current_picture_ptr->encoding_error[
i] =
s->current_picture.encoding_error[
i];
2017 avctx->
error[
i] +=
s->current_picture_ptr->encoding_error[
i];
2020 s->current_picture_ptr->encoding_error,
2026 s->misc_bits +
s->i_tex_bits +
2032 s->stuffing_bits = 8*stuffing_count;
2033 if (stuffing_count) {
2035 stuffing_count + 50) {
2040 switch (
s->codec_id) {
2043 while (stuffing_count--) {
2050 stuffing_count -= 4;
2051 while (stuffing_count--) {
2057 s->stuffing_bits = 0;
2072 int vbv_delay, min_delay;
2075 int minbits =
s->frame_bits - 8 *
2076 (
s->vbv_delay_ptr -
s->pb.buf - 1);
2077 double bits =
s->rc_context.buffer_index + minbits - inbits;
2081 "Internal error, negative bits\n");
2086 min_delay = (minbits * 90000LL + avctx->
rc_max_rate - 1) /
2089 vbv_delay =
FFMAX(vbv_delay, min_delay);
2093 s->vbv_delay_ptr[0] &= 0xF8;
2094 s->vbv_delay_ptr[0] |= vbv_delay >> 13;
2095 s->vbv_delay_ptr[1] = vbv_delay >> 5;
2096 s->vbv_delay_ptr[2] &= 0x07;
2097 s->vbv_delay_ptr[2] |= vbv_delay << 3;
2111 #if FF_API_VBV_DELAY
2117 s->total_bits +=
s->frame_bits;
2118 #if FF_API_STAT_BITS
2125 pkt->
pts =
s->current_picture.f->pts;
2127 if (!
s->current_picture.f->coded_picture_number)
2134 if (
s->current_picture.f->key_frame)
2144 if (!
s->picture[
i].reference)
2156 int n,
int threshold)
2158 static const char tab[64] = {
2159 3, 2, 2, 1, 1, 1, 1, 1,
2160 1, 1, 1, 1, 1, 1, 1, 1,
2161 1, 1, 1, 1, 1, 1, 1, 1,
2162 0, 0, 0, 0, 0, 0, 0, 0,
2163 0, 0, 0, 0, 0, 0, 0, 0,
2164 0, 0, 0, 0, 0, 0, 0, 0,
2165 0, 0, 0, 0, 0, 0, 0, 0,
2166 0, 0, 0, 0, 0, 0, 0, 0
2171 int16_t *
block =
s->block[n];
2172 const int last_index =
s->block_last_index[n];
2175 if (threshold < 0) {
2177 threshold = -threshold;
2182 if (last_index <= skip_dc - 1)
2185 for (
i = 0;
i <= last_index;
i++) {
2186 const int j =
s->intra_scantable.permutated[
i];
2189 if (skip_dc &&
i == 0)
2193 }
else if (
level > 1) {
2199 if (score >= threshold)
2201 for (
i = skip_dc;
i <= last_index;
i++) {
2202 const int j =
s->intra_scantable.permutated[
i];
2206 s->block_last_index[n] = 0;
2208 s->block_last_index[n] = -1;
2215 const int maxlevel =
s->max_qcoeff;
2216 const int minlevel =
s->min_qcoeff;
2224 for (;
i <= last_index;
i++) {
2225 const int j =
s->intra_scantable.permutated[
i];
2228 if (
level > maxlevel) {
2231 }
else if (
level < minlevel) {
2241 "warning, clipping %d dct coefficients to %d..%d\n",
2242 overflow, minlevel, maxlevel);
2249 for (y = 0; y < 8; y++) {
2250 for (x = 0; x < 8; x++) {
2256 for (y2 =
FFMAX(y - 1, 0); y2 <
FFMIN(8, y + 2); y2++) {
2257 for (x2=
FFMAX(x - 1, 0); x2 <
FFMIN(8, x + 2); x2++) {
2258 int v = ptr[x2 + y2 *
stride];
2264 weight[x + 8 * y]= (36 *
ff_sqrt(count * sqr - sum * sum)) / count;
2270 int motion_x,
int motion_y,
2271 int mb_block_height,
2276 int16_t orig[12][64];
2277 const int mb_x =
s->mb_x;
2278 const int mb_y =
s->mb_y;
2281 int dct_offset =
s->linesize * 8;
2282 int uv_dct_offset =
s->uvlinesize * 8;
2283 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
2284 ptrdiff_t wrap_y, wrap_c;
2286 for (
i = 0;
i < mb_block_count;
i++)
2287 skip_dct[
i] =
s->skipdct;
2289 if (
s->adaptive_quant) {
2290 const int last_qp =
s->qscale;
2291 const int mb_xy = mb_x + mb_y *
s->mb_stride;
2293 s->lambda =
s->lambda_table[mb_xy];
2297 s->qscale =
s->current_picture_ptr->qscale_table[mb_xy];
2298 s->dquant =
s->qscale - last_qp;
2319 wrap_y =
s->linesize;
2320 wrap_c =
s->uvlinesize;
2321 ptr_y =
s->new_picture.f->data[0] +
2322 (mb_y * 16 * wrap_y) + mb_x * 16;
2323 ptr_cb =
s->new_picture.f->data[1] +
2324 (mb_y * mb_block_height * wrap_c) + mb_x * mb_block_width;
2325 ptr_cr =
s->new_picture.f->data[2] +
2326 (mb_y * mb_block_height * wrap_c) + mb_x * mb_block_width;
2328 if((mb_x * 16 + 16 >
s->width || mb_y * 16 + 16 >
s->height) &&
s->codec_id !=
AV_CODEC_ID_AMV){
2329 uint8_t *ebuf =
s->sc.edge_emu_buffer + 38 * wrap_y;
2330 int cw = (
s->width +
s->chroma_x_shift) >>
s->chroma_x_shift;
2331 int ch = (
s->height +
s->chroma_y_shift) >>
s->chroma_y_shift;
2332 s->vdsp.emulated_edge_mc(ebuf, ptr_y,
2334 16, 16, mb_x * 16, mb_y * 16,
2335 s->width,
s->height);
2337 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y, ptr_cb,
2339 mb_block_width, mb_block_height,
2340 mb_x * mb_block_width, mb_y * mb_block_height,
2342 ptr_cb = ebuf + 16 * wrap_y;
2343 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y + 16, ptr_cr,
2345 mb_block_width, mb_block_height,
2346 mb_x * mb_block_width, mb_y * mb_block_height,
2348 ptr_cr = ebuf + 16 * wrap_y + 16;
2353 int progressive_score, interlaced_score;
2355 s->interlaced_dct = 0;
2356 progressive_score =
s->mecc.ildct_cmp[4](
s, ptr_y,
NULL, wrap_y, 8) +
2357 s->mecc.ildct_cmp[4](
s, ptr_y + wrap_y * 8,
2358 NULL, wrap_y, 8) - 400;
2360 if (progressive_score > 0) {
2361 interlaced_score =
s->mecc.ildct_cmp[4](
s, ptr_y,
2362 NULL, wrap_y * 2, 8) +
2363 s->mecc.ildct_cmp[4](
s, ptr_y + wrap_y,
2364 NULL, wrap_y * 2, 8);
2365 if (progressive_score > interlaced_score) {
2366 s->interlaced_dct = 1;
2368 dct_offset = wrap_y;
2369 uv_dct_offset = wrap_c;
2378 s->pdsp.get_pixels(
s->block[0], ptr_y, wrap_y);
2379 s->pdsp.get_pixels(
s->block[1], ptr_y + 8, wrap_y);
2380 s->pdsp.get_pixels(
s->block[2], ptr_y + dct_offset, wrap_y);
2381 s->pdsp.get_pixels(
s->block[3], ptr_y + dct_offset + 8, wrap_y);
2387 s->pdsp.get_pixels(
s->block[4], ptr_cb, wrap_c);
2388 s->pdsp.get_pixels(
s->block[5], ptr_cr, wrap_c);
2389 if (!
s->chroma_y_shift &&
s->chroma_x_shift) {
2390 s->pdsp.get_pixels(
s->block[6], ptr_cb + uv_dct_offset, wrap_c);
2391 s->pdsp.get_pixels(
s->block[7], ptr_cr + uv_dct_offset, wrap_c);
2392 }
else if (!
s->chroma_y_shift && !
s->chroma_x_shift) {
2393 s->pdsp.get_pixels(
s->block[ 6], ptr_cb + 8, wrap_c);
2394 s->pdsp.get_pixels(
s->block[ 7], ptr_cr + 8, wrap_c);
2395 s->pdsp.get_pixels(
s->block[ 8], ptr_cb + uv_dct_offset, wrap_c);
2396 s->pdsp.get_pixels(
s->block[ 9], ptr_cr + uv_dct_offset, wrap_c);
2397 s->pdsp.get_pixels(
s->block[10], ptr_cb + uv_dct_offset + 8, wrap_c);
2398 s->pdsp.get_pixels(
s->block[11], ptr_cr + uv_dct_offset + 8, wrap_c);
2404 uint8_t *dest_y, *dest_cb, *dest_cr;
2406 dest_y =
s->dest[0];
2407 dest_cb =
s->dest[1];
2408 dest_cr =
s->dest[2];
2411 op_pix =
s->hdsp.put_pixels_tab;
2412 op_qpix =
s->qdsp.put_qpel_pixels_tab;
2414 op_pix =
s->hdsp.put_no_rnd_pixels_tab;
2415 op_qpix =
s->qdsp.put_no_rnd_qpel_pixels_tab;
2420 s->last_picture.f->data,
2422 op_pix =
s->hdsp.avg_pixels_tab;
2423 op_qpix =
s->qdsp.avg_qpel_pixels_tab;
2427 s->next_picture.f->data,
2432 int progressive_score, interlaced_score;
2434 s->interlaced_dct = 0;
2435 progressive_score =
s->mecc.ildct_cmp[0](
s, dest_y, ptr_y, wrap_y, 8) +
2436 s->mecc.ildct_cmp[0](
s, dest_y + wrap_y * 8,
2441 progressive_score -= 400;
2443 if (progressive_score > 0) {
2444 interlaced_score =
s->mecc.ildct_cmp[0](
s, dest_y, ptr_y,
2446 s->mecc.ildct_cmp[0](
s, dest_y + wrap_y,
2450 if (progressive_score > interlaced_score) {
2451 s->interlaced_dct = 1;
2453 dct_offset = wrap_y;
2454 uv_dct_offset = wrap_c;
2462 s->pdsp.diff_pixels(
s->block[0], ptr_y, dest_y, wrap_y);
2463 s->pdsp.diff_pixels(
s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
2464 s->pdsp.diff_pixels(
s->block[2], ptr_y + dct_offset,
2465 dest_y + dct_offset, wrap_y);
2466 s->pdsp.diff_pixels(
s->block[3], ptr_y + dct_offset + 8,
2467 dest_y + dct_offset + 8, wrap_y);
2473 s->pdsp.diff_pixels(
s->block[4], ptr_cb, dest_cb, wrap_c);
2474 s->pdsp.diff_pixels(
s->block[5], ptr_cr, dest_cr, wrap_c);
2475 if (!
s->chroma_y_shift) {
2476 s->pdsp.diff_pixels(
s->block[6], ptr_cb + uv_dct_offset,
2477 dest_cb + uv_dct_offset, wrap_c);
2478 s->pdsp.diff_pixels(
s->block[7], ptr_cr + uv_dct_offset,
2479 dest_cr + uv_dct_offset, wrap_c);
2483 if (
s->current_picture.mc_mb_var[
s->mb_stride * mb_y + mb_x] <
2484 2 *
s->qscale *
s->qscale) {
2486 if (
s->mecc.sad[1](
NULL, ptr_y, dest_y, wrap_y, 8) < 20 *
s->qscale)
2488 if (
s->mecc.sad[1](
NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 *
s->qscale)
2490 if (
s->mecc.sad[1](
NULL, ptr_y + dct_offset, dest_y + dct_offset,
2491 wrap_y, 8) < 20 *
s->qscale)
2493 if (
s->mecc.sad[1](
NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8,
2494 wrap_y, 8) < 20 *
s->qscale)
2496 if (
s->mecc.sad[1](
NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 *
s->qscale)
2498 if (
s->mecc.sad[1](
NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 *
s->qscale)
2500 if (!
s->chroma_y_shift) {
2501 if (
s->mecc.sad[1](
NULL, ptr_cb + uv_dct_offset,
2502 dest_cb + uv_dct_offset,
2503 wrap_c, 8) < 20 *
s->qscale)
2505 if (
s->mecc.sad[1](
NULL, ptr_cr + uv_dct_offset,
2506 dest_cr + uv_dct_offset,
2507 wrap_c, 8) < 20 *
s->qscale)
2513 if (
s->quantizer_noise_shaping) {
2526 if (!
s->chroma_y_shift) {
2534 memcpy(orig[0],
s->block[0],
sizeof(int16_t) * 64 * mb_block_count);
2540 for (
i = 0;
i < mb_block_count;
i++) {
2543 s->block_last_index[
i] =
s->dct_quantize(
s,
s->block[
i],
i,
s->qscale, &overflow);
2552 s->block_last_index[
i] = -1;
2554 if (
s->quantizer_noise_shaping) {
2555 for (
i = 0;
i < mb_block_count;
i++) {
2557 s->block_last_index[
i] =
2559 orig[
i],
i,
s->qscale);
2564 if (
s->luma_elim_threshold && !
s->mb_intra)
2565 for (
i = 0;
i < 4;
i++)
2567 if (
s->chroma_elim_threshold && !
s->mb_intra)
2568 for (
i = 4;
i < mb_block_count;
i++)
2572 for (
i = 0;
i < mb_block_count;
i++) {
2573 if (
s->block_last_index[
i] == -1)
2574 s->coded_score[
i] = INT_MAX / 256;
2580 s->block_last_index[4] =
2581 s->block_last_index[5] = 0;
2583 s->block[5][0] = (1024 +
s->c_dc_scale / 2) /
s->c_dc_scale;
2584 if (!
s->chroma_y_shift) {
2585 for (
i=6;
i<12;
i++) {
2586 s->block_last_index[
i] = 0;
2587 s->block[
i][0] =
s->block[4][0];
2594 for (
i = 0;
i < mb_block_count;
i++) {
2596 if (
s->block_last_index[
i] > 0) {
2597 for (j = 63; j > 0; j--) {
2598 if (
s->block[
i][
s->intra_scantable.permutated[j]])
2601 s->block_last_index[
i] = j;
2607 switch(
s->codec_id){
2663 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2691 memcpy(d->
mv,
s->mv, 2*4*2*
sizeof(
int));
2692 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2714 if(
s->data_partitioning){
2729 int *dmin,
int *next_block,
int motion_x,
int motion_y)
2736 s->block=
s->blocks[*next_block];
2737 s->pb= pb[*next_block];
2738 if(
s->data_partitioning){
2739 s->pb2 = pb2 [*next_block];
2740 s->tex_pb= tex_pb[*next_block];
2744 memcpy(dest_backup,
s->dest,
sizeof(
s->dest));
2745 s->dest[0] =
s->sc.rd_scratchpad;
2746 s->dest[1] =
s->sc.rd_scratchpad + 16*
s->linesize;
2747 s->dest[2] =
s->sc.rd_scratchpad + 16*
s->linesize + 8;
2754 if(
s->data_partitioning){
2762 score *=
s->lambda2;
2767 memcpy(
s->dest, dest_backup,
sizeof(
s->dest));
2785 else if(
w==8 &&
h==8)
2803 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
2804 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
2808 return s->mecc.nsse[0](
s,
s->new_picture.f->data[0] +
s->mb_x * 16 +
s->mb_y *
s->linesize * 16,
s->dest[0],
s->linesize, 16) +
2809 s->mecc.nsse[1](
s,
s->new_picture.f->data[1] +
s->mb_x * 8 +
s->mb_y *
s->uvlinesize * 8,
s->dest[1],
s->uvlinesize, 8) +
2810 s->mecc.nsse[1](
s,
s->new_picture.f->data[2] +
s->mb_x * 8 +
s->mb_y *
s->uvlinesize * 8,
s->dest[2],
s->uvlinesize, 8);
2812 return s->mecc.sse[0](
NULL,
s->new_picture.f->data[0] +
s->mb_x * 16 +
s->mb_y *
s->linesize * 16,
s->dest[0],
s->linesize, 16) +
2813 s->mecc.sse[1](
NULL,
s->new_picture.f->data[1] +
s->mb_x * 8 +
s->mb_y *
s->uvlinesize * 8,
s->dest[1],
s->uvlinesize, 8) +
2814 s->mecc.sse[1](
NULL,
s->new_picture.f->data[2] +
s->mb_x * 8 +
s->mb_y *
s->uvlinesize * 8,
s->dest[2],
s->uvlinesize, 8);
2817 return sse(
s,
s->new_picture.f->data[0] +
s->mb_x*16 +
s->mb_y*
s->linesize*16,
s->dest[0],
w,
h,
s->linesize)
2818 +
sse(
s,
s->new_picture.f->data[1] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*8,
s->dest[1],
w>>1,
h>>1,
s->uvlinesize)
2819 +
sse(
s,
s->new_picture.f->data[2] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*8,
s->dest[2],
w>>1,
h>>1,
s->uvlinesize);
2827 s->me.dia_size=
s->avctx->pre_dia_size;
2828 s->first_slice_line=1;
2829 for(
s->mb_y=
s->end_mb_y-1;
s->mb_y >=
s->start_mb_y;
s->mb_y--) {
2830 for(
s->mb_x=
s->mb_width-1;
s->mb_x >=0 ;
s->mb_x--) {
2833 s->first_slice_line=0;
2844 s->me.dia_size=
s->avctx->dia_size;
2845 s->first_slice_line=1;
2846 for(
s->mb_y=
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2849 for(
s->mb_x=0;
s->mb_x <
s->mb_width;
s->mb_x++) {
2850 s->block_index[0]+=2;
2851 s->block_index[1]+=2;
2852 s->block_index[2]+=2;
2853 s->block_index[3]+=2;
2861 s->first_slice_line=0;
2870 for(mb_y=
s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
2871 for(mb_x=0; mb_x <
s->mb_width; mb_x++) {
2874 uint8_t *pix =
s->new_picture.f->data[0] + (yy *
s->linesize) + xx;
2876 int sum =
s->mpvencdsp.pix_sum(pix,
s->linesize);
2878 varc = (
s->mpvencdsp.pix_norm1(pix,
s->linesize) -
2879 (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
2881 s->current_picture.mb_var [
s->mb_stride * mb_y + mb_x] = varc;
2882 s->current_picture.mb_mean[
s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
2883 s->me.mb_var_sum_temp += varc;
2891 if(
s->partitioned_frame){
2910 uint8_t *ptr =
s->mb_info_ptr +
s->mb_info_size - 12;
2912 int mba =
s->mb_x +
s->mb_width * (
s->mb_y %
s->gob_index);
2913 int gobn =
s->mb_y /
s->gob_index;
2917 bytestream_put_le32(&ptr,
offset);
2918 bytestream_put_byte(&ptr,
s->qscale);
2919 bytestream_put_byte(&ptr, gobn);
2920 bytestream_put_le16(&ptr, mba);
2921 bytestream_put_byte(&ptr, pred_x);
2922 bytestream_put_byte(&ptr, pred_y);
2924 bytestream_put_byte(&ptr, 0);
2925 bytestream_put_byte(&ptr, 0);
2933 s->mb_info_size += 12;
2934 s->prev_mb_info =
s->last_mb_info;
2938 if (!
s->mb_info_size)
2939 s->mb_info_size += 12;
2946 &&
s->slice_context_count == 1
2947 &&
s->pb.buf ==
s->avctx->internal->byte_buffer) {
2948 int lastgob_pos =
s->ptr_lastgob -
s->pb.buf;
2949 int vbv_pos =
s->vbv_delay_ptr -
s->pb.buf;
2952 int new_buffer_size = 0;
2954 if ((
s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) {
2962 s->avctx->internal->byte_buffer_size + size_increase);
2966 memcpy(new_buffer,
s->avctx->internal->byte_buffer,
s->avctx->internal->byte_buffer_size);
2967 av_free(
s->avctx->internal->byte_buffer);
2968 s->avctx->internal->byte_buffer = new_buffer;
2969 s->avctx->internal->byte_buffer_size = new_buffer_size;
2971 s->ptr_lastgob =
s->pb.buf + lastgob_pos;
2972 s->vbv_delay_ptr =
s->pb.buf + vbv_pos;
2981 int mb_x, mb_y, mb_y_order;
2982 int chr_h= 16>>
s->chroma_y_shift;
3009 s->last_dc[
i] = 128 <<
s->intra_dc_precision;
3011 s->current_picture.encoding_error[
i] = 0;
3014 s->last_dc[0] = 128*8/13;
3015 s->last_dc[1] = 128*8/14;
3016 s->last_dc[2] = 128*8/14;
3019 memset(
s->last_mv, 0,
sizeof(
s->last_mv));
3023 switch(
s->codec_id){
3038 s->first_slice_line = 1;
3039 s->ptr_lastgob =
s->pb.buf;
3040 for (mb_y_order =
s->start_mb_y; mb_y_order < s->end_mb_y; mb_y_order++) {
3044 if (first_in_slice && mb_y_order !=
s->start_mb_y)
3046 s->last_dc[0] =
s->last_dc[1] =
s->last_dc[2] = 1024 <<
s->intra_dc_precision;
3056 for(mb_x=0; mb_x <
s->mb_width; mb_x++) {
3057 int xy= mb_y*
s->mb_stride + mb_x;
3058 int mb_type=
s->mb_type[xy];
3062 int size_increase =
s->avctx->internal->byte_buffer_size/4
3070 if(
s->data_partitioning){
3084 xy=
s->mb_y*
s->mb_stride +
s->mb_x;
3085 mb_type=
s->mb_type[xy];
3090 int current_packet_size, is_gob_start;
3092 current_packet_size= ((
put_bits_count(&
s->pb)+7)>>3) - (
s->ptr_lastgob -
s->pb.buf);
3094 is_gob_start =
s->rtp_payload_size &&
3095 current_packet_size >=
s->rtp_payload_size &&
3098 if(
s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
3100 switch(
s->codec_id){
3103 if(!
s->h263_slice_structured)
3104 if(
s->mb_x ||
s->mb_y%
s->gob_index) is_gob_start=0;
3107 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3109 if(
s->mb_skip_run) is_gob_start=0;
3112 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3117 if(
s->start_mb_y != mb_y || mb_x!=0){
3128 if (
s->error_rate &&
s->resync_mb_x +
s->resync_mb_y > 0) {
3130 int d = 100 /
s->error_rate;
3132 current_packet_size=0;
3133 s->pb.buf_ptr=
s->ptr_lastgob;
3138 #if FF_API_RTP_CALLBACK
3140 if (
s->avctx->rtp_callback){
3141 int number_mb = (mb_y -
s->resync_mb_y)*
s->mb_width + mb_x -
s->resync_mb_x;
3142 s->avctx->rtp_callback(
s->avctx,
s->ptr_lastgob, current_packet_size, number_mb);
3147 switch(
s->codec_id){
3165 s->mb_info_size += 12;
3175 s->misc_bits+=
bits -
s->last_bits;
3179 s->ptr_lastgob += current_packet_size;
3180 s->first_slice_line=1;
3181 s->resync_mb_x=mb_x;
3182 s->resync_mb_y=mb_y;
3186 if( (
s->resync_mb_x ==
s->mb_x)
3187 &&
s->resync_mb_y+1 ==
s->mb_y){
3188 s->first_slice_line=0;
3198 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
3204 if(
s->data_partitioning){
3205 backup_s.pb2=
s->pb2;
3206 backup_s.tex_pb=
s->tex_pb;
3213 s->mv[0][0][0] =
s->p_mv_table[xy][0];
3214 s->mv[0][0][1] =
s->p_mv_table[xy][1];
3216 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3223 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3224 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3225 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3228 &dmin, &next_block, 0, 0);
3237 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3244 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
3245 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
3248 &dmin, &next_block, 0, 0);
3254 s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3255 s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3257 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3263 s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3264 s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3266 &dmin, &next_block,
s->mv[1][0][0],
s->mv[1][0][1]);
3272 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3273 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3274 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3275 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3277 &dmin, &next_block, 0, 0);
3284 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3285 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3286 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3289 &dmin, &next_block, 0, 0);
3296 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3297 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3298 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3301 &dmin, &next_block, 0, 0);
3307 for(dir=0; dir<2; dir++){
3309 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3310 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3311 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3315 &dmin, &next_block, 0, 0);
3324 &dmin, &next_block, 0, 0);
3325 if(
s->h263_pred ||
s->h263_aic){
3327 s->mbintra_table[mb_x + mb_y*
s->mb_stride]=1;
3335 const int last_qp= backup_s.qscale;
3339 static const int dquant_tab[4]={-1,1,-2,2};
3340 int storecoefs =
s->mb_intra &&
s->dc_val[0];
3348 s->mv[0][0][0] = best_s.
mv[0][0][0];
3349 s->mv[0][0][1] = best_s.
mv[0][0][1];
3350 s->mv[1][0][0] = best_s.
mv[1][0][0];
3351 s->mv[1][0][1] = best_s.
mv[1][0][1];
3354 for(; qpi<4; qpi++){
3355 int dquant= dquant_tab[qpi];
3356 qp= last_qp + dquant;
3357 if(qp < s->avctx->qmin || qp >
s->avctx->qmax)
3359 backup_s.dquant= dquant;
3362 dc[
i]=
s->dc_val[0][
s->block_index[
i] ];
3363 memcpy(ac[
i],
s->ac_val[0][
s->block_index[
i]],
sizeof(int16_t)*16);
3368 &dmin, &next_block,
s->mv[mvdir][0][0],
s->mv[mvdir][0][1]);
3372 s->dc_val[0][
s->block_index[
i] ]=
dc[
i];
3373 memcpy(
s->ac_val[0][
s->block_index[
i]], ac[
i],
sizeof(int16_t)*16);
3381 int mx=
s->b_direct_mv_table[xy][0];
3382 int my=
s->b_direct_mv_table[xy][1];
3384 backup_s.dquant = 0;
3389 &dmin, &next_block, mx, my);
3392 backup_s.dquant = 0;
3397 &dmin, &next_block, 0, 0);
3402 coded |=
s->block_last_index[
i];
3405 memcpy(
s->mv, best_s.
mv,
sizeof(
s->mv));
3427 &dmin, &next_block, mx, my);
3432 s->current_picture.qscale_table[xy] = best_s.
qscale;
3438 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
3441 if(
s->data_partitioning){
3444 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
3445 s->pb2= backup_s.pb2;
3449 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
3450 s->tex_pb= backup_s.tex_pb;
3459 s->hdsp.put_pixels_tab[0][0](
s->dest[0],
s->sc.rd_scratchpad ,
s->linesize ,16);
3460 s->hdsp.put_pixels_tab[1][0](
s->dest[1],
s->sc.rd_scratchpad + 16*
s->linesize ,
s->uvlinesize, 8);
3461 s->hdsp.put_pixels_tab[1][0](
s->dest[2],
s->sc.rd_scratchpad + 16*
s->linesize + 8,
s->uvlinesize, 8);
3467 int motion_x = 0, motion_y = 0;
3475 motion_x=
s->mv[0][0][0] = 0;
3476 motion_y=
s->mv[0][0][1] = 0;
3481 motion_x=
s->mv[0][0][0] =
s->p_mv_table[xy][0];
3482 motion_y=
s->mv[0][0][1] =
s->p_mv_table[xy][1];
3489 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3490 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3491 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3499 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
3500 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
3507 motion_x=
s->b_direct_mv_table[xy][0];
3508 motion_y=
s->b_direct_mv_table[xy][1];
3522 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3523 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3524 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3525 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3530 motion_x=
s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3531 motion_y=
s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3536 motion_x=
s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3537 motion_y=
s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3544 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3545 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3546 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3554 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3555 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3556 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3563 for(dir=0; dir<2; dir++){
3565 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3566 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3567 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3578 s->last_mv_dir =
s->mv_dir;
3589 s->p_mv_table[xy][0]=0;
3590 s->p_mv_table[xy][1]=0;
3597 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
3598 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
3600 s->current_picture.encoding_error[0] +=
sse(
3601 s,
s->new_picture.f->data[0] +
s->mb_x*16 +
s->mb_y*
s->linesize*16,
3602 s->dest[0],
w,
h,
s->linesize);
3603 s->current_picture.encoding_error[1] +=
sse(
3604 s,
s->new_picture.f->data[1] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3605 s->dest[1],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3606 s->current_picture.encoding_error[2] +=
sse(
3607 s,
s->new_picture.f->data[2] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3608 s->dest[2],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3614 ff_dlog(
s->avctx,
"MB %d %d bits\n",
3625 #if FF_API_RTP_CALLBACK
3628 if (
s->avctx->rtp_callback) {
3629 int number_mb = (mb_y -
s->resync_mb_y)*
s->mb_width -
s->resync_mb_x;
3633 s->avctx->rtp_callback(
s->avctx,
s->ptr_lastgob, pdif, number_mb);
3641 #define MERGE(field) dst->field += src->field; src->field=0
3651 MERGE(dct_count[0]);
3652 MERGE(dct_count[1]);
3661 MERGE(er.error_count);
3662 MERGE(padding_bug_score);
3663 MERGE(current_picture.encoding_error[0]);
3664 MERGE(current_picture.encoding_error[1]);
3665 MERGE(current_picture.encoding_error[2]);
3668 for(
i=0;
i<64;
i++){
3669 MERGE(dct_error_sum[0][
i]);
3670 MERGE(dct_error_sum[1][
i]);
3681 if (
s->next_lambda){
3682 s->current_picture_ptr->f->quality =
3683 s->current_picture.f->quality =
s->next_lambda;
3684 if(!dry_run)
s->next_lambda= 0;
3685 }
else if (!
s->fixed_qscale) {
3687 s->current_picture_ptr->f->quality =
3688 s->current_picture.f->quality = quality;
3689 if (
s->current_picture.f->quality < 0)
3693 if(
s->adaptive_quant){
3694 switch(
s->codec_id){
3709 s->lambda=
s->lambda_table[0];
3712 s->lambda =
s->current_picture.f->quality;
3720 s->time =
s->current_picture_ptr->f->pts *
s->avctx->time_base.num;
3723 s->pb_time=
s->pp_time - (
s->last_non_b_time -
s->time);
3726 av_assert1(
s->picture_number == 0 ||
s->time >
s->last_non_b_time);
3727 s->pp_time=
s->time -
s->last_non_b_time;
3728 s->last_non_b_time=
s->time;
3736 int context_count =
s->slice_context_count;
3738 s->picture_number = picture_number;
3741 s->me.mb_var_sum_temp =
3742 s->me.mc_mb_var_sum_temp = 0;
3751 s->me.scene_change_score=0;
3756 if(
s->msmpeg4_version >= 3)
s->no_rounding=1;
3757 else s->no_rounding=0;
3760 s->no_rounding ^= 1;
3771 s->lambda=
s->last_lambda_for[
s->pict_type];
3773 s->lambda=
s->last_lambda_for[
s->last_non_b_pict_type];
3778 if(
s->q_chroma_intra_matrix !=
s->q_intra_matrix )
av_freep(&
s->q_chroma_intra_matrix);
3779 if(
s->q_chroma_intra_matrix16 !=
s->q_intra_matrix16)
av_freep(&
s->q_chroma_intra_matrix16);
3780 s->q_chroma_intra_matrix =
s->q_intra_matrix;
3781 s->q_chroma_intra_matrix16 =
s->q_intra_matrix16;
3788 for(
i=1;
i<context_count;
i++){
3796 s->lambda = (
s->lambda *
s->me_penalty_compensation + 128) >> 8;
3797 s->lambda2 = (
s->lambda2 * (
int64_t)
s->me_penalty_compensation + 128) >> 8;
3808 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3811 if(!
s->fixed_qscale){
3813 s->avctx->execute(
s->avctx,
mb_var_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
3816 for(
i=1;
i<context_count;
i++){
3819 s->current_picture.mc_mb_var_sum=
s->current_picture_ptr->mc_mb_var_sum=
s->me.mc_mb_var_sum_temp;
3820 s->current_picture. mb_var_sum=
s->current_picture_ptr-> mb_var_sum=
s->me. mb_var_sum_temp;
3823 if (
s->me.scene_change_score >
s->scenechange_threshold &&
3826 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3828 if(
s->msmpeg4_version >= 3)
3830 ff_dlog(
s,
"Scene change detected, encoding as I Frame %"PRId64
" %"PRId64
"\n",
3831 s->current_picture.mb_var_sum,
s->current_picture.mc_mb_var_sum);
3874 for(dir=0; dir<2; dir++){
3880 s->b_field_mv_table[dir][
i][j], dir ?
s->b_code :
s->f_code,
type, 1);
3891 if (
s->qscale < 3 &&
s->max_qcoeff <= 128 &&
3904 if (
s->avctx->intra_matrix) {
3906 luma_matrix =
s->avctx->intra_matrix;
3908 if (
s->avctx->chroma_intra_matrix)
3909 chroma_matrix =
s->avctx->chroma_intra_matrix;
3913 int j =
s->idsp.idct_permutation[
i];
3915 s->chroma_intra_matrix[j] =
av_clip_uint8((chroma_matrix[
i] *
s->qscale) >> 3);
3918 s->y_dc_scale_table=
3920 s->chroma_intra_matrix[0] =
3923 s->intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3925 s->chroma_intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3929 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};
3930 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};
3937 s->y_dc_scale_table= y;
3938 s->c_dc_scale_table=
c;
3939 s->intra_matrix[0] = 13;
3940 s->chroma_intra_matrix[0] = 14;
3942 s->intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3944 s->chroma_intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3949 s->y_dc_scale_table=
3954 s->current_picture_ptr->f->key_frame =
3956 s->current_picture_ptr->f->pict_type =
3957 s->current_picture.f->pict_type =
s->pict_type;
3959 if (
s->current_picture.f->key_frame)
3960 s->picture_in_gop_number=0;
3962 s->mb_x =
s->mb_y = 0;
3964 switch(
s->out_format) {
3968 s->pred,
s->intra_matrix,
s->chroma_intra_matrix);
4007 s->header_bits=
bits -
s->last_bits;
4009 for(
i=1;
i<context_count;
i++){
4012 s->avctx->execute(
s->avctx,
encode_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
4013 for(
i=1;
i<context_count;
i++){
4014 if (
s->pb.buf_end ==
s->thread_context[
i]->pb.buf)
4023 const int intra=
s->mb_intra;
4026 s->dct_count[intra]++;
4028 for(
i=0;
i<64;
i++){
4033 s->dct_error_sum[intra][
i] +=
level;
4034 level -=
s->dct_offset[intra][
i];
4037 s->dct_error_sum[intra][
i] -=
level;
4038 level +=
s->dct_offset[intra][
i];
4047 int16_t *
block,
int n,
4048 int qscale,
int *overflow){
4050 const uint16_t *matrix;
4052 const uint8_t *perm_scantable;
4054 unsigned int threshold1, threshold2;
4066 int coeff_count[64];
4067 int qmul, qadd, start_i, last_non_zero,
i,
dc;
4068 const int esc_length=
s->ac_esc_length;
4076 if(
s->dct_error_sum)
4079 qadd= ((qscale-1)|1)*8;
4082 else mpeg2_qscale = qscale << 1;
4086 scantable=
s->intra_scantable.scantable;
4087 perm_scantable=
s->intra_scantable.permutated;
4104 qmat = n < 4 ?
s->q_intra_matrix[qscale] :
s->q_chroma_intra_matrix[qscale];
4105 matrix = n < 4 ?
s->intra_matrix :
s->chroma_intra_matrix;
4109 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4110 length =
s->intra_chroma_ac_vlc_length;
4111 last_length=
s->intra_chroma_ac_vlc_last_length;
4113 length =
s->intra_ac_vlc_length;
4114 last_length=
s->intra_ac_vlc_last_length;
4117 scantable=
s->inter_scantable.scantable;
4118 perm_scantable=
s->inter_scantable.permutated;
4121 qmat =
s->q_inter_matrix[qscale];
4122 matrix =
s->inter_matrix;
4123 length =
s->inter_ac_vlc_length;
4124 last_length=
s->inter_ac_vlc_last_length;
4129 threshold2= (threshold1<<1);
4131 for(
i=63;
i>=start_i;
i--) {
4132 const int j = scantable[
i];
4135 if(((
unsigned)(
level+threshold1))>threshold2){
4141 for(
i=start_i;
i<=last_non_zero;
i++) {
4142 const int j = scantable[
i];
4147 if(((
unsigned)(
level+threshold1))>threshold2){
4168 *overflow=
s->max_qcoeff <
max;
4170 if(last_non_zero < start_i){
4171 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4172 return last_non_zero;
4175 score_tab[start_i]= 0;
4176 survivor[0]= start_i;
4179 for(
i=start_i;
i<=last_non_zero;
i++){
4180 int level_index, j, zero_distortion;
4182 int best_score=256*256*256*120;
4186 zero_distortion= dct_coeff*dct_coeff;
4188 for(level_index=0; level_index < coeff_count[
i]; level_index++){
4197 unquant_coeff= alevel*qmul + qadd;
4199 j =
s->idsp.idct_permutation[scantable[
i]];
4200 unquant_coeff = alevel * matrix[j] * 8;
4202 j =
s->idsp.idct_permutation[scantable[
i]];
4204 unquant_coeff = (
int)( alevel * mpeg2_qscale * matrix[j]) >> 4;
4205 unquant_coeff = (unquant_coeff - 1) | 1;
4207 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((
int) matrix[j])) >> 5;
4208 unquant_coeff = (unquant_coeff - 1) | 1;
4213 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
4215 if((
level&(~127)) == 0){
4216 for(j=survivor_count-1; j>=0; j--){
4217 int run=
i - survivor[j];
4219 score += score_tab[
i-
run];
4221 if(score < best_score){
4224 level_tab[
i+1]=
level-64;
4229 for(j=survivor_count-1; j>=0; j--){
4230 int run=
i - survivor[j];
4232 score += score_tab[
i-
run];
4233 if(score < last_score){
4236 last_level=
level-64;
4242 distortion += esc_length*lambda;
4243 for(j=survivor_count-1; j>=0; j--){
4244 int run=
i - survivor[j];
4245 int score= distortion + score_tab[
i-
run];
4247 if(score < best_score){
4250 level_tab[
i+1]=
level-64;
4255 for(j=survivor_count-1; j>=0; j--){
4256 int run=
i - survivor[j];
4257 int score= distortion + score_tab[
i-
run];
4258 if(score < last_score){
4261 last_level=
level-64;
4269 score_tab[
i+1]= best_score;
4272 if(last_non_zero <= 27){
4273 for(; survivor_count; survivor_count--){
4274 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
4278 for(; survivor_count; survivor_count--){
4279 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda)
4284 survivor[ survivor_count++ ]=
i+1;
4288 last_score= 256*256*256*120;
4289 for(
i= survivor[0];
i<=last_non_zero + 1;
i++){
4290 int score= score_tab[
i];
4292 score += lambda * 2;
4294 if(score < last_score){
4297 last_level= level_tab[
i];
4298 last_run= run_tab[
i];
4303 s->coded_score[n] = last_score;
4306 last_non_zero= last_i - 1;
4307 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4309 if(last_non_zero < start_i)
4310 return last_non_zero;
4312 if(last_non_zero == 0 && start_i == 0){
4314 int best_score=
dc *
dc;
4316 for(
i=0;
i<coeff_count[0];
i++){
4319 int unquant_coeff, score, distortion;
4322 unquant_coeff= (alevel*qmul + qadd)>>3;
4324 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((
int) matrix[0])) >> 5;
4325 unquant_coeff = (unquant_coeff - 1) | 1;
4327 unquant_coeff = (unquant_coeff + 4) >> 3;
4328 unquant_coeff<<= 3 + 3;
4330 distortion= (unquant_coeff -
dc) * (unquant_coeff -
dc);
4333 else score= distortion + esc_length*lambda;
4335 if(score < best_score){
4337 best_level=
level - 64;
4340 block[0]= best_level;
4341 s->coded_score[n] = best_score -
dc*
dc;
4342 if(best_level == 0)
return -1;
4343 else return last_non_zero;
4349 block[ perm_scantable[last_non_zero] ]= last_level;
4352 for(;
i>start_i;
i -= run_tab[
i] + 1){
4353 block[ perm_scantable[
i-1] ]= level_tab[
i];
4356 return last_non_zero;
4371 if(
i==0)
s*= sqrt(0.5);
4372 if(j==0)
s*= sqrt(0.5);
4386 const uint8_t *perm_scantable;
4392 int qmul, qadd, start_i, last_non_zero,
i,
dc;
4396 int rle_index,
run, q = 1, sum;
4398 if(
basis[0][0] == 0)
4404 scantable=
s->intra_scantable.scantable;
4405 perm_scantable=
s->intra_scantable.permutated;
4423 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4424 length =
s->intra_chroma_ac_vlc_length;
4425 last_length=
s->intra_chroma_ac_vlc_last_length;
4427 length =
s->intra_ac_vlc_length;
4428 last_length=
s->intra_ac_vlc_last_length;
4431 scantable=
s->inter_scantable.scantable;
4432 perm_scantable=
s->inter_scantable.permutated;
4435 length =
s->inter_ac_vlc_length;
4436 last_length=
s->inter_ac_vlc_last_length;
4438 last_non_zero =
s->block_last_index[n];
4441 for(
i=0;
i<64;
i++){
4446 for(
i=0;
i<64;
i++){
4452 w= 15 + (48*qns*one +
w/2)/
w;
4465 for(
i=start_i;
i<=last_non_zero;
i++){
4466 int j= perm_scantable[
i];
4473 run_tab[rle_index++]=
run;
4483 int best_score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0], 0);
4486 int run2, best_unquant_change=0, analyze_gradient;
4487 analyze_gradient = last_non_zero > 2 ||
s->quantizer_noise_shaping >= 3;
4489 if(analyze_gradient){
4490 for(
i=0;
i<64;
i++){
4500 int change, old_coeff;
4506 for(change=-1; change<=1; change+=2){
4507 int new_level=
level + change;
4508 int score, new_coeff;
4510 new_coeff= q*new_level;
4511 if(new_coeff >= 2048 || new_coeff < 0)
4514 score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0],
4515 new_coeff - old_coeff);
4516 if(score<best_score){
4519 best_change= change;
4520 best_unquant_change= new_coeff - old_coeff;
4527 run2= run_tab[rle_index++];
4531 for(
i=start_i;
i<64;
i++){
4532 int j= perm_scantable[
i];
4534 int change, old_coeff;
4536 if(
s->quantizer_noise_shaping < 3 &&
i > last_non_zero + 1)
4541 else old_coeff= qmul*
level + qadd;
4542 run2= run_tab[rle_index++];
4549 for(change=-1; change<=1; change+=2){
4550 int new_level=
level + change;
4551 int score, new_coeff, unquant_change;
4558 if(new_level<0) new_coeff= qmul*new_level - qadd;
4559 else new_coeff= qmul*new_level + qadd;
4560 if(new_coeff >= 2048 || new_coeff <= -2048)
4565 if(level < 63 && level > -63){
4566 if(
i < last_non_zero)
4576 if(analyze_gradient){
4577 int g= d1[ scantable[
i] ];
4578 if(
g && (
g^new_level) >= 0)
4582 if(
i < last_non_zero){
4583 int next_i=
i + run2 + 1;
4584 int next_level=
block[ perm_scantable[next_i] ] + 64;
4586 if(next_level&(~127))
4589 if(next_i < last_non_zero)
4609 if(
i < last_non_zero){
4610 int next_i=
i + run2 + 1;
4611 int next_level=
block[ perm_scantable[next_i] ] + 64;
4613 if(next_level&(~127))
4616 if(next_i < last_non_zero)
4635 unquant_change= new_coeff - old_coeff;
4636 av_assert2((score < 100*lambda && score > -100*lambda) || lambda==0);
4638 score +=
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[j],
4640 if(score<best_score){
4643 best_change= change;
4644 best_unquant_change= unquant_change;
4648 prev_level=
level + 64;
4649 if(prev_level&(~127))
4659 int j= perm_scantable[ best_coeff ];
4661 block[j] += best_change;
4663 if(best_coeff > last_non_zero){
4664 last_non_zero= best_coeff;
4667 for(; last_non_zero>=start_i; last_non_zero--){
4668 if(
block[perm_scantable[last_non_zero]])
4675 for(
i=start_i;
i<=last_non_zero;
i++){
4676 int j= perm_scantable[
i];
4680 run_tab[rle_index++]=
run;
4687 s->mpvencdsp.add_8x8basis(rem,
basis[j], best_unquant_change);
4693 return last_non_zero;
4708 const uint8_t *scantable,
int last)
4719 for (
i = 0;
i <= last;
i++) {
4720 const int j = scantable[
i];
4725 for (
i = 0;
i <= last;
i++) {
4726 const int j = scantable[
i];
4727 const int perm_j = permutation[j];
4733 int16_t *
block,
int n,
4734 int qscale,
int *overflow)
4736 int i, j,
level, last_non_zero, q, start_i;
4741 unsigned int threshold1, threshold2;
4745 if(
s->dct_error_sum)
4749 scantable=
s->intra_scantable.scantable;
4764 qmat = n < 4 ?
s->q_intra_matrix[qscale] :
s->q_chroma_intra_matrix[qscale];
4767 scantable=
s->inter_scantable.scantable;
4770 qmat =
s->q_inter_matrix[qscale];
4774 threshold2= (threshold1<<1);
4775 for(
i=63;
i>=start_i;
i--) {
4779 if(((
unsigned)(
level+threshold1))>threshold2){
4786 for(
i=start_i;
i<=last_non_zero;
i++) {
4792 if(((
unsigned)(
level+threshold1))>threshold2){
4805 *overflow=
s->max_qcoeff <
max;
4810 scantable, last_non_zero);
4812 return last_non_zero;
4815 #define OFFSET(x) offsetof(MpegEncContext, x)
4816 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4819 {
"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 },
4849 {
"structured_slices",
"Write slice start position at every GOB header instead of just GOB number.",
OFFSET(h263_slice_structured),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE},
4883 .
name =
"msmpeg4v2",
const uint16_t ff_aanscales[64]
const uint16_t ff_inv_aanscales[64]
AAN (Arai, Agui and Nakajima) (I)DCT tables.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define FF_MB_DECISION_RD
rate distortion
#define FF_COMPLIANCE_NORMAL
#define FF_MB_DECISION_BITS
chooses the one which needs the fewest bits
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
#define FF_MB_DECISION_SIMPLE
uses mb_cmp
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
static av_cold int init(AVCodecContext *avctx)
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
#define AV_CEIL_RSHIFT(a, b)
#define ROUNDED_DIV(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define CONFIG_H261_ENCODER
#define CONFIG_WMV2_ENCODER
#define CONFIG_MPEG2VIDEO_ENCODER
#define CONFIG_RV20_ENCODER
#define CONFIG_MPEG1VIDEO_ENCODER
#define CONFIG_SPEEDHQ_ENCODER
#define CONFIG_FLV_ENCODER
#define CONFIG_RV10_ENCODER
#define CONFIG_H263P_ENCODER
#define CONFIG_H263_ENCODER
#define CONFIG_MJPEG_ENCODER
#define CONFIG_MPEG4_ENCODER
void ff_fdct_ifast(int16_t *data)
void ff_jpeg_fdct_islow_10(int16_t *data)
void ff_jpeg_fdct_islow_8(int16_t *data)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
int ff_check_codec_matrices(AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max)
#define FF_MATRIX_TYPE_INTER
#define FF_MATRIX_TYPE_CHROMA_INTRA
#define FF_MATRIX_TYPE_INTRA
Check if the elements of codec context matrices (intra_matrix, inter_matrix or chroma_intra_matrix) a...
void ff_faandct(int16_t *data)
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
#define AV_CODEC_FLAG_QPEL
Use qpel MC.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define AV_CODEC_FLAG_AC_PRED
H.263 advanced intra coding / MPEG-4 AC prediction.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define AV_CODEC_FLAG_4MV
4 MV per MB allowed / advanced prediction for H.263.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
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...
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
FF_ENABLE_DEPRECATION_WARNINGS 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.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
@ 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...
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
void ff_h261_encode_init(MpegEncContext *s)
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_h261_reorder_mb_index(MpegEncContext *s)
int ff_h261_get_picture_format(int width, int height)
void ff_h263_update_motion_val(MpegEncContext *s)
void ff_h263_loop_filter(MpegEncContext *s)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is actually possible in H.263 (limit difference to -2....
void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_h263_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
void ff_h263_encode_init(MpegEncContext *s)
#define H263_GOB_HEIGHT(h)
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
const uint8_t ff_h263_chroma_qscale_table[32]
const uint16_t ff_h263_format[8][2]
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static const int32_t qmat16[MAT_SIZE]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int weight(int i, int blen, int offset)
void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number)
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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.
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define PTRDIFF_SPECIFIER
#define FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
static int ff_thread_once(char *control, void(*routine)(void))
static enum AVPixelFormat pix_fmts[]
const uint8_t ff_zigzag_direct[64]
const uint32_t ff_square_tab[512]
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#define LOCAL_ALIGNED_16(t, v,...)
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64])
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
static const uint8_t mv_bits[2][16][10]
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
void ff_fix_long_p_mvs(MpegEncContext *s, int type)
int ff_init_me(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)
int ff_pre_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
int ff_get_best_fcode(MpegEncContext *s, int16_t(*mv_table)[2], int type)
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
void ff_mpeg1_clean_buffers(MpegEncContext *s)
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], int motion_x, int motion_y)
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_mpeg1_encode_init(MpegEncContext *s)
const uint16_t ff_mpeg1_default_intra_matrix[256]
const uint16_t ff_mpeg1_default_non_intra_matrix[64]
const int16_t ff_mpeg4_default_intra_matrix[64]
const int16_t ff_mpeg4_default_non_intra_matrix[64]
void ff_mpeg4_clean_buffers(MpegEncContext *s)
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
void ff_mpeg4_stuffing(PutBitContext *pbc)
add MPEG-4 stuffing bits (01...1)
void ff_mpeg4_merge_partitions(MpegEncContext *s)
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is actually possible in MPEG-4
int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
void ff_set_mpeg4_time(MpegEncContext *s)
void ff_mpeg4_init_partitions(MpegEncContext *s)
int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, ScratchpadContext *sc, int shared, int encoding, int chroma_x_shift, int chroma_y_shift, int out_format, int mb_stride, int mb_width, int mb_height, int b8_stride, ptrdiff_t *linesize, ptrdiff_t *uvlinesize)
Allocate a Picture.
void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
Deallocate a picture.
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
void ff_free_picture_tables(Picture *pic)
#define MAX_PICTURE_COUNT
#define CANDIDATE_MB_TYPE_INTRA
#define CANDIDATE_MB_TYPE_BACKWARD
#define CANDIDATE_MB_TYPE_FORWARD_I
#define CANDIDATE_MB_TYPE_INTER_I
#define CANDIDATE_MB_TYPE_BIDIR_I
#define CANDIDATE_MB_TYPE_BACKWARD_I
#define CANDIDATE_MB_TYPE_SKIPPED
#define CANDIDATE_MB_TYPE_INTER
#define CANDIDATE_MB_TYPE_DIRECT
#define CANDIDATE_MB_TYPE_BIDIR
#define CANDIDATE_MB_TYPE_FORWARD
#define CANDIDATE_MB_TYPE_INTER4V
#define PICT_BOTTOM_FIELD
#define CANDIDATE_MB_TYPE_DIRECT0
void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
void ff_mpv_common_end(MpegEncContext *s)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
#define FF_MPV_FLAG_CBP_RD
void ff_dct_encode_init_x86(MpegEncContext *s)
static int get_bits_diff(MpegEncContext *s)
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])
#define MV_TYPE_FIELD
2 vectors, one per field
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
#define FF_MPV_FLAG_QP_RD
#define UNI_AC_ENC_INDEX(run, level)
#define FF_MPV_COMMON_OPTS
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
#define MV_TYPE_16X16
1 vector for the whole mb
#define FF_MPV_FLAG_SKIP_RD
static void ff_update_block_index(MpegEncContext *s)
#define FF_MPV_FLAG_STRICT_GOP
static int estimate_qp(MpegEncContext *s, int dry_run)
static void update_noise_reduction(MpegEncContext *s)
static void denoise_dct_c(MpegEncContext *s, int16_t *block)
static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride)
AVCodec ff_msmpeg4v2_encoder
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)
static void set_frame_distances(MpegEncContext *s)
const AVOption ff_mpv_generic_options[]
static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
static const AVClass h263p_class
static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
static int estimate_best_b_count(MpegEncContext *s)
static int mb_var_thread(AVCodecContext *c, void *arg)
static int estimate_motion_thread(AVCodecContext *c, void *arg)
static void update_mb_info(MpegEncContext *s)
static int select_input_picture(MpegEncContext *s)
static const AVOption h263p_options[]
static const AVClass wmv1_class
static const AVClass msmpeg4v3_class
static int encode_frame(AVCodecContext *c, AVFrame *frame, AVPacket *pkt)
int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
static int pre_estimate_motion_thread(AVCodecContext *c, void *arg)
static int get_sae(uint8_t *src, int ref, int stride)
AVCodec ff_msmpeg4v3_encoder
static const AVClass h263_class
static uint8_t default_fcode_tab[MAX_MV *2+1]
static void build_basis(uint8_t *perm)
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)
static int alloc_picture(MpegEncContext *s, Picture *pic, int shared)
static void clip_coeffs(MpegEncContext *s, int16_t *block, int last_index)
static void frame_end(MpegEncContext *s)
static int dct_quantize_refine(MpegEncContext *s, int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale)
static void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type)
static void mpv_encode_init_static(void)
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
static int sse_mb(MpegEncContext *s)
static int frame_start(MpegEncContext *s)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
static void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
static int16_t basis[64][64]
static void mpv_encode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for encoding.
static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
static int encode_picture(MpegEncContext *s, int picture_number)
static const AVOption h263_options[]
void ff_init_qscale_tab(MpegEncContext *s)
init s->current_picture.qscale_table from s->lambda_table
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src)
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
static void write_mb_info(MpegEncContext *s)
void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block according to permutation.
static const AVClass msmpeg4v2_class
static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src)
static void update_qscale(MpegEncContext *s)
static int encode_thread(AVCodecContext *c, void *arg)
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride)
static void write_slice_end(MpegEncContext *s)
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
av_cold int ff_dct_encode_init(MpegEncContext *s)
static int skip_check(MpegEncContext *s, Picture *p, Picture *ref)
static void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type)
static int dct_quantize_trellis_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
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)
const uint8_t *const ff_mpeg2_dc_scale_table[4]
const uint8_t ff_mpeg2_non_linear_qscale[32]
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
void ff_msmpeg4_encode_init(MpegEncContext *s)
#define CONFIG_MSMPEG4_ENCODER
void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_msmpeg4_encode_ext_header(MpegEncContext *s)
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void rebase_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Rebase the bit writer onto a reallocated buffer.
static void set_put_bits_buffer_size(PutBitContext *s, int size)
Change the end of the buffer.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static const int BUF_BITS
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
av_cold int ff_rate_control_init(MpegEncContext *s)
av_cold void ff_rate_control_uninit(MpegEncContext *s)
float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
int ff_vbv_update(MpegEncContext *s, int frame_size)
int ff_get_2pass_fcode(MpegEncContext *s)
void ff_write_pass1_stats(MpegEncContext *s)
int ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number)
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
static const uint8_t sp5x_qscale_five_quant_table[][64]
void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64])
void ff_speedhq_end_slice(MpegEncContext *s)
av_cold int ff_speedhq_encode_init(MpegEncContext *s)
int ff_speedhq_mb_y_order_to_mb(int mb_y_order, int mb_height, int *first_in_slice)
void ff_speedhq_encode_picture_header(MpegEncContext *s)
This structure describes the bitrate properties of an encoded bitstream.
int avg_bitrate
Average bitrate of the stream, in bits per second.
uint64_t vbv_delay
The delay between the time the packet this structure is associated with is received and the time when...
int min_bitrate
Minimum bitrate of the stream, in bits per second.
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int max_bitrate
Maximum bitrate of the stream, in bits per second.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
attribute_deprecated int brd_scale
float rc_max_available_vbv_use
Ratecontrol attempt to use, at maximum, of what can be used without an underflow.
int trellis
trellis RD quantization
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
attribute_deprecated int pre_me
int width
picture width / height.
attribute_deprecated int i_count
char * stats_out
pass1 encoding statistics output buffer
int rc_buffer_size
decoder bitstream buffer size
attribute_deprecated int header_bits
attribute_deprecated int scenechange_threshold
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
attribute_deprecated int frame_bits
attribute_deprecated int mv_bits
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...
int qmin
minimum quantizer
attribute_deprecated int b_sensitivity
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
uint16_t * inter_matrix
custom inter quantization matrix Must be allocated with the av_malloc() family of functions,...
int active_thread_type
Which multithreading methods are in use by the codec.
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
int mb_decision
macroblock decision mode
attribute_deprecated int misc_bits
int has_b_frames
Size of the frame reordering buffer in the decoder.
attribute_deprecated int frame_skip_threshold
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
attribute_deprecated int frame_skip_cmp
attribute_deprecated int p_count
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
attribute_deprecated int mpeg_quant
float temporal_cplx_masking
temporary complexity masking (0-> disabled)
float p_masking
p block masking (0-> disabled)
float dark_masking
darkness masking (0-> disabled)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
attribute_deprecated int rtp_payload_size
int ildct_cmp
interlaced DCT comparison function
int64_t rc_max_rate
maximum bitrate
attribute_deprecated int me_penalty_compensation
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int qmax
maximum quantizer
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
attribute_deprecated int i_tex_bits
int flags
AV_CODEC_FLAG_*.
attribute_deprecated int frame_skip_exp
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
attribute_deprecated int prediction_method
int64_t rc_min_rate
minimum bitrate
int intra_dc_precision
precision of the intra DC coefficient - 8
uint64_t error[AV_NUM_DATA_POINTERS]
error
attribute_deprecated int p_tex_bits
attribute_deprecated int noise_reduction
attribute_deprecated int skip_count
attribute_deprecated int b_frame_strategy
float lumi_masking
luminance masking (0-> disabled)
attribute_deprecated int frame_skip_factor
attribute_deprecated uint64_t vbv_delay
VBV delay coded in the last frame (in periods of a 27 MHz clock).
struct AVCodecInternal * internal
Private context used for internal data.
float spatial_cplx_masking
spatial complexity masking (0-> disabled)
int slices
Number of slices.
unsigned int byte_buffer_size
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int display_picture_number
picture number in display order
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void(* fdct)(int16_t *block)
int partitioned_frame
is current frame partitioned
int16_t(* block)[64]
points to one of the following blocks
PutBitContext tex_pb
used for data partitioned VOPs
int data_partitioning
data partitioning flag from header
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int last_bits
temp var used for calculating the above vars
PutBitContext pb2
used for data partitioned VOPs
int block_last_index[12]
last non zero coefficient in block
int misc_bits
cbp, mb_type
int last_dc[3]
last DC values for MPEG-1
PutBitContext pb
bit output
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
int mb_skipped
MUST BE SET only during DECODING.
int dquant
qscale difference to prev qscale
double buffer_index
amount of bits in the video/audio buffer
static int ref[MAX_W *MAX_W]
static const struct twinvq_data tab
static float mean(const float *input, int size)
static const double coeff[2][5]
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t offset[127][2]
int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)