Go to the documentation of this file.
71 #define QUANT_BIAS_SHIFT 8
73 #define QMAT_SHIFT_MMX 16
92 const uint16_t *quant_matrix,
93 int bias,
int qmin,
int qmax,
int intra)
104 else qscale2 =
qscale << 1;
111 for (
i = 0;
i < 64;
i++) {
112 const int j =
s->idsp.idct_permutation[
i];
113 int64_t den = (int64_t) qscale2 * quant_matrix[j];
123 for (
i = 0;
i < 64;
i++) {
124 const int j =
s->idsp.idct_permutation[
i];
125 int64_t den =
ff_aanscales[
i] * (int64_t) qscale2 * quant_matrix[j];
135 for (
i = 0;
i < 64;
i++) {
136 const int j =
s->idsp.idct_permutation[
i];
137 int64_t den = (int64_t) qscale2 * quant_matrix[j];
157 for (
i = intra;
i < 64;
i++) {
169 "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
176 if (
s->q_scale_type == 1 && 0) {
178 int bestdiff=INT_MAX;
186 if (
diff < bestdiff) {
195 s->qscale = av_clip(
s->qscale,
s->avctx->qmin,
s->vbv_ignore_qmax ? 31 :
s->avctx->qmax);
208 for (
i = 0;
i < 64;
i++) {
220 int8_t *
const qscale_table =
s->current_picture.qscale_table;
223 for (
i = 0;
i <
s->mb_num;
i++) {
224 unsigned int lam =
s->lambda_table[
s->mb_index2xy[
i]];
226 qscale_table[
s->mb_index2xy[
i]] = av_clip(qp,
s->avctx->qmin,
234 #define COPY(a) dst->a= src->a
259 for (
i = -16;
i < 16;
i++) {
265 s->input_picture_number = 0;
266 s->picture_in_gop_number = 0;
276 if (!
s->dct_quantize)
280 s->fast_dct_quantize =
s->dct_quantize;
281 if (
s->avctx->trellis)
292 int i,
ret, format_supported;
301 "only YUV420 and YUV422 are supported\n");
307 format_supported = 0;
316 format_supported = 1;
322 format_supported = 1;
324 if (!format_supported) {
354 #if FF_API_PRIVATE_OPT
371 "keyframe interval too large!, reducing it from %d to %d\n",
386 s->rtp_mode = !!
s->rtp_payload_size;
390 if (
s->intra_dc_precision < 0) {
391 s->intra_dc_precision += 8;
392 }
else if (
s->intra_dc_precision >= 8)
393 s->intra_dc_precision -= 8;
395 if (
s->intra_dc_precision < 0) {
397 "intra dc precision must be positive, note some applications use"
398 " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n");
411 if (
s->gop_size <= 1) {
421 s->adaptive_quant = (
s->avctx->lumi_masking ||
422 s->avctx->dark_masking ||
423 s->avctx->temporal_cplx_masking ||
424 s->avctx->spatial_cplx_masking ||
425 s->avctx->p_masking ||
465 "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
482 "impossible bitrate constraints, this will fail\n");
492 if (!
s->fixed_qscale &&
500 if (
s->avctx->rc_max_rate &&
501 s->avctx->rc_min_rate ==
s->avctx->rc_max_rate &&
505 s->avctx->rc_max_rate * 0xFFFFLL) {
507 "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
508 "specified vbv buffer is too large for the given bitrate!\n");
520 "OBMC is only supported with simple mb decision\n");
529 if (
s->max_b_frames &&
536 if (
s->max_b_frames < 0) {
538 "max b frames must be 0 or positive for mpegvideo based encoders\n");
548 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
610 #if FF_API_PRIVATE_OPT
621 "mpeg2 style quantization not supported by codec\n");
641 "QP RD is no longer compatible with MJPEG or AMV\n");
645 #if FF_API_PRIVATE_OPT
652 if (
s->scenechange_threshold < 1000000000 &&
655 "closed gop with scene change detection are not supported yet, "
656 "set threshold to 1000000000\n");
664 "low delay forcing is only available for mpeg2, "
665 "set strict_std_compliance to 'unofficial' or lower in order to allow it\n");
668 if (
s->max_b_frames != 0) {
670 "B-frames cannot be used with low delay\n");
675 if (
s->q_scale_type == 1) {
678 "non linear quant only supports qmax <= 28 currently\n");
689 if (
s->avctx->thread_count > 1 &&
696 "multi threaded encoding not supported by codec\n");
700 if (
s->avctx->thread_count < 1) {
702 "automatic thread number detection not supported by codec, "
712 #if FF_API_PRIVATE_OPT
723 "notice: b_frame_strategy only affects the first pass\n");
724 s->b_frame_strategy = 0;
738 s->inter_quant_bias = 0;
740 s->intra_quant_bias = 0;
753 s->avctx->time_base.den > (1 << 16) - 1) {
755 "timebase %d/%d not supported by MPEG 4 standard, "
756 "the maximum admitted value for the timebase denominator "
757 "is %d\n",
s->avctx->time_base.num,
s->avctx->time_base.den,
761 s->time_increment_bits =
av_log2(
s->avctx->time_base.den - 1) + 1;
767 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
772 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
791 "The specified picture size of %dx%d is not valid for the "
792 "H.261 codec.\nValid sizes are 176x144, 352x288\n",
793 s->width,
s->height);
805 s->width,
s->height) == 8) {
807 "The specified picture size of %dx%d is not valid for "
808 "the H.263 codec.\nValid sizes are 128x96, 176x144, "
809 "352x288, 704x576, and 1408x1152. "
810 "Try H.263+.\n",
s->width,
s->height);
822 s->modified_quant =
s->h263_aic;
824 s->unrestricted_mv =
s->obmc ||
s->loop_filter ||
s->umvplus;
834 s->unrestricted_mv = 1;
848 s->modified_quant = 1;
852 s->unrestricted_mv = 0;
857 s->unrestricted_mv = 1;
858 s->low_delay =
s->max_b_frames ? 0 : 1;
859 avctx->
delay =
s->low_delay ? 0 : (
s->max_b_frames + 1);
864 s->unrestricted_mv = 1;
865 s->msmpeg4_version = 2;
872 s->unrestricted_mv = 1;
873 s->msmpeg4_version = 3;
874 s->flipflop_rounding = 1;
881 s->unrestricted_mv = 1;
882 s->msmpeg4_version = 4;
883 s->flipflop_rounding = 1;
890 s->unrestricted_mv = 1;
891 s->msmpeg4_version = 5;
892 s->flipflop_rounding = 1;
900 #if FF_API_PRIVATE_OPT
911 s->progressive_frame =
927 if (
s->msmpeg4_version) {
946 if (
s->noise_reduction) {
948 2 * 64 *
sizeof(uint16_t),
fail);
956 if (
s->slice_context_count > 1) {
960 s->h263_slice_structured = 1;
963 s->quant_precision = 5;
965 #if FF_API_PRIVATE_OPT
978 ff_set_cmp(&
s->mecc,
s->mecc.ildct_cmp,
s->avctx->ildct_cmp);
979 ff_set_cmp(&
s->mecc,
s->mecc.frame_skip_cmp,
s->frame_skip_cmp);
993 for (
i = 0;
i < 64;
i++) {
994 int j =
s->idsp.idct_permutation[
i];
1000 s->intra_matrix[j] =
1004 s->chroma_intra_matrix[j] =
1008 if (
s->avctx->intra_matrix)
1009 s->intra_matrix[j] =
s->avctx->intra_matrix[
i];
1010 if (
s->avctx->inter_matrix)
1011 s->inter_matrix[j] =
s->avctx->inter_matrix[
i];
1018 s->intra_matrix,
s->intra_quant_bias,
avctx->
qmin,
1021 s->inter_matrix,
s->inter_quant_bias,
avctx->
qmin,
1028 #if FF_API_PRIVATE_OPT
1038 if (
s->b_frame_strategy == 2) {
1039 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1041 if (!
s->tmp_frames[
i])
1045 s->tmp_frames[
i]->width =
s->width >>
s->brd_scale;
1046 s->tmp_frames[
i]->height =
s->height >>
s->brd_scale;
1090 if(
s->q_chroma_intra_matrix !=
s->q_intra_matrix )
av_freep(&
s->q_chroma_intra_matrix);
1091 if(
s->q_chroma_intra_matrix16 !=
s->q_intra_matrix16)
av_freep(&
s->q_chroma_intra_matrix16);
1092 s->q_chroma_intra_matrix=
NULL;
1093 s->q_chroma_intra_matrix16=
NULL;
1110 for (y = 0; y < 16; y++) {
1111 for (
x = 0;
x < 16;
x++) {
1126 h =
s->height & ~15;
1128 for (y = 0; y <
h; y += 16) {
1129 for (
x = 0;
x <
w;
x += 16) {
1136 acc += sae + 500 < sad;
1145 s->chroma_x_shift,
s->chroma_y_shift,
s->out_format,
1146 s->mb_stride,
s->mb_width,
s->mb_height,
s->b8_stride,
1147 &
s->linesize, &
s->uvlinesize);
1154 int i, display_picture_number = 0,
ret;
1155 int encoding_delay =
s->max_b_frames ?
s->max_b_frames
1156 : (
s->low_delay ? 0 : 1);
1157 int flush_offset = 1;
1162 display_picture_number =
s->input_picture_number++;
1166 int64_t last =
s->user_specified_pts;
1170 "Invalid pts (%"PRId64
") <= last (%"PRId64
")\n",
1175 if (!
s->low_delay && display_picture_number == 1)
1176 s->dts_delta =
pts - last;
1178 s->user_specified_pts =
pts;
1181 s->user_specified_pts =
1182 pts =
s->user_specified_pts + 1;
1184 "Warning: AVFrame.pts=? trying to guess (%"PRId64
")\n",
1187 pts = display_picture_number;
1191 if (!pic_arg->
buf[0] ||
1193 pic_arg->
linesize[1] !=
s->uvlinesize ||
1196 if ((
s->width & 15) || (
s->height & 15))
1204 pic_arg->
linesize[1],
s->linesize,
s->uvlinesize);
1210 pic = &
s->picture[
i];
1227 int h_chroma_shift, v_chroma_shift;
1232 for (
i = 0;
i < 3;
i++) {
1234 int dst_stride =
i ?
s->uvlinesize :
s->linesize;
1235 int h_shift =
i ? h_chroma_shift : 0;
1236 int v_shift =
i ? v_chroma_shift : 0;
1237 int w =
s->width >> h_shift;
1238 int h =
s->height >> v_shift;
1244 && !
s->progressive_sequence
1245 &&
FFALIGN(
s->height, 32) -
s->height > 16)
1248 if (!
s->avctx->rc_buffer_size)
1251 if (src_stride == dst_stride)
1252 memcpy(dst,
src, src_stride *
h);
1257 memcpy(dst2,
src,
w);
1262 if ((
s->width & 15) || (
s->height & (vpad-1))) {
1263 s->mpvencdsp.draw_edges(dst, dst_stride,
1282 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)
1283 if (
s->input_picture[flush_offset])
1286 if (flush_offset <= 1)
1289 encoding_delay = encoding_delay - flush_offset + 1;
1294 s->input_picture[
i - flush_offset] =
s->input_picture[
i];
1296 s->input_picture[encoding_delay] = (
Picture*) pic;
1305 int64_t score64 = 0;
1307 for (plane = 0; plane < 3; plane++) {
1309 const int bw = plane ? 1 : 2;
1310 for (y = 0; y <
s->mb_height * bw; y++) {
1311 for (
x = 0;
x <
s->mb_width * bw;
x++) {
1312 int off = p->
shared ? 0 : 16;
1315 int v =
s->mecc.frame_skip_cmp[1](
s, dptr, rptr,
stride, 8);
1317 switch (
FFABS(
s->frame_skip_exp)) {
1318 case 0: score =
FFMAX(score, v);
break;
1319 case 1: score +=
FFABS(v);
break;
1320 case 2: score64 += v * (int64_t)v;
break;
1321 case 3: score64 +=
FFABS(v * (int64_t)v * v);
break;
1322 case 4: score64 += (v * (int64_t)v) * (v * (int64_t)v);
break;
1331 if (
s->frame_skip_exp < 0)
1332 score64 = pow(score64 / (
double)(
s->mb_width *
s->mb_height),
1333 -1.0/
s->frame_skip_exp);
1337 if (score64 < ((
s->frame_skip_factor * (int64_t)
s->lambda) >> 8))
1369 const int scale =
s->brd_scale;
1370 int width =
s->width >> scale;
1371 int height =
s->height >> scale;
1373 int64_t best_rd = INT64_MAX;
1374 int best_b_count = -1;
1385 b_lambda = p_lambda;
1389 for (
i = 0;
i <
s->max_b_frames + 2;
i++) {
1390 Picture pre_input, *pre_input_ptr =
i ?
s->input_picture[
i - 1] :
1391 s->next_picture_ptr;
1394 if (pre_input_ptr && (!
i ||
s->input_picture[
i - 1])) {
1395 pre_input = *pre_input_ptr;
1404 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[0],
1405 s->tmp_frames[
i]->linesize[0],
1409 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[1],
1410 s->tmp_frames[
i]->linesize[1],
1414 s->mpvencdsp.shrink[scale](
s->tmp_frames[
i]->data[2],
1415 s->tmp_frames[
i]->linesize[2],
1422 for (j = 0; j <
s->max_b_frames + 1; j++) {
1426 if (!
s->input_picture[j])
1437 c->mb_decision =
s->avctx->mb_decision;
1438 c->me_cmp =
s->avctx->me_cmp;
1439 c->mb_cmp =
s->avctx->mb_cmp;
1440 c->me_sub_cmp =
s->avctx->me_sub_cmp;
1442 c->time_base =
s->avctx->time_base;
1443 c->max_b_frames =
s->max_b_frames;
1460 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1461 int is_p =
i % (j + 1) == j ||
i ==
s->max_b_frames;
1463 s->tmp_frames[
i + 1]->pict_type = is_p ?
1465 s->tmp_frames[
i + 1]->quality = is_p ? p_lambda : b_lambda;
1484 rd +=
c->error[0] +
c->error[1] +
c->error[2];
1497 return best_b_count;
1505 s->reordered_input_picture[
i - 1] =
s->reordered_input_picture[
i];
1509 if (!
s->reordered_input_picture[0] &&
s->input_picture[0]) {
1510 if (
s->frame_skip_threshold ||
s->frame_skip_factor) {
1511 if (
s->picture_in_gop_number <
s->gop_size &&
1512 s->next_picture_ptr &&
1524 !
s->next_picture_ptr ||
s->intra_only) {
1525 s->reordered_input_picture[0] =
s->input_picture[0];
1527 s->reordered_input_picture[0]->f->coded_picture_number =
1528 s->coded_picture_number++;
1533 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1534 int pict_num =
s->input_picture[0]->f->display_picture_number +
i;
1536 if (pict_num >=
s->rc_context.num_entries)
1538 if (!
s->input_picture[
i]) {
1543 s->input_picture[
i]->f->pict_type =
1544 s->rc_context.entry[pict_num].new_pict_type;
1548 if (
s->b_frame_strategy == 0) {
1549 b_frames =
s->max_b_frames;
1550 while (b_frames && !
s->input_picture[b_frames])
1552 }
else if (
s->b_frame_strategy == 1) {
1553 for (
i = 1;
i <
s->max_b_frames + 1;
i++) {
1554 if (
s->input_picture[
i] &&
1555 s->input_picture[
i]->b_frame_score == 0) {
1556 s->input_picture[
i]->b_frame_score =
1558 s->input_picture[
i ]->f->data[0],
1559 s->input_picture[
i - 1]->f->data[0],
1563 for (
i = 0;
i <
s->max_b_frames + 1;
i++) {
1564 if (!
s->input_picture[
i] ||
1565 s->input_picture[
i]->b_frame_score - 1 >
1566 s->mb_num /
s->b_sensitivity)
1570 b_frames =
FFMAX(0,
i - 1);
1573 for (
i = 0;
i < b_frames + 1;
i++) {
1574 s->input_picture[
i]->b_frame_score = 0;
1576 }
else if (
s->b_frame_strategy == 2) {
1584 for (
i = b_frames - 1;
i >= 0;
i--) {
1585 int type =
s->input_picture[
i]->f->pict_type;
1590 b_frames ==
s->max_b_frames) {
1592 "warning, too many B-frames in a row\n");
1595 if (
s->picture_in_gop_number + b_frames >=
s->gop_size) {
1597 s->gop_size >
s->picture_in_gop_number) {
1598 b_frames =
s->gop_size -
s->picture_in_gop_number - 1;
1610 s->reordered_input_picture[0] =
s->input_picture[b_frames];
1613 s->reordered_input_picture[0]->f->coded_picture_number =
1614 s->coded_picture_number++;
1615 for (
i = 0;
i < b_frames;
i++) {
1616 s->reordered_input_picture[
i + 1] =
s->input_picture[
i];
1617 s->reordered_input_picture[
i + 1]->f->pict_type =
1619 s->reordered_input_picture[
i + 1]->f->coded_picture_number =
1620 s->coded_picture_number++;
1627 if (
s->reordered_input_picture[0]) {
1628 s->reordered_input_picture[0]->reference =
1629 s->reordered_input_picture[0]->f->pict_type !=
1635 if (
s->reordered_input_picture[0]->shared ||
s->avctx->rc_buffer_size) {
1643 pic = &
s->picture[
i];
1645 pic->
reference =
s->reordered_input_picture[0]->reference;
1656 s->reordered_input_picture[0]->shared = 0;
1658 s->current_picture_ptr = pic;
1661 s->current_picture_ptr =
s->reordered_input_picture[0];
1662 for (
i = 0;
i < 4;
i++) {
1668 s->current_picture_ptr)) < 0)
1671 s->picture_number =
s->new_picture.f->display_picture_number;
1678 if (
s->unrestricted_mv &&
1679 s->current_picture.reference &&
1682 int hshift =
desc->log2_chroma_w;
1683 int vshift =
desc->log2_chroma_h;
1684 s->mpvencdsp.draw_edges(
s->current_picture.f->data[0],
1685 s->current_picture.f->linesize[0],
1686 s->h_edge_pos,
s->v_edge_pos,
1689 s->mpvencdsp.draw_edges(
s->current_picture.f->data[1],
1690 s->current_picture.f->linesize[1],
1691 s->h_edge_pos >> hshift,
1692 s->v_edge_pos >> vshift,
1696 s->mpvencdsp.draw_edges(
s->current_picture.f->data[2],
1697 s->current_picture.f->linesize[2],
1698 s->h_edge_pos >> hshift,
1699 s->v_edge_pos >> vshift,
1707 s->last_pict_type =
s->pict_type;
1708 s->last_lambda_for [
s->pict_type] =
s->current_picture_ptr->f->quality;
1710 s->last_non_b_pict_type =
s->pict_type;
1712 #if FF_API_CODED_FRAME
1718 #if FF_API_ERROR_FRAME
1720 memcpy(
s->current_picture.f->error,
s->current_picture.encoding_error,
1721 sizeof(
s->current_picture.encoding_error));
1730 for (intra = 0; intra < 2; intra++) {
1731 if (
s->dct_count[intra] > (1 << 16)) {
1732 for (
i = 0;
i < 64;
i++) {
1733 s->dct_error_sum[intra][
i] >>= 1;
1735 s->dct_count[intra] >>= 1;
1738 for (
i = 0;
i < 64;
i++) {
1739 s->dct_offset[intra][
i] = (
s->noise_reduction *
1740 s->dct_count[intra] +
1741 s->dct_error_sum[intra][
i] / 2) /
1742 (
s->dct_error_sum[intra][
i] + 1);
1753 s->last_picture_ptr !=
s->next_picture_ptr &&
1754 s->last_picture_ptr->f->buf[0]) {
1758 s->current_picture_ptr->f->pict_type =
s->pict_type;
1763 s->current_picture_ptr)) < 0)
1767 s->last_picture_ptr =
s->next_picture_ptr;
1769 s->next_picture_ptr =
s->current_picture_ptr;
1772 if (
s->last_picture_ptr) {
1774 if (
s->last_picture_ptr->f->buf[0] &&
1776 s->last_picture_ptr)) < 0)
1779 if (
s->next_picture_ptr) {
1781 if (
s->next_picture_ptr->f->buf[0] &&
1783 s->next_picture_ptr)) < 0)
1789 for (
i = 0;
i < 4;
i++) {
1791 s->current_picture.f->data[
i] +=
1792 s->current_picture.f->linesize[
i];
1794 s->current_picture.f->linesize[
i] *= 2;
1795 s->last_picture.f->linesize[
i] *= 2;
1796 s->next_picture.f->linesize[
i] *= 2;
1801 s->dct_unquantize_intra =
s->dct_unquantize_mpeg2_intra;
1802 s->dct_unquantize_inter =
s->dct_unquantize_mpeg2_inter;
1804 s->dct_unquantize_intra =
s->dct_unquantize_h263_intra;
1805 s->dct_unquantize_inter =
s->dct_unquantize_h263_inter;
1807 s->dct_unquantize_intra =
s->dct_unquantize_mpeg1_intra;
1808 s->dct_unquantize_inter =
s->dct_unquantize_mpeg1_inter;
1811 if (
s->dct_error_sum) {
1820 const AVFrame *pic_arg,
int *got_packet)
1823 int i, stuffing_count,
ret;
1824 int context_count =
s->slice_context_count;
1826 s->vbv_ignore_qmax = 0;
1828 s->picture_in_gop_number++;
1838 if (
s->new_picture.f->data[0]) {
1839 int growing_buffer = context_count == 1 && !
pkt->
data && !
s->data_partitioning;
1848 s->mb_width*
s->mb_height*12);
1849 s->prev_mb_info =
s->last_mb_info =
s->mb_info_size = 0;
1852 for (
i = 0;
i < context_count;
i++) {
1853 int start_y =
s->thread_context[
i]->start_mb_y;
1855 int h =
s->mb_height;
1862 s->pict_type =
s->new_picture.f->pict_type;
1869 if (growing_buffer) {
1877 #if FF_API_STAT_BITS
1903 s->lambda <
s->lmax) {
1904 s->next_lambda =
FFMAX(
s->lambda + min_step,
s->lambda *
1905 (
s->qscale + 1) /
s->qscale);
1906 if (
s->adaptive_quant) {
1908 for (
i = 0;
i <
s->mb_height *
s->mb_stride;
i++)
1909 s->lambda_table[
i] =
1910 FFMAX(
s->lambda_table[
i] + min_step,
1911 s->lambda_table[
i] * (
s->qscale + 1) /
1917 if (
s->flipflop_rounding ||
1920 s->no_rounding ^= 1;
1923 s->time_base =
s->last_time_base;
1924 s->last_non_b_time =
s->time -
s->pp_time;
1926 for (
i = 0;
i < context_count;
i++) {
1930 s->vbv_ignore_qmax = 1;
1941 for (
i = 0;
i < 4;
i++) {
1942 s->current_picture_ptr->encoding_error[
i] =
s->current_picture.encoding_error[
i];
1943 avctx->
error[
i] +=
s->current_picture_ptr->encoding_error[
i];
1946 s->current_picture_ptr->encoding_error,
1952 s->misc_bits +
s->i_tex_bits +
1958 s->stuffing_bits = 8*stuffing_count;
1959 if (stuffing_count) {
1961 stuffing_count + 50) {
1966 switch (
s->codec_id) {
1969 while (stuffing_count--) {
1976 stuffing_count -= 4;
1977 while (stuffing_count--) {
1989 if (
s->avctx->rc_max_rate &&
1990 s->avctx->rc_min_rate ==
s->avctx->rc_max_rate &&
1993 s->avctx->rc_max_rate * 0xFFFFLL) {
1998 double inbits =
s->avctx->rc_max_rate *
2000 int minbits =
s->frame_bits - 8 *
2001 (
s->vbv_delay_ptr -
s->pb.buf - 1);
2002 double bits =
s->rc_context.buffer_index + minbits - inbits;
2006 "Internal error, negative bits\n");
2011 min_delay = (minbits * 90000LL +
s->avctx->rc_max_rate - 1) /
2012 s->avctx->rc_max_rate;
2018 s->vbv_delay_ptr[0] &= 0xF8;
2021 s->vbv_delay_ptr[2] &= 0x07;
2036 #if FF_API_VBV_DELAY
2042 s->total_bits +=
s->frame_bits;
2043 #if FF_API_STAT_BITS
2050 pkt->
pts =
s->current_picture.f->pts;
2052 if (!
s->current_picture.f->coded_picture_number)
2059 if (
s->current_picture.f->key_frame)
2069 if (!
s->picture[
i].reference)
2081 int n,
int threshold)
2083 static const char tab[64] = {
2084 3, 2, 2, 1, 1, 1, 1, 1,
2085 1, 1, 1, 1, 1, 1, 1, 1,
2086 1, 1, 1, 1, 1, 1, 1, 1,
2087 0, 0, 0, 0, 0, 0, 0, 0,
2088 0, 0, 0, 0, 0, 0, 0, 0,
2089 0, 0, 0, 0, 0, 0, 0, 0,
2090 0, 0, 0, 0, 0, 0, 0, 0,
2091 0, 0, 0, 0, 0, 0, 0, 0
2096 int16_t *
block =
s->block[n];
2097 const int last_index =
s->block_last_index[n];
2100 if (threshold < 0) {
2102 threshold = -threshold;
2107 if (last_index <= skip_dc - 1)
2110 for (
i = 0;
i <= last_index;
i++) {
2111 const int j =
s->intra_scantable.permutated[
i];
2114 if (skip_dc &&
i == 0)
2118 }
else if (
level > 1) {
2124 if (score >= threshold)
2126 for (
i = skip_dc;
i <= last_index;
i++) {
2127 const int j =
s->intra_scantable.permutated[
i];
2131 s->block_last_index[n] = 0;
2133 s->block_last_index[n] = -1;
2140 const int maxlevel =
s->max_qcoeff;
2141 const int minlevel =
s->min_qcoeff;
2149 for (;
i <= last_index;
i++) {
2150 const int j =
s->intra_scantable.permutated[
i];
2153 if (
level > maxlevel) {
2156 }
else if (
level < minlevel) {
2166 "warning, clipping %d dct coefficients to %d..%d\n",
2174 for (y = 0; y < 8; y++) {
2175 for (
x = 0;
x < 8;
x++) {
2181 for (y2 =
FFMAX(y - 1, 0); y2 <
FFMIN(8, y + 2); y2++) {
2182 for (x2=
FFMAX(
x - 1, 0); x2 <
FFMIN(8,
x + 2); x2++) {
2183 int v = ptr[x2 + y2 *
stride];
2189 weight[
x + 8 * y]= (36 *
ff_sqrt(count * sqr - sum * sum)) / count;
2195 int motion_x,
int motion_y,
2196 int mb_block_height,
2201 int16_t orig[12][64];
2202 const int mb_x =
s->mb_x;
2203 const int mb_y =
s->mb_y;
2207 int uv_dct_offset =
s->uvlinesize * 8;
2208 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
2209 ptrdiff_t wrap_y, wrap_c;
2211 for (
i = 0;
i < mb_block_count;
i++)
2212 skip_dct[
i] =
s->skipdct;
2214 if (
s->adaptive_quant) {
2215 const int last_qp =
s->qscale;
2216 const int mb_xy =
mb_x +
mb_y *
s->mb_stride;
2218 s->lambda =
s->lambda_table[mb_xy];
2222 s->qscale =
s->current_picture_ptr->qscale_table[mb_xy];
2223 s->dquant =
s->qscale - last_qp;
2226 s->dquant = av_clip(
s->dquant, -2, 2);
2244 wrap_y =
s->linesize;
2245 wrap_c =
s->uvlinesize;
2246 ptr_y =
s->new_picture.f->data[0] +
2248 ptr_cb =
s->new_picture.f->data[1] +
2249 (
mb_y * mb_block_height * wrap_c) +
mb_x * mb_block_width;
2250 ptr_cr =
s->new_picture.f->data[2] +
2251 (
mb_y * mb_block_height * wrap_c) +
mb_x * mb_block_width;
2254 uint8_t *ebuf =
s->sc.edge_emu_buffer + 38 * wrap_y;
2255 int cw = (
s->width +
s->chroma_x_shift) >>
s->chroma_x_shift;
2256 int ch = (
s->height +
s->chroma_y_shift) >>
s->chroma_y_shift;
2257 s->vdsp.emulated_edge_mc(ebuf, ptr_y,
2260 s->width,
s->height);
2262 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y, ptr_cb,
2264 mb_block_width, mb_block_height,
2265 mb_x * mb_block_width,
mb_y * mb_block_height,
2267 ptr_cb = ebuf + 16 * wrap_y;
2268 s->vdsp.emulated_edge_mc(ebuf + 16 * wrap_y + 16, ptr_cr,
2270 mb_block_width, mb_block_height,
2271 mb_x * mb_block_width,
mb_y * mb_block_height,
2273 ptr_cr = ebuf + 16 * wrap_y + 16;
2278 int progressive_score, interlaced_score;
2280 s->interlaced_dct = 0;
2281 progressive_score =
s->mecc.ildct_cmp[4](
s, ptr_y,
NULL, wrap_y, 8) +
2282 s->mecc.ildct_cmp[4](
s, ptr_y + wrap_y * 8,
2283 NULL, wrap_y, 8) - 400;
2285 if (progressive_score > 0) {
2286 interlaced_score =
s->mecc.ildct_cmp[4](
s, ptr_y,
2287 NULL, wrap_y * 2, 8) +
2288 s->mecc.ildct_cmp[4](
s, ptr_y + wrap_y,
2289 NULL, wrap_y * 2, 8);
2290 if (progressive_score > interlaced_score) {
2291 s->interlaced_dct = 1;
2294 uv_dct_offset = wrap_c;
2303 s->pdsp.get_pixels(
s->block[0], ptr_y, wrap_y);
2304 s->pdsp.get_pixels(
s->block[1], ptr_y + 8, wrap_y);
2305 s->pdsp.get_pixels(
s->block[2], ptr_y +
dct_offset, wrap_y);
2306 s->pdsp.get_pixels(
s->block[3], ptr_y +
dct_offset + 8, wrap_y);
2312 s->pdsp.get_pixels(
s->block[4], ptr_cb, wrap_c);
2313 s->pdsp.get_pixels(
s->block[5], ptr_cr, wrap_c);
2314 if (!
s->chroma_y_shift &&
s->chroma_x_shift) {
2315 s->pdsp.get_pixels(
s->block[6], ptr_cb + uv_dct_offset, wrap_c);
2316 s->pdsp.get_pixels(
s->block[7], ptr_cr + uv_dct_offset, wrap_c);
2317 }
else if (!
s->chroma_y_shift && !
s->chroma_x_shift) {
2318 s->pdsp.get_pixels(
s->block[ 6], ptr_cb + 8, wrap_c);
2319 s->pdsp.get_pixels(
s->block[ 7], ptr_cr + 8, wrap_c);
2320 s->pdsp.get_pixels(
s->block[ 8], ptr_cb + uv_dct_offset, wrap_c);
2321 s->pdsp.get_pixels(
s->block[ 9], ptr_cr + uv_dct_offset, wrap_c);
2322 s->pdsp.get_pixels(
s->block[10], ptr_cb + uv_dct_offset + 8, wrap_c);
2323 s->pdsp.get_pixels(
s->block[11], ptr_cr + uv_dct_offset + 8, wrap_c);
2329 uint8_t *dest_y, *dest_cb, *dest_cr;
2331 dest_y =
s->dest[0];
2332 dest_cb =
s->dest[1];
2333 dest_cr =
s->dest[2];
2336 op_pix =
s->hdsp.put_pixels_tab;
2337 op_qpix =
s->qdsp.put_qpel_pixels_tab;
2339 op_pix =
s->hdsp.put_no_rnd_pixels_tab;
2340 op_qpix =
s->qdsp.put_no_rnd_qpel_pixels_tab;
2345 s->last_picture.f->data,
2347 op_pix =
s->hdsp.avg_pixels_tab;
2348 op_qpix =
s->qdsp.avg_qpel_pixels_tab;
2352 s->next_picture.f->data,
2357 int progressive_score, interlaced_score;
2359 s->interlaced_dct = 0;
2360 progressive_score =
s->mecc.ildct_cmp[0](
s, dest_y, ptr_y, wrap_y, 8) +
2361 s->mecc.ildct_cmp[0](
s, dest_y + wrap_y * 8,
2366 progressive_score -= 400;
2368 if (progressive_score > 0) {
2369 interlaced_score =
s->mecc.ildct_cmp[0](
s, dest_y, ptr_y,
2371 s->mecc.ildct_cmp[0](
s, dest_y + wrap_y,
2375 if (progressive_score > interlaced_score) {
2376 s->interlaced_dct = 1;
2379 uv_dct_offset = wrap_c;
2387 s->pdsp.diff_pixels(
s->block[0], ptr_y, dest_y, wrap_y);
2388 s->pdsp.diff_pixels(
s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
2391 s->pdsp.diff_pixels(
s->block[3], ptr_y +
dct_offset + 8,
2398 s->pdsp.diff_pixels(
s->block[4], ptr_cb, dest_cb, wrap_c);
2399 s->pdsp.diff_pixels(
s->block[5], ptr_cr, dest_cr, wrap_c);
2400 if (!
s->chroma_y_shift) {
2401 s->pdsp.diff_pixels(
s->block[6], ptr_cb + uv_dct_offset,
2402 dest_cb + uv_dct_offset, wrap_c);
2403 s->pdsp.diff_pixels(
s->block[7], ptr_cr + uv_dct_offset,
2404 dest_cr + uv_dct_offset, wrap_c);
2408 if (
s->current_picture.mc_mb_var[
s->mb_stride *
mb_y +
mb_x] <
2409 2 *
s->qscale *
s->qscale) {
2411 if (
s->mecc.sad[1](
NULL, ptr_y, dest_y, wrap_y, 8) < 20 *
s->qscale)
2413 if (
s->mecc.sad[1](
NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 *
s->qscale)
2416 wrap_y, 8) < 20 *
s->qscale)
2419 wrap_y, 8) < 20 *
s->qscale)
2421 if (
s->mecc.sad[1](
NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 *
s->qscale)
2423 if (
s->mecc.sad[1](
NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 *
s->qscale)
2425 if (!
s->chroma_y_shift) {
2426 if (
s->mecc.sad[1](
NULL, ptr_cb + uv_dct_offset,
2427 dest_cb + uv_dct_offset,
2428 wrap_c, 8) < 20 *
s->qscale)
2430 if (
s->mecc.sad[1](
NULL, ptr_cr + uv_dct_offset,
2431 dest_cr + uv_dct_offset,
2432 wrap_c, 8) < 20 *
s->qscale)
2438 if (
s->quantizer_noise_shaping) {
2451 if (!
s->chroma_y_shift) {
2459 memcpy(orig[0],
s->block[0],
sizeof(int16_t) * 64 * mb_block_count);
2465 for (
i = 0;
i < mb_block_count;
i++) {
2468 s->block_last_index[
i] =
s->dct_quantize(
s,
s->block[
i],
i,
s->qscale, &
overflow);
2477 s->block_last_index[
i] = -1;
2479 if (
s->quantizer_noise_shaping) {
2480 for (
i = 0;
i < mb_block_count;
i++) {
2482 s->block_last_index[
i] =
2484 orig[
i],
i,
s->qscale);
2489 if (
s->luma_elim_threshold && !
s->mb_intra)
2490 for (
i = 0;
i < 4;
i++)
2492 if (
s->chroma_elim_threshold && !
s->mb_intra)
2493 for (
i = 4;
i < mb_block_count;
i++)
2497 for (
i = 0;
i < mb_block_count;
i++) {
2498 if (
s->block_last_index[
i] == -1)
2499 s->coded_score[
i] = INT_MAX / 256;
2505 s->block_last_index[4] =
2506 s->block_last_index[5] = 0;
2508 s->block[5][0] = (1024 +
s->c_dc_scale / 2) /
s->c_dc_scale;
2509 if (!
s->chroma_y_shift) {
2510 for (
i=6;
i<12;
i++) {
2511 s->block_last_index[
i] = 0;
2512 s->block[
i][0] =
s->block[4][0];
2519 for (
i = 0;
i < mb_block_count;
i++) {
2521 if (
s->block_last_index[
i] > 0) {
2522 for (j = 63; j > 0; j--) {
2523 if (
s->block[
i][
s->intra_scantable.permutated[j]])
2526 s->block_last_index[
i] = j;
2532 switch(
s->codec_id){
2584 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2612 memcpy(d->
mv,
s->mv, 2*4*2*
sizeof(
int));
2613 memcpy(d->
last_mv,
s->last_mv, 2*2*2*
sizeof(
int));
2635 if(
s->data_partitioning){
2650 int *dmin,
int *next_block,
int motion_x,
int motion_y)
2657 s->block=
s->blocks[*next_block];
2658 s->pb=
pb[*next_block];
2659 if(
s->data_partitioning){
2660 s->pb2 =
pb2 [*next_block];
2661 s->tex_pb=
tex_pb[*next_block];
2665 memcpy(dest_backup,
s->dest,
sizeof(
s->dest));
2666 s->dest[0] =
s->sc.rd_scratchpad;
2667 s->dest[1] =
s->sc.rd_scratchpad + 16*
s->linesize;
2668 s->dest[2] =
s->sc.rd_scratchpad + 16*
s->linesize + 8;
2675 if(
s->data_partitioning){
2683 score *=
s->lambda2;
2688 memcpy(
s->dest, dest_backup,
sizeof(
s->dest));
2706 else if(
w==8 &&
h==8)
2724 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
2725 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
2729 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) +
2730 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) +
2731 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);
2733 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) +
2734 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) +
2735 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);
2738 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)
2739 +
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)
2740 +
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);
2748 s->me.dia_size=
s->avctx->pre_dia_size;
2749 s->first_slice_line=1;
2750 for(
s->mb_y=
s->end_mb_y-1;
s->mb_y >=
s->start_mb_y;
s->mb_y--) {
2751 for(
s->mb_x=
s->mb_width-1;
s->mb_x >=0 ;
s->mb_x--) {
2754 s->first_slice_line=0;
2767 s->me.dia_size=
s->avctx->dia_size;
2768 s->first_slice_line=1;
2769 for(
s->mb_y=
s->start_mb_y;
s->mb_y <
s->end_mb_y;
s->mb_y++) {
2772 for(
s->mb_x=0;
s->mb_x <
s->mb_width;
s->mb_x++) {
2773 s->block_index[0]+=2;
2774 s->block_index[1]+=2;
2775 s->block_index[2]+=2;
2776 s->block_index[3]+=2;
2784 s->first_slice_line=0;
2799 uint8_t *pix =
s->new_picture.f->data[0] + (yy *
s->linesize) + xx;
2801 int sum =
s->mpvencdsp.pix_sum(pix,
s->linesize);
2803 varc = (
s->mpvencdsp.pix_norm1(pix,
s->linesize) -
2804 (((unsigned) sum * sum) >> 8) + 500 + 128) >> 8;
2806 s->current_picture.mb_var [
s->mb_stride *
mb_y +
mb_x] = varc;
2807 s->current_picture.mb_mean[
s->mb_stride *
mb_y +
mb_x] = (sum+128)>>8;
2808 s->me.mb_var_sum_temp += varc;
2816 if(
s->partitioned_frame){
2834 uint8_t *ptr =
s->mb_info_ptr +
s->mb_info_size - 12;
2836 int mba =
s->mb_x +
s->mb_width * (
s->mb_y %
s->gob_index);
2837 int gobn =
s->mb_y /
s->gob_index;
2841 bytestream_put_le32(&ptr,
offset);
2842 bytestream_put_byte(&ptr,
s->qscale);
2843 bytestream_put_byte(&ptr, gobn);
2844 bytestream_put_le16(&ptr, mba);
2845 bytestream_put_byte(&ptr, pred_x);
2846 bytestream_put_byte(&ptr, pred_y);
2848 bytestream_put_byte(&ptr, 0);
2849 bytestream_put_byte(&ptr, 0);
2857 s->mb_info_size += 12;
2858 s->prev_mb_info =
s->last_mb_info;
2870 if (!
s->mb_info_size)
2871 s->mb_info_size += 12;
2878 &&
s->slice_context_count == 1
2879 &&
s->pb.buf ==
s->avctx->internal->byte_buffer) {
2880 int lastgob_pos =
s->ptr_lastgob -
s->pb.buf;
2881 int vbv_pos =
s->vbv_delay_ptr -
s->pb.buf;
2884 int new_buffer_size = 0;
2886 if ((
s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) {
2894 s->avctx->internal->byte_buffer_size + size_increase);
2898 memcpy(new_buffer,
s->avctx->internal->byte_buffer,
s->avctx->internal->byte_buffer_size);
2899 av_free(
s->avctx->internal->byte_buffer);
2900 s->avctx->internal->byte_buffer = new_buffer;
2901 s->avctx->internal->byte_buffer_size = new_buffer_size;
2903 s->ptr_lastgob =
s->pb.buf + lastgob_pos;
2904 s->vbv_delay_ptr =
s->pb.buf + vbv_pos;
2914 int chr_h= 16>>
s->chroma_y_shift;
2943 s->last_dc[
i] = 128 <<
s->intra_dc_precision;
2945 s->current_picture.encoding_error[
i] = 0;
2948 s->last_dc[0] = 128*8/13;
2949 s->last_dc[1] = 128*8/14;
2950 s->last_dc[2] = 128*8/14;
2953 memset(
s->last_mv, 0,
sizeof(
s->last_mv));
2957 switch(
s->codec_id){
2972 s->first_slice_line = 1;
2973 s->ptr_lastgob =
s->pb.buf;
2987 int size_increase =
s->avctx->internal->byte_buffer_size/4
2995 if(
s->data_partitioning){
3009 xy=
s->mb_y*
s->mb_stride +
s->mb_x;
3015 int current_packet_size, is_gob_start;
3017 current_packet_size= ((
put_bits_count(&
s->pb)+7)>>3) - (
s->ptr_lastgob -
s->pb.buf);
3019 is_gob_start =
s->rtp_payload_size &&
3020 current_packet_size >=
s->rtp_payload_size &&
3023 if(
s->start_mb_y ==
mb_y &&
mb_y > 0 &&
mb_x==0) is_gob_start=1;
3025 switch(
s->codec_id){
3028 if(!
s->h263_slice_structured)
3029 if(
s->mb_x ||
s->mb_y%
s->gob_index) is_gob_start=0;
3032 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3034 if(
s->mb_skip_run) is_gob_start=0;
3037 if(
s->mb_x==0 &&
s->mb_y!=0) is_gob_start=1;
3053 if (
s->error_rate &&
s->resync_mb_x +
s->resync_mb_y > 0) {
3055 int d = 100 /
s->error_rate;
3057 current_packet_size=0;
3058 s->pb.buf_ptr=
s->ptr_lastgob;
3063 #if FF_API_RTP_CALLBACK
3065 if (
s->avctx->rtp_callback){
3066 int number_mb = (
mb_y -
s->resync_mb_y)*
s->mb_width +
mb_x -
s->resync_mb_x;
3067 s->avctx->rtp_callback(
s->avctx,
s->ptr_lastgob, current_packet_size, number_mb);
3073 switch(
s->codec_id){
3096 s->misc_bits+=
bits -
s->last_bits;
3100 s->ptr_lastgob += current_packet_size;
3101 s->first_slice_line=1;
3102 s->resync_mb_x=
mb_x;
3103 s->resync_mb_y=
mb_y;
3107 if( (
s->resync_mb_x ==
s->mb_x)
3108 &&
s->resync_mb_y+1 ==
s->mb_y){
3109 s->first_slice_line=0;
3119 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
3125 if(
s->data_partitioning){
3126 backup_s.pb2=
s->pb2;
3127 backup_s.tex_pb=
s->tex_pb;
3134 s->mv[0][0][0] =
s->p_mv_table[xy][0];
3135 s->mv[0][0][1] =
s->p_mv_table[xy][1];
3137 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3144 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3145 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3146 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3149 &dmin, &next_block, 0, 0);
3158 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3165 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
3166 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
3169 &dmin, &next_block, 0, 0);
3175 s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3176 s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3178 &dmin, &next_block,
s->mv[0][0][0],
s->mv[0][0][1]);
3184 s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3185 s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3187 &dmin, &next_block,
s->mv[1][0][0],
s->mv[1][0][1]);
3193 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3194 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3195 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3196 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3198 &dmin, &next_block, 0, 0);
3205 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3206 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3207 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3210 &dmin, &next_block, 0, 0);
3217 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3218 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3219 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3222 &dmin, &next_block, 0, 0);
3228 for(dir=0; dir<2; dir++){
3230 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3231 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3232 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3236 &dmin, &next_block, 0, 0);
3245 &dmin, &next_block, 0, 0);
3246 if(
s->h263_pred ||
s->h263_aic){
3248 s->mbintra_table[
mb_x +
mb_y*
s->mb_stride]=1;
3256 const int last_qp= backup_s.qscale;
3260 static const int dquant_tab[4]={-1,1,-2,2};
3261 int storecoefs =
s->mb_intra &&
s->dc_val[0];
3269 s->mv[0][0][0] = best_s.
mv[0][0][0];
3270 s->mv[0][0][1] = best_s.
mv[0][0][1];
3271 s->mv[1][0][0] = best_s.
mv[1][0][0];
3272 s->mv[1][0][1] = best_s.
mv[1][0][1];
3275 for(; qpi<4; qpi++){
3276 int dquant= dquant_tab[qpi];
3278 if(qp < s->
avctx->
qmin || qp >
s->avctx->qmax)
3283 dc[
i]=
s->dc_val[0][
s->block_index[
i] ];
3284 memcpy(ac[
i],
s->ac_val[0][
s->block_index[
i]],
sizeof(int16_t)*16);
3289 &dmin, &next_block,
s->mv[mvdir][0][0],
s->mv[mvdir][0][1]);
3293 s->dc_val[0][
s->block_index[
i] ]=
dc[
i];
3294 memcpy(
s->ac_val[0][
s->block_index[
i]], ac[
i],
sizeof(int16_t)*16);
3302 int mx=
s->b_direct_mv_table[xy][0];
3303 int my=
s->b_direct_mv_table[xy][1];
3305 backup_s.dquant = 0;
3310 &dmin, &next_block, mx, my);
3313 backup_s.dquant = 0;
3318 &dmin, &next_block, 0, 0);
3323 coded |=
s->block_last_index[
i];
3326 memcpy(
s->mv, best_s.
mv,
sizeof(
s->mv));
3348 &dmin, &next_block, mx, my);
3353 s->current_picture.qscale_table[xy] = best_s.
qscale;
3362 if(
s->data_partitioning){
3366 s->pb2= backup_s.pb2;
3370 avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
3371 s->tex_pb= backup_s.tex_pb;
3380 s->hdsp.put_pixels_tab[0][0](
s->dest[0],
s->sc.rd_scratchpad ,
s->linesize ,16);
3381 s->hdsp.put_pixels_tab[1][0](
s->dest[1],
s->sc.rd_scratchpad + 16*
s->linesize ,
s->uvlinesize, 8);
3382 s->hdsp.put_pixels_tab[1][0](
s->dest[2],
s->sc.rd_scratchpad + 16*
s->linesize + 8,
s->uvlinesize, 8);
3388 int motion_x = 0, motion_y = 0;
3396 motion_x=
s->mv[0][0][0] = 0;
3397 motion_y=
s->mv[0][0][1] = 0;
3402 motion_x=
s->mv[0][0][0] =
s->p_mv_table[xy][0];
3403 motion_y=
s->mv[0][0][1] =
s->p_mv_table[xy][1];
3410 j=
s->field_select[0][
i] =
s->p_field_select_table[
i][xy];
3411 s->mv[0][
i][0] =
s->p_field_mv_table[
i][j][xy][0];
3412 s->mv[0][
i][1] =
s->p_field_mv_table[
i][j][xy][1];
3420 s->mv[0][
i][0] =
s->current_picture.motion_val[0][
s->block_index[
i]][0];
3421 s->mv[0][
i][1] =
s->current_picture.motion_val[0][
s->block_index[
i]][1];
3428 motion_x=
s->b_direct_mv_table[xy][0];
3429 motion_y=
s->b_direct_mv_table[xy][1];
3443 s->mv[0][0][0] =
s->b_bidir_forw_mv_table[xy][0];
3444 s->mv[0][0][1] =
s->b_bidir_forw_mv_table[xy][1];
3445 s->mv[1][0][0] =
s->b_bidir_back_mv_table[xy][0];
3446 s->mv[1][0][1] =
s->b_bidir_back_mv_table[xy][1];
3451 motion_x=
s->mv[1][0][0] =
s->b_back_mv_table[xy][0];
3452 motion_y=
s->mv[1][0][1] =
s->b_back_mv_table[xy][1];
3457 motion_x=
s->mv[0][0][0] =
s->b_forw_mv_table[xy][0];
3458 motion_y=
s->mv[0][0][1] =
s->b_forw_mv_table[xy][1];
3465 j=
s->field_select[0][
i] =
s->b_field_select_table[0][
i][xy];
3466 s->mv[0][
i][0] =
s->b_field_mv_table[0][
i][j][xy][0];
3467 s->mv[0][
i][1] =
s->b_field_mv_table[0][
i][j][xy][1];
3475 j=
s->field_select[1][
i] =
s->b_field_select_table[1][
i][xy];
3476 s->mv[1][
i][0] =
s->b_field_mv_table[1][
i][j][xy][0];
3477 s->mv[1][
i][1] =
s->b_field_mv_table[1][
i][j][xy][1];
3484 for(dir=0; dir<2; dir++){
3486 j=
s->field_select[dir][
i] =
s->b_field_select_table[dir][
i][xy];
3487 s->mv[dir][
i][0] =
s->b_field_mv_table[dir][
i][j][xy][0];
3488 s->mv[dir][
i][1] =
s->b_field_mv_table[dir][
i][j][xy][1];
3499 s->last_mv_dir =
s->mv_dir;
3510 s->p_mv_table[xy][0]=0;
3511 s->p_mv_table[xy][1]=0;
3518 if(
s->mb_x*16 + 16 >
s->width )
w=
s->width -
s->mb_x*16;
3519 if(
s->mb_y*16 + 16 >
s->height)
h=
s->height-
s->mb_y*16;
3521 s->current_picture.encoding_error[0] +=
sse(
3522 s,
s->new_picture.f->data[0] +
s->mb_x*16 +
s->mb_y*
s->linesize*16,
3523 s->dest[0],
w,
h,
s->linesize);
3524 s->current_picture.encoding_error[1] +=
sse(
3525 s,
s->new_picture.f->data[1] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3526 s->dest[1],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3527 s->current_picture.encoding_error[2] +=
sse(
3528 s,
s->new_picture.f->data[2] +
s->mb_x*8 +
s->mb_y*
s->uvlinesize*chr_h,
3529 s->dest[2],
w>>1,
h>>
s->chroma_y_shift,
s->uvlinesize);
3535 ff_dlog(
s->avctx,
"MB %d %d bits\n",
3546 #if FF_API_RTP_CALLBACK
3549 if (
s->avctx->rtp_callback) {
3550 int number_mb = (
mb_y -
s->resync_mb_y)*
s->mb_width -
s->resync_mb_x;
3554 s->avctx->rtp_callback(
s->avctx,
s->ptr_lastgob, pdif, number_mb);
3562 #define MERGE(field) dst->field += src->field; src->field=0
3589 for(
i=0;
i<64;
i++){
3602 if (
s->next_lambda){
3603 s->current_picture_ptr->f->quality =
3604 s->current_picture.f->quality =
s->next_lambda;
3605 if(!dry_run)
s->next_lambda= 0;
3606 }
else if (!
s->fixed_qscale) {
3608 s->current_picture_ptr->f->quality =
3609 s->current_picture.f->quality =
quality;
3610 if (
s->current_picture.f->quality < 0)
3614 if(
s->adaptive_quant){
3615 switch(
s->codec_id){
3630 s->lambda=
s->lambda_table[0];
3633 s->lambda =
s->current_picture.f->quality;
3641 s->time =
s->current_picture_ptr->f->pts *
s->avctx->time_base.num;
3644 s->pb_time=
s->pp_time - (
s->last_non_b_time -
s->time);
3647 s->pp_time=
s->time -
s->last_non_b_time;
3648 s->last_non_b_time=
s->time;
3657 int context_count =
s->slice_context_count;
3662 s->me.mb_var_sum_temp =
3663 s->me.mc_mb_var_sum_temp = 0;
3672 s->me.scene_change_score=0;
3677 if(
s->msmpeg4_version >= 3)
s->no_rounding=1;
3678 else s->no_rounding=0;
3681 s->no_rounding ^= 1;
3690 s->lambda=
s->last_lambda_for[
s->pict_type];
3692 s->lambda=
s->last_lambda_for[
s->last_non_b_pict_type];
3697 if(
s->q_chroma_intra_matrix !=
s->q_intra_matrix )
av_freep(&
s->q_chroma_intra_matrix);
3698 if(
s->q_chroma_intra_matrix16 !=
s->q_intra_matrix16)
av_freep(&
s->q_chroma_intra_matrix16);
3699 s->q_chroma_intra_matrix =
s->q_intra_matrix;
3700 s->q_chroma_intra_matrix16 =
s->q_intra_matrix16;
3704 for(
i=1;
i<context_count;
i++){
3715 s->lambda = (
s->lambda *
s->me_penalty_compensation + 128) >> 8;
3716 s->lambda2 = (
s->lambda2 * (int64_t)
s->me_penalty_compensation + 128) >> 8;
3727 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3730 if(!
s->fixed_qscale){
3732 s->avctx->execute(
s->avctx,
mb_var_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
3735 for(
i=1;
i<context_count;
i++){
3738 s->current_picture.mc_mb_var_sum=
s->current_picture_ptr->mc_mb_var_sum=
s->me.mc_mb_var_sum_temp;
3739 s->current_picture. mb_var_sum=
s->current_picture_ptr-> mb_var_sum=
s->me. mb_var_sum_temp;
3742 if (
s->me.scene_change_score >
s->scenechange_threshold &&
3745 for(
i=0;
i<
s->mb_stride*
s->mb_height;
i++)
3747 if(
s->msmpeg4_version >= 3)
3749 ff_dlog(
s,
"Scene change detected, encoding as I Frame %"PRId64
" %"PRId64
"\n",
3750 s->current_picture.mb_var_sum,
s->current_picture.mc_mb_var_sum);
3793 for(dir=0; dir<2; dir++){
3799 s->b_field_mv_table[dir][
i][j], dir ?
s->b_code :
s->f_code,
type, 1);
3810 if (
s->qscale < 3 &&
s->max_qcoeff <= 128 &&
3819 if (
s->avctx->intra_matrix) {
3821 luma_matrix =
s->avctx->intra_matrix;
3823 if (
s->avctx->chroma_intra_matrix)
3824 chroma_matrix =
s->avctx->chroma_intra_matrix;
3828 int j =
s->idsp.idct_permutation[
i];
3830 s->chroma_intra_matrix[j] = av_clip_uint8((chroma_matrix[
i] *
s->qscale) >> 3);
3831 s->
intra_matrix[j] = av_clip_uint8(( luma_matrix[
i] *
s->qscale) >> 3);
3833 s->y_dc_scale_table=
3835 s->chroma_intra_matrix[0] =
3838 s->intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3840 s->chroma_intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3844 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};
3845 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};
3852 s->y_dc_scale_table= y;
3853 s->c_dc_scale_table=
c;
3854 s->intra_matrix[0] = 13;
3855 s->chroma_intra_matrix[0] = 14;
3857 s->intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3859 s->chroma_intra_matrix,
s->intra_quant_bias, 8, 8, 1);
3864 s->current_picture_ptr->f->key_frame =
3866 s->current_picture_ptr->f->pict_type =
3867 s->current_picture.f->pict_type =
s->pict_type;
3869 if (
s->current_picture.f->key_frame)
3870 s->picture_in_gop_number=0;
3872 s->mb_x =
s->mb_y = 0;
3874 switch(
s->out_format) {
3878 s->pred,
s->intra_matrix,
s->chroma_intra_matrix);
3913 s->header_bits=
bits -
s->last_bits;
3915 for(
i=1;
i<context_count;
i++){
3918 s->avctx->execute(
s->avctx,
encode_thread, &
s->thread_context[0],
NULL, context_count,
sizeof(
void*));
3919 for(
i=1;
i<context_count;
i++){
3920 if (
s->pb.buf_end ==
s->thread_context[
i]->pb.buf)
3929 const int intra=
s->mb_intra;
3932 s->dct_count[intra]++;
3934 for(
i=0;
i<64;
i++){
3939 s->dct_error_sum[intra][
i] +=
level;
3940 level -=
s->dct_offset[intra][
i];
3943 s->dct_error_sum[intra][
i] -=
level;
3944 level +=
s->dct_offset[intra][
i];
3953 int16_t *
block,
int n,
3956 const uint16_t *matrix;
3958 const uint8_t *perm_scantable;
3960 unsigned int threshold1, threshold2;
3972 int coeff_count[64];
3973 int qmul, qadd, start_i, last_non_zero,
i,
dc;
3974 const int esc_length=
s->ac_esc_length;
3982 if(
s->dct_error_sum)
3988 else mpeg2_qscale =
qscale << 1;
3992 scantable=
s->intra_scantable.scantable;
3993 perm_scantable=
s->intra_scantable.permutated;
4010 qmat = n < 4 ?
s->q_intra_matrix[
qscale] :
s->q_chroma_intra_matrix[
qscale];
4011 matrix = n < 4 ?
s->intra_matrix :
s->chroma_intra_matrix;
4015 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4016 length =
s->intra_chroma_ac_vlc_length;
4017 last_length=
s->intra_chroma_ac_vlc_last_length;
4019 length =
s->intra_ac_vlc_length;
4020 last_length=
s->intra_ac_vlc_last_length;
4023 scantable=
s->inter_scantable.scantable;
4024 perm_scantable=
s->inter_scantable.permutated;
4027 qmat =
s->q_inter_matrix[
qscale];
4028 matrix =
s->inter_matrix;
4029 length =
s->inter_ac_vlc_length;
4030 last_length=
s->inter_ac_vlc_last_length;
4035 threshold2= (threshold1<<1);
4037 for(
i=63;
i>=start_i;
i--) {
4038 const int j = scantable[
i];
4041 if(((
unsigned)(
level+threshold1))>threshold2){
4047 for(
i=start_i;
i<=last_non_zero;
i++) {
4048 const int j = scantable[
i];
4053 if(((
unsigned)(
level+threshold1))>threshold2){
4076 if(last_non_zero < start_i){
4077 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4078 return last_non_zero;
4081 score_tab[start_i]= 0;
4082 survivor[0]= start_i;
4085 for(
i=start_i;
i<=last_non_zero;
i++){
4086 int level_index, j, zero_distortion;
4088 int best_score=256*256*256*120;
4092 zero_distortion= dct_coeff*dct_coeff;
4094 for(level_index=0; level_index < coeff_count[
i]; level_index++){
4103 unquant_coeff= alevel*qmul + qadd;
4105 j =
s->idsp.idct_permutation[scantable[
i]];
4106 unquant_coeff = alevel * matrix[j] * 8;
4108 j =
s->idsp.idct_permutation[scantable[
i]];
4110 unquant_coeff = (
int)( alevel * mpeg2_qscale * matrix[j]) >> 4;
4111 unquant_coeff = (unquant_coeff - 1) | 1;
4113 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((
int) matrix[j])) >> 5;
4114 unquant_coeff = (unquant_coeff - 1) | 1;
4119 distortion= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distortion;
4121 if((
level&(~127)) == 0){
4122 for(j=survivor_count-1; j>=0; j--){
4123 int run=
i - survivor[j];
4125 score += score_tab[
i-
run];
4127 if(score < best_score){
4130 level_tab[
i+1]=
level-64;
4135 for(j=survivor_count-1; j>=0; j--){
4136 int run=
i - survivor[j];
4138 score += score_tab[
i-
run];
4139 if(score < last_score){
4142 last_level=
level-64;
4148 distortion += esc_length*
lambda;
4149 for(j=survivor_count-1; j>=0; j--){
4150 int run=
i - survivor[j];
4151 int score= distortion + score_tab[
i-
run];
4153 if(score < best_score){
4156 level_tab[
i+1]=
level-64;
4161 for(j=survivor_count-1; j>=0; j--){
4162 int run=
i - survivor[j];
4163 int score= distortion + score_tab[
i-
run];
4164 if(score < last_score){
4167 last_level=
level-64;
4175 score_tab[
i+1]= best_score;
4178 if(last_non_zero <= 27){
4179 for(; survivor_count; survivor_count--){
4180 if(score_tab[ survivor[survivor_count-1] ] <= best_score)
4184 for(; survivor_count; survivor_count--){
4185 if(score_tab[ survivor[survivor_count-1] ] <= best_score +
lambda)
4190 survivor[ survivor_count++ ]=
i+1;
4194 last_score= 256*256*256*120;
4195 for(
i= survivor[0];
i<=last_non_zero + 1;
i++){
4196 int score= score_tab[
i];
4200 if(score < last_score){
4203 last_level= level_tab[
i];
4204 last_run= run_tab[
i];
4209 s->coded_score[n] = last_score;
4212 last_non_zero= last_i - 1;
4213 memset(
block + start_i, 0, (64-start_i)*
sizeof(int16_t));
4215 if(last_non_zero < start_i)
4216 return last_non_zero;
4218 if(last_non_zero == 0 && start_i == 0){
4220 int best_score=
dc *
dc;
4222 for(
i=0;
i<coeff_count[0];
i++){
4225 int unquant_coeff, score, distortion;
4228 unquant_coeff= (alevel*qmul + qadd)>>3;
4230 unquant_coeff = ((( alevel << 1) + 1) * mpeg2_qscale * ((
int) matrix[0])) >> 5;
4231 unquant_coeff = (unquant_coeff - 1) | 1;
4233 unquant_coeff = (unquant_coeff + 4) >> 3;
4234 unquant_coeff<<= 3 + 3;
4236 distortion= (unquant_coeff -
dc) * (unquant_coeff -
dc);
4239 else score= distortion + esc_length*
lambda;
4241 if(score < best_score){
4243 best_level=
level - 64;
4246 block[0]= best_level;
4247 s->coded_score[n] = best_score -
dc*
dc;
4248 if(best_level == 0)
return -1;
4249 else return last_non_zero;
4255 block[ perm_scantable[last_non_zero] ]= last_level;
4258 for(;
i>start_i;
i -= run_tab[
i] + 1){
4259 block[ perm_scantable[
i-1] ]= level_tab[
i];
4262 return last_non_zero;
4277 if(
i==0)
s*= sqrt(0.5);
4278 if(j==0)
s*= sqrt(0.5);
4292 const uint8_t *perm_scantable;
4298 int qmul, qadd, start_i, last_non_zero,
i,
dc;
4302 int rle_index,
run, q = 1, sum;
4304 if(
basis[0][0] == 0)
4310 scantable=
s->intra_scantable.scantable;
4311 perm_scantable=
s->intra_scantable.permutated;
4329 if (n > 3 &&
s->intra_chroma_ac_vlc_length) {
4330 length =
s->intra_chroma_ac_vlc_length;
4331 last_length=
s->intra_chroma_ac_vlc_last_length;
4333 length =
s->intra_ac_vlc_length;
4334 last_length=
s->intra_ac_vlc_last_length;
4337 scantable=
s->inter_scantable.scantable;
4338 perm_scantable=
s->inter_scantable.permutated;
4341 length =
s->inter_ac_vlc_length;
4342 last_length=
s->inter_ac_vlc_last_length;
4344 last_non_zero =
s->block_last_index[n];
4347 for(
i=0;
i<64;
i++){
4352 for(
i=0;
i<64;
i++){
4358 w= 15 + (48*qns*one +
w/2)/
w;
4371 for(
i=start_i;
i<=last_non_zero;
i++){
4372 int j= perm_scantable[
i];
4379 run_tab[rle_index++]=
run;
4389 int best_score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0], 0);
4392 int run2, best_unquant_change=0, analyze_gradient;
4393 analyze_gradient = last_non_zero > 2 ||
s->quantizer_noise_shaping >= 3;
4395 if(analyze_gradient){
4396 for(
i=0;
i<64;
i++){
4406 int change, old_coeff;
4412 for(change=-1; change<=1; change+=2){
4413 int new_level=
level + change;
4414 int score, new_coeff;
4416 new_coeff= q*new_level;
4417 if(new_coeff >= 2048 || new_coeff < 0)
4420 score =
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[0],
4421 new_coeff - old_coeff);
4422 if(score<best_score){
4425 best_change= change;
4426 best_unquant_change= new_coeff - old_coeff;
4433 run2= run_tab[rle_index++];
4437 for(
i=start_i;
i<64;
i++){
4438 int j= perm_scantable[
i];
4440 int change, old_coeff;
4442 if(
s->quantizer_noise_shaping < 3 &&
i > last_non_zero + 1)
4447 else old_coeff= qmul*
level + qadd;
4448 run2= run_tab[rle_index++];
4455 for(change=-1; change<=1; change+=2){
4456 int new_level=
level + change;
4457 int score, new_coeff, unquant_change;
4464 if(new_level<0) new_coeff= qmul*new_level - qadd;
4465 else new_coeff= qmul*new_level + qadd;
4466 if(new_coeff >= 2048 || new_coeff <= -2048)
4471 if(level < 63 && level > -63){
4472 if(
i < last_non_zero)
4482 if(analyze_gradient){
4483 int g= d1[ scantable[
i] ];
4484 if(
g && (
g^new_level) >= 0)
4488 if(
i < last_non_zero){
4489 int next_i=
i + run2 + 1;
4490 int next_level=
block[ perm_scantable[next_i] ] + 64;
4492 if(next_level&(~127))
4495 if(next_i < last_non_zero)
4515 if(
i < last_non_zero){
4516 int next_i=
i + run2 + 1;
4517 int next_level=
block[ perm_scantable[next_i] ] + 64;
4519 if(next_level&(~127))
4522 if(next_i < last_non_zero)
4541 unquant_change= new_coeff - old_coeff;
4544 score +=
s->mpvencdsp.try_8x8basis(rem,
weight,
basis[j],
4546 if(score<best_score){
4549 best_change= change;
4550 best_unquant_change= unquant_change;
4554 prev_level=
level + 64;
4555 if(prev_level&(~127))
4565 int j= perm_scantable[ best_coeff ];
4567 block[j] += best_change;
4569 if(best_coeff > last_non_zero){
4570 last_non_zero= best_coeff;
4573 for(; last_non_zero>=start_i; last_non_zero--){
4574 if(
block[perm_scantable[last_non_zero]])
4581 for(
i=start_i;
i<=last_non_zero;
i++){
4582 int j= perm_scantable[
i];
4586 run_tab[rle_index++]=
run;
4593 s->mpvencdsp.add_8x8basis(rem,
basis[j], best_unquant_change);
4599 return last_non_zero;
4614 const uint8_t *scantable,
int last)
4625 for (
i = 0;
i <= last;
i++) {
4626 const int j = scantable[
i];
4631 for (
i = 0;
i <= last;
i++) {
4632 const int j = scantable[
i];
4633 const int perm_j = permutation[j];
4639 int16_t *
block,
int n,
4642 int i, j,
level, last_non_zero, q, start_i;
4647 unsigned int threshold1, threshold2;
4651 if(
s->dct_error_sum)
4655 scantable=
s->intra_scantable.scantable;
4670 qmat = n < 4 ?
s->q_intra_matrix[
qscale] :
s->q_chroma_intra_matrix[
qscale];
4673 scantable=
s->inter_scantable.scantable;
4676 qmat =
s->q_inter_matrix[
qscale];
4680 threshold2= (threshold1<<1);
4681 for(
i=63;
i>=start_i;
i--) {
4685 if(((
unsigned)(
level+threshold1))>threshold2){
4692 for(
i=start_i;
i<=last_non_zero;
i++) {
4698 if(((
unsigned)(
level+threshold1))>threshold2){
4716 scantable, last_non_zero);
4718 return last_non_zero;
4721 #define OFFSET(x) offsetof(MpegEncContext, x)
4722 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
4725 {
"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 },
4789 .
name =
"msmpeg4v2",
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
int mb_skipped
MUST BE SET only during DECODING.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
#define FF_ENABLE_DEPRECATION_WARNINGS
uint16_t * mb_type
Table for candidate MB types for encoding (defines in mpegutils.h)
#define MV_TYPE_16X16
1 vector for the whole mb
#define AV_LOG_WARNING
Something somehow does not look correct.
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
AVPixelFormat
Pixel format.
int data_partitioning
data partitioning flag from header
static void set_frame_distances(MpegEncContext *s)
static av_cold int init(AVCodecContext *avctx)
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)
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_mpeg4_encode_video_packet_header(MpegEncContext *s)
int b_code
backward MV resolution for B-frames (MPEG-4)
attribute_deprecated int mpeg_quant
void ff_mpeg4_merge_partitions(MpegEncContext *s)
void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
int64_t rc_min_rate
minimum bitrate
void ff_fix_long_p_mvs(MpegEncContext *s, int type)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
#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.
void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block according to permutation.
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
static int16_t basis[64][64]
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])
#define CONFIG_H263_ENCODER
static int encode_frame(AVCodecContext *c, AVFrame *frame)
Picture current_picture
copy of the current picture structure.
static int estimate_motion_thread(AVCodecContext *c, void *arg)
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.
static av_cold int end(AVCodecContext *avctx)
int partitioned_frame
is current frame partitioned
uint16_t(* dct_offset)[64]
#define UNI_AC_ENC_INDEX(run, level)
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define CANDIDATE_MB_TYPE_INTER_I
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
void ff_free_picture_tables(Picture *pic)
static int alloc_picture(MpegEncContext *s, Picture *pic, int shared)
const AVOption ff_mpv_generic_options[]
int last_dc[3]
last DC values for MPEG-1
#define CANDIDATE_MB_TYPE_BACKWARD_I
const uint8_t ff_mpeg2_non_linear_qscale[32]
attribute_deprecated int p_tex_bits
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
attribute_deprecated int skip_count
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
#define AV_LOG_VERBOSE
Detailed information.
#define PICT_BOTTOM_FIELD
#define CONFIG_MPEG2VIDEO_ENCODER
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
void ff_h261_encode_init(MpegEncContext *s)
void ff_init_block_index(MpegEncContext *s)
struct AVCodecContext * avctx
void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number)
av_cold int ff_rate_control_init(MpegEncContext *s)
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define CANDIDATE_MB_TYPE_SKIPPED
static int pre_estimate_motion_thread(AVCodecContext *c, void *arg)
PutBitContext pb
bit output
#define CANDIDATE_MB_TYPE_INTER
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int qmax
maximum quantizer
attribute_deprecated int frame_skip_threshold
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
#define AV_CODEC_FLAG_4MV
4 MV per MB allowed / advanced prediction for H.263.
void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
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 FF_MPV_FLAG_SKIP_RD
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define CONFIG_H263P_ENCODER
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
#define CANDIDATE_MB_TYPE_FORWARD_I
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
attribute_deprecated int frame_bits
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
attribute_deprecated int pre_me
static int estimate_qp(MpegEncContext *s, int dry_run)
attribute_deprecated int prediction_method
int ff_get_best_fcode(MpegEncContext *s, int16_t(*mv_table)[2], int type)
void ff_set_mpeg4_time(MpegEncContext *s)
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
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.
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)
#define CANDIDATE_MB_TYPE_BIDIR
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
int padding_bug_score
used to detect the VERY common padding bug in MPEG-4
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
static const struct twinvq_data tab
static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride)
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Shrink the already allocated side data buffer.
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
int flags
AV_CODEC_FLAG_*.
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
int umvplus
== H.263+ && unrestricted_mv
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.
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.
void ff_h263_update_motion_val(MpegEncContext *s)
#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.
#define CANDIDATE_MB_TYPE_INTER4V
static const AVOption h263_options[]
static const uint8_t sp5x_quant_table[20][64]
#define MAX_PICTURE_COUNT
av_cold int ff_dct_encode_init(MpegEncContext *s)
void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t size_increase)
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)
int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
attribute_deprecated int p_count
void ff_mpv_common_end(MpegEncContext *s)
static int frame_start(MpegEncContext *s)
void ff_init_qscale_tab(MpegEncContext *s)
init s->current_picture.qscale_table from s->lambda_table
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void update_mb_info(MpegEncContext *s, int startcode)
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
int ff_h261_get_picture_format(int width, int height)
static uint8_t default_fcode_tab[MAX_MV *2+1]
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
@ 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)
#define CONFIG_RV10_ENCODER
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.
void ff_h263_encode_init(MpegEncContext *s)
const uint8_t ff_h263_chroma_qscale_table[32]
static void rebase_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Rebase the bit writer onto a reallocated buffer.
void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
Deallocate a picture.
const uint8_t *const ff_mpeg2_dc_scale_table[4]
static const AVClass msmpeg4v3_class
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
attribute_deprecated int mv_bits
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
attribute_deprecated int brd_scale
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)
int ff_check_alignment(void)
void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
#define CONFIG_WMV2_ENCODER
void ff_mpeg4_stuffing(PutBitContext *pbc)
add MPEG-4 stuffing bits (01...1)
@ 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
uint64_t error[AV_NUM_DATA_POINTERS]
error
This structure describes the bitrate properties of an encoded bitstream.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
uint64_t encoding_error[AV_NUM_DATA_POINTERS]
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
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 ...
int rc_buffer_size
decoder bitstream buffer size
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
int avg_bitrate
Average bitrate of the stream, in bits per second.
#define CONFIG_MPEG4_ENCODER
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
static const AVClass h263_class
PutBitContext pb2
used for data partitioned VOPs
#define LIBAVUTIL_VERSION_INT
void ff_write_pass1_stats(MpegEncContext *s)
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)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int f_code
forward MV resolution
av_cold void ff_mpv_idct_init(MpegEncContext *s)
attribute_deprecated int i_tex_bits
attribute_deprecated int misc_bits
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
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
#define ROUNDED_DIV(a, b)
void ff_faandct(int16_t *data)
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
void ff_fdct_ifast(int16_t *data)
AVCodec ff_msmpeg4v3_encoder
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
#define AV_CODEC_FLAG_AC_PRED
H.263 advanced intra coding / MPEG-4 AC prediction.
attribute_deprecated int b_frame_strategy
attribute_deprecated int noise_reduction
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 avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void ff_jpeg_fdct_islow_8(int16_t *data)
int trellis
trellis RD quantization
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.
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
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_jpeg_fdct_islow_10(int16_t *data)
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is actually possible in H.263 (limit difference to -2....
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
static int weight(int i, int blen, int offset)
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
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.
#define CONFIG_RV20_ENCODER
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static int get_sae(uint8_t *src, int ref, int stride)
#define AV_CODEC_FLAG_QPEL
Use qpel MC.
attribute_deprecated uint64_t vbv_delay
VBV delay coded in the last frame (in periods of a 27 MHz clock).
#define CONFIG_MPEG1VIDEO_ENCODER
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 ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
#define CONFIG_H261_ENCODER
static void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
#define CONFIG_MSMPEG4_ENCODER
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
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
const int16_t ff_mpeg4_default_intra_matrix[64]
attribute_deprecated int frame_skip_exp
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 AV_NOPTS_VALUE
Undefined timestamp value.
attribute_deprecated int rtp_payload_size
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
#define CANDIDATE_MB_TYPE_DIRECT0
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], int motion_x, int motion_y)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
@ 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...
const uint16_t ff_mpeg1_default_intra_matrix[256]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
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)
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
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]
int ff_msmpeg4_encode_init(MpegEncContext *s)
int max_bitrate
Maximum bitrate of the stream, in bits per second.
#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_msmpeg4_encode_ext_header(MpegEncContext *s)
#define MV_TYPE_FIELD
2 vectors, one per field
int flags
A combination of AV_PKT_FLAG values.
int picture_in_gop_number
0-> first pic in gop, ...
unsigned int byte_buffer_size
attribute_deprecated int i_count
#define FF_COMPLIANCE_NORMAL
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is actually possible in MPEG-4
#define AV_LOG_INFO
Standard information.
static void update_qscale(MpegEncContext *s)
static void ff_update_block_index(MpegEncContext *s)
uint64_t vbv_delay
The delay between the time the packet this structure is associated with is received and the time when...
AVCodec ff_msmpeg4v2_encoder
int block_last_index[12]
last non zero coefficient in block
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)
#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
void ff_dct_encode_init_x86(MpegEncContext *s)
attribute_deprecated int b_sensitivity
#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 encode_thread(AVCodecContext *c, void *arg)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
const uint32_t ff_square_tab[512]
static int estimate_best_b_count(MpegEncContext *s)
int intra_dc_precision
precision of the intra DC coefficient - 8
int obmc
overlapped block motion compensation
PutBitContext tex_pb
used for data partitioned VOPs
attribute_deprecated int frame_skip_cmp
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static const int32_t qmat16[MAT_SIZE]
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...
attribute_deprecated int header_bits
static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride)
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 ff_flv_encode_picture_header(MpegEncContext *s, int picture_number)
static const AVClass h263p_class
void ff_mpeg4_init_partitions(MpegEncContext *s)
const char * name
Name of the codec implementation.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
int ff_init_me(MpegEncContext *s)
int min_bitrate
Minimum bitrate of the stream, in bits per second.
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.
av_cold void ff_rate_control_uninit(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_DIRECT
double buffer_index
amount of bits in the video/audio buffer
int h263_slice_structured
const uint8_t ff_zigzag_direct[64]
static int get_bits_diff(MpegEncContext *s)
#define AV_CODEC_FLAG_CLOSED_GOP
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]
#define CONFIG_MJPEG_ENCODER
int 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, ...).
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o w
#define CANDIDATE_MB_TYPE_BIDIR_I
const uint16_t ff_inv_aanscales[64]
av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
void ff_h263_loop_filter(MpegEncContext *s)
#define FF_MPV_FLAG_CBP_RD
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
#define AV_INPUT_BUFFER_PADDING_SIZE
static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src)
#define FF_ARRAY_ELEMS(a)
int ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
attribute_deprecated int scenechange_threshold
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
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
#define CANDIDATE_MB_TYPE_INTRA
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
int last_bits
temp var used for calculating the above vars
int qmin
minimum quantizer
int gop_picture_number
index of the first picture of a GOP based on fake_pic_num & MPEG-1 specific
static int select_input_picture(MpegEncContext *s)
static void frame_end(MpegEncContext *s)
static int ref[MAX_W *MAX_W]
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define CANDIDATE_MB_TYPE_FORWARD
#define FF_MB_DECISION_RD
rate distortion
#define FF_DISABLE_DEPRECATION_WARNINGS
static int shift(int a, int b)
void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
@ 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)
void ff_mpeg1_encode_init(MpegEncContext *s)
Undefined Behavior In the C some operations are like signed integer overflow
void(* fdct)(int16_t *block)
static int skip_check(MpegEncContext *s, Picture *p, Picture *ref)
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int dct_quantize_refine(MpegEncContext *s, int16_t *block, int16_t *weight, int16_t *orig, int n, int qscale)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FF_MPV_FLAG_STRICT_GOP
#define LOCAL_ALIGNED_16(t, v,...)
int slices
Number of slices.
#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)
static int encode_picture(MpegEncContext *s, int picture_number)
int width
picture width / height.
attribute_deprecated int me_penalty_compensation
static const AVClass wmv1_class
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static const double coeff[2][5]
The exact code depends on how similar the blocks are and how related they are to the block
#define FF_MPV_FLAG_QP_RD
int misc_bits
cbp, mb_type
void ff_mjpeg_encode_picture_trailer(PutBitContext *pb, int header_bits)
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
static void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type)
void ff_get_2pass_fcode(MpegEncContext *s)
#define CONFIG_FLV_ENCODER
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
static void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type)
void ff_h261_reorder_mb_index(MpegEncContext *s)
int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
int display_picture_number
picture number in display order
static const AVClass msmpeg4v2_class
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define FF_MPV_COMMON_OPTS
attribute_deprecated int frame_skip_factor
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int alt_inter_vlc
alternative inter vlc
void ff_h263_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)
#define CANDIDATE_MB_TYPE_BACKWARD
const uint16_t ff_aanscales[64]
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
static const AVOption h263p_options[]
static void write_slice_end(MpegEncContext *s)