History

avcodec/mpegvideo: Move MPVPicture arrays to MPVMainEncContext

Also avoid allocations while at it.

Andreas Rheinhardt committed 1 year ago

Commit bf4dedd1 parent 72bf3d34 files · +68 −72Browse files

Showing the changes to libavcodec (4 of 4 files). Show all

Unified · Split

4 files
  1. libavcodec/mpeg4videoenc.c +6 −5
  2. libavcodec/mpegvideo.h +0 −2
  3. libavcodec/mpegvideo_enc.c +59 −65
  4. libavcodec/mpegvideoenc.h +3 −0
libavcodec/mpeg4videoenc.c+6−5
@@ -668,7 +668,7 @@ static void mpeg4_encode_mb(MpegEncContext *const s, int16_t block[][64], · 667 unmodified lines
668 for (int i = 0; i < m->max_b_frames; i++) {668 for (int i = 0; i < m->max_b_frames; i++) {
669 const uint8_t *b_pic;669 const uint8_t *b_pic;
670 int diff;670 int diff;
671 const MPVPicture *pic = s->reordered_input_picture[i + 1];671 const MPVPicture *pic = m->reordered_input_picture[i + 1];
672 672
673 if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B)673 if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B)
674 break;674 break;
@@ -900,16 +900,17 @@ void ff_set_mpeg4_time(MpegEncContext *s) · 225 unmodified lines
900 }900 }
901}901}
902 902
903static void mpeg4_encode_gop_header(MpegEncContext *s)903static void mpeg4_encode_gop_header(MPVMainEncContext *const m)
904{904{
905 MpegEncContext *const s = &m->s;
905 int64_t hours, minutes, seconds;906 int64_t hours, minutes, seconds;
906 int64_t time;907 int64_t time;
907 908
908 put_bits32(&s->pb, GOP_STARTCODE);909 put_bits32(&s->pb, GOP_STARTCODE);
909 910
910 time = s->cur_pic.ptr->f->pts;911 time = s->cur_pic.ptr->f->pts;
911 if (s->reordered_input_picture[1])912 if (m->reordered_input_picture[1])
912 time = FFMIN(time, s->reordered_input_picture[1]->f->pts);913 time = FFMIN(time, m->reordered_input_picture[1]->f->pts);
913 time = time * s->avctx->time_base.num;914 time = time * s->avctx->time_base.num;
914 s->last_time_base = FFUDIV(time, s->avctx->time_base.den);915 s->last_time_base = FFUDIV(time, s->avctx->time_base.den);
915 916
@@ -1077,7 +1078,7 @@ static int mpeg4_encode_picture_header(MPVMainEncContext *const m) · 161 unmodified lines
1077 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy1078 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy
1078 mpeg4_encode_vol_header(m4, 0, 0);1079 mpeg4_encode_vol_header(m4, 0, 0);
1079 }1080 }
1080 mpeg4_encode_gop_header(s);1081 mpeg4_encode_gop_header(m);
1081 }1082 }
1082 1083
1083 s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;1084 s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;
libavcodec/mpegvideo.h+0−2
@@ -123,8 +123,6 @@ typedef struct MpegEncContext { · 122 unmodified lines
123 ptrdiff_t linesize; ///< line size, in bytes, may be different from width123 ptrdiff_t linesize; ///< line size, in bytes, may be different from width
124 ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width124 ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width
125 struct AVRefStructPool *picture_pool; ///< Pool for MPVPictures125 struct AVRefStructPool *picture_pool; ///< Pool for MPVPictures
126 MPVPicture **input_picture;///< next pictures on display order for encoding
127 MPVPicture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
128 126
129 BufferPoolContext buffer_pools;127 BufferPoolContext buffer_pools;
130 128
libavcodec/mpegvideo_enc.c+59−65
@@ -915,8 +915,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 914 unmodified lines
915 return ret;915 return ret;
916 916
917 if (!(avctx->stats_out = av_mallocz(256)) ||917 if (!(avctx->stats_out = av_mallocz(256)) ||
918 !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MPVENC_MAX_B_FRAMES + 1) ||
919 !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MPVENC_MAX_B_FRAMES + 1) ||
920 !(s->new_pic = av_frame_alloc()) ||918 !(s->new_pic = av_frame_alloc()) ||
921 !(s->picture_pool = ff_mpv_alloc_pic_pool(0)))919 !(s->picture_pool = ff_mpv_alloc_pic_pool(0)))
922 return AVERROR(ENOMEM);920 return AVERROR(ENOMEM);
@@ -1049,11 +1047,9 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 126 unmodified lines
1049 ff_mpv_common_end(s);1047 ff_mpv_common_end(s);
1050 av_refstruct_pool_uninit(&s->picture_pool);1048 av_refstruct_pool_uninit(&s->picture_pool);
1051 1049
1052 if (s->input_picture && s->reordered_input_picture) {1050 for (int i = 0; i < MPVENC_MAX_B_FRAMES + 1; i++) {
1053 for (int i = 0; i < MPVENC_MAX_B_FRAMES + 1; i++) {1051 av_refstruct_unref(&m->input_picture[i]);
1054 av_refstruct_unref(&s->input_picture[i]);1052 av_refstruct_unref(&m->reordered_input_picture[i]);
1055 av_refstruct_unref(&s->reordered_input_picture[i]);
1056 }
1057 }1053 }
1058 for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++)1054 for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++)
1059 av_frame_free(&m->tmp_frames[i]);1055 av_frame_free(&m->tmp_frames[i]);
@@ -1077,8 +1073,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 17 unmodified lines
1077 1073
1078 av_freep(&s->q_intra_matrix);1074 av_freep(&s->q_intra_matrix);
1079 av_freep(&s->q_intra_matrix16);1075 av_freep(&s->q_intra_matrix16);
1080 av_freep(&s->input_picture);
1081 av_freep(&s->reordered_input_picture);
1082 av_freep(&s->dct_offset);1076 av_freep(&s->dct_offset);
1083 av_freep(&s->mb_var);1077 av_freep(&s->mb_var);
1084 av_freep(&s->mc_mb_var);1078 av_freep(&s->mc_mb_var);
@@ -1260,7 +1254,7 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 175 unmodified lines
1260 int flush_offset = 1;1254 int flush_offset = 1;
1261 int direct = 1;1255 int direct = 1;
1262 1256
1263 av_assert1(!s->input_picture[0]);1257 av_assert1(!m->input_picture[0]);
1264 1258
1265 if (pic_arg) {1259 if (pic_arg) {
1266 pts = pic_arg->pts;1260 pts = pic_arg->pts;
@@ -1363,14 +1357,14 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 96 unmodified lines
1363 1357
1364 pic->display_picture_number = display_picture_number;1358 pic->display_picture_number = display_picture_number;
1365 pic->f->pts = pts; // we set this here to avoid modifying pic_arg1359 pic->f->pts = pts; // we set this here to avoid modifying pic_arg
1366 } else if (!s->reordered_input_picture[1]) {1360 } else if (!m->reordered_input_picture[1]) {
1367 /* Flushing: When the above check is true, the encoder is about to run1361 /* Flushing: When the above check is true, the encoder is about to run
1368 * out of frames to encode. Check if there are input_pictures left;1362 * out of frames to encode. Check if there are input_pictures left;
1369 * if so, ensure s->input_picture[0] contains the first picture.1363 * if so, ensure m->input_picture[0] contains the first picture.
1370 * A flush_offset != 1 will only happen if we did not receive enough1364 * A flush_offset != 1 will only happen if we did not receive enough
1371 * input frames. */1365 * input frames. */
1372 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)1366 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)
1373 if (s->input_picture[flush_offset])1367 if (m->input_picture[flush_offset])
1374 break;1368 break;
1375 1369
1376 encoding_delay -= flush_offset - 1;1370 encoding_delay -= flush_offset - 1;
@@ -1378,11 +1372,11 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 1 unmodified line
1378 1372
1379 /* shift buffer entries */1373 /* shift buffer entries */
1380 for (int i = flush_offset; i <= MPVENC_MAX_B_FRAMES; i++)1374 for (int i = flush_offset; i <= MPVENC_MAX_B_FRAMES; i++)
1381 s->input_picture[i - flush_offset] = s->input_picture[i];1375 m->input_picture[i - flush_offset] = m->input_picture[i];
1382 for (int i = MPVENC_MAX_B_FRAMES + 1 - flush_offset; i <= MPVENC_MAX_B_FRAMES; i++)1376 for (int i = MPVENC_MAX_B_FRAMES + 1 - flush_offset; i <= MPVENC_MAX_B_FRAMES; i++)
1383 s->input_picture[i] = NULL;1377 m->input_picture[i] = NULL;
1384 1378
1385 s->input_picture[encoding_delay] = pic;1379 m->input_picture[encoding_delay] = pic;
1386 1380
1387 return 0;1381 return 0;
1388fail:1382fail:
@@ -1482,7 +1476,7 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 93 unmodified lines
1482 FF_LAMBDA_SHIFT;1476 FF_LAMBDA_SHIFT;
1483 1477
1484 for (int i = 0; i < m->max_b_frames + 2; i++) {1478 for (int i = 0; i < m->max_b_frames + 2; i++) {
1485 const MPVPicture *pre_input_ptr = i ? s->input_picture[i - 1] :1479 const MPVPicture *pre_input_ptr = i ? m->input_picture[i - 1] :
1486 s->next_pic.ptr;1480 s->next_pic.ptr;
1487 1481
1488 if (pre_input_ptr) {1482 if (pre_input_ptr) {
@@ -1517,7 +1511,7 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 28 unmodified lines
1517 AVCodecContext *c;1511 AVCodecContext *c;
1518 int64_t rd = 0;1512 int64_t rd = 0;
1519 1513
1520 if (!s->input_picture[j])1514 if (!m->input_picture[j])
1521 break;1515 break;
1522 1516
1523 c = avcodec_alloc_context3(NULL);1517 c = avcodec_alloc_context3(NULL);
@@ -1612,16 +1606,16 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 88 unmodified lines
1612 MpegEncContext *const s = &m->s;1606 MpegEncContext *const s = &m->s;
1613 1607
1614 /* Either nothing to do or can't do anything */1608 /* Either nothing to do or can't do anything */
1615 if (s->reordered_input_picture[0] || !s->input_picture[0])1609 if (m->reordered_input_picture[0] || !m->input_picture[0])
1616 return 0;1610 return 0;
1617 1611
1618 /* set next picture type & ordering */1612 /* set next picture type & ordering */
1619 if (m->frame_skip_threshold || m->frame_skip_factor) {1613 if (m->frame_skip_threshold || m->frame_skip_factor) {
1620 if (m->picture_in_gop_number < m->gop_size &&1614 if (m->picture_in_gop_number < m->gop_size &&
1621 s->next_pic.ptr &&1615 s->next_pic.ptr &&
1622 skip_check(m, s->input_picture[0], s->next_pic.ptr)) {1616 skip_check(m, m->input_picture[0], s->next_pic.ptr)) {
1623 // FIXME check that the gop check above is +-1 correct1617 // FIXME check that the gop check above is +-1 correct
1624 av_refstruct_unref(&s->input_picture[0]);1618 av_refstruct_unref(&m->input_picture[0]);
1625 1619
1626 ff_vbv_update(m, 0);1620 ff_vbv_update(m, 0);
1627 1621
@@ -1631,48 +1625,48 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 3 unmodified lines
1631 1625
1632 if (/* m->picture_in_gop_number >= m->gop_size || */1626 if (/* m->picture_in_gop_number >= m->gop_size || */
1633 !s->next_pic.ptr || m->intra_only) {1627 !s->next_pic.ptr || m->intra_only) {
1634 s->reordered_input_picture[0] = s->input_picture[0];1628 m->reordered_input_picture[0] = m->input_picture[0];
1635 s->input_picture[0] = NULL;1629 m->input_picture[0] = NULL;
1636 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;1630 m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
1637 s->reordered_input_picture[0]->coded_picture_number =1631 m->reordered_input_picture[0]->coded_picture_number =
1638 m->coded_picture_number++;1632 m->coded_picture_number++;
1639 } else {1633 } else {
1640 int b_frames = 0;1634 int b_frames = 0;
1641 1635
1642 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {1636 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
1643 for (int i = 0; i < m->max_b_frames + 1; i++) {1637 for (int i = 0; i < m->max_b_frames + 1; i++) {
1644 int pict_num = s->input_picture[0]->display_picture_number + i;1638 int pict_num = m->input_picture[0]->display_picture_number + i;
1645 1639
1646 if (pict_num >= m->rc_context.num_entries)1640 if (pict_num >= m->rc_context.num_entries)
1647 break;1641 break;
1648 if (!s->input_picture[i]) {1642 if (!m->input_picture[i]) {
1649 m->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P;1643 m->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P;
1650 break;1644 break;
1651 }1645 }
1652 1646
1653 s->input_picture[i]->f->pict_type =1647 m->input_picture[i]->f->pict_type =
1654 m->rc_context.entry[pict_num].new_pict_type;1648 m->rc_context.entry[pict_num].new_pict_type;
1655 }1649 }
1656 }1650 }
1657 1651
1658 if (m->b_frame_strategy == 0) {1652 if (m->b_frame_strategy == 0) {
1659 b_frames = m->max_b_frames;1653 b_frames = m->max_b_frames;
1660 while (b_frames && !s->input_picture[b_frames])1654 while (b_frames && !m->input_picture[b_frames])
1661 b_frames--;1655 b_frames--;
1662 } else if (m->b_frame_strategy == 1) {1656 } else if (m->b_frame_strategy == 1) {
1663 for (int i = 1; i < m->max_b_frames + 1; i++) {1657 for (int i = 1; i < m->max_b_frames + 1; i++) {
1664 if (s->input_picture[i] &&1658 if (m->input_picture[i] &&
1665 s->input_picture[i]->b_frame_score == 0) {1659 m->input_picture[i]->b_frame_score == 0) {
1666 s->input_picture[i]->b_frame_score =1660 m->input_picture[i]->b_frame_score =
1667 get_intra_count(s,1661 get_intra_count(s,
1668 s->input_picture[i ]->f->data[0],1662 m->input_picture[i ]->f->data[0],
1669 s->input_picture[i - 1]->f->data[0],1663 m->input_picture[i - 1]->f->data[0],
1670 s->linesize) + 1;1664 s->linesize) + 1;
1671 }1665 }
1672 }1666 }
1673 for (int i = 0; i < m->max_b_frames + 1; i++) {1667 for (int i = 0; i < m->max_b_frames + 1; i++) {
1674 if (!s->input_picture[i] ||1668 if (!m->input_picture[i] ||
1675 s->input_picture[i]->b_frame_score - 1 >1669 m->input_picture[i]->b_frame_score - 1 >
1676 s->mb_num / m->b_sensitivity) {1670 s->mb_num / m->b_sensitivity) {
1677 b_frames = FFMAX(0, i - 1);1671 b_frames = FFMAX(0, i - 1);
1678 break;1672 break;
@@ -1681,11 +1675,11 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 2 unmodified lines
1681 1675
1682 /* reset scores */1676 /* reset scores */
1683 for (int i = 0; i < b_frames + 1; i++)1677 for (int i = 0; i < b_frames + 1; i++)
1684 s->input_picture[i]->b_frame_score = 0;1678 m->input_picture[i]->b_frame_score = 0;
1685 } else if (m->b_frame_strategy == 2) {1679 } else if (m->b_frame_strategy == 2) {
1686 b_frames = estimate_best_b_count(m);1680 b_frames = estimate_best_b_count(m);
1687 if (b_frames < 0) {1681 if (b_frames < 0) {
1688 av_refstruct_unref(&s->input_picture[0]);1682 av_refstruct_unref(&m->input_picture[0]);
1689 return b_frames;1683 return b_frames;
1690 }1684 }
1691 }1685 }
@@ -1693,11 +1687,11 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 1 unmodified line
1693 emms_c();1687 emms_c();
1694 1688
1695 for (int i = b_frames - 1; i >= 0; i--) {1689 for (int i = b_frames - 1; i >= 0; i--) {
1696 int type = s->input_picture[i]->f->pict_type;1690 int type = m->input_picture[i]->f->pict_type;
1697 if (type && type != AV_PICTURE_TYPE_B)1691 if (type && type != AV_PICTURE_TYPE_B)
1698 b_frames = i;1692 b_frames = i;
1699 }1693 }
1700 if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B &&1694 if (m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B &&
1701 b_frames == m->max_b_frames) {1695 b_frames == m->max_b_frames) {
1702 av_log(s->avctx, AV_LOG_ERROR,1696 av_log(s->avctx, AV_LOG_ERROR,
1703 "warning, too many B-frames in a row\n");1697 "warning, too many B-frames in a row\n");
@@ -1710,26 +1704,26 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 6 unmodified lines
1710 } else {1704 } else {
1711 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)1705 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
1712 b_frames = 0;1706 b_frames = 0;
1713 s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I;1707 m->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I;
1714 }1708 }
1715 }1709 }
1716 1710
1717 if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames &&1711 if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames &&
1718 s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I)1712 m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I)
1719 b_frames--;1713 b_frames--;
1720 1714
1721 s->reordered_input_picture[0] = s->input_picture[b_frames];1715 m->reordered_input_picture[0] = m->input_picture[b_frames];
1722 s->input_picture[b_frames] = NULL;1716 m->input_picture[b_frames] = NULL;
1723 if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)1717 if (m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
1724 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;1718 m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;
1725 s->reordered_input_picture[0]->coded_picture_number =1719 m->reordered_input_picture[0]->coded_picture_number =
1726 m->coded_picture_number++;1720 m->coded_picture_number++;
1727 for (int i = 0; i < b_frames; i++) {1721 for (int i = 0; i < b_frames; i++) {
1728 s->reordered_input_picture[i + 1] = s->input_picture[i];1722 m->reordered_input_picture[i + 1] = m->input_picture[i];
1729 s->input_picture[i] = NULL;1723 m->input_picture[i] = NULL;
1730 s->reordered_input_picture[i + 1]->f->pict_type =1724 m->reordered_input_picture[i + 1]->f->pict_type =
1731 AV_PICTURE_TYPE_B;1725 AV_PICTURE_TYPE_B;
1732 s->reordered_input_picture[i + 1]->coded_picture_number =1726 m->reordered_input_picture[i + 1]->coded_picture_number =
1733 m->coded_picture_number++;1727 m->coded_picture_number++;
1734 }1728 }
1735 }1729 }
@@ -1742,34 +1736,34 @@ static int select_input_picture(MPVMainEncContext *const m) · 6 unmodified lines
1742 MpegEncContext *const s = &m->s;1736 MpegEncContext *const s = &m->s;
1743 int ret;1737 int ret;
1744 1738
1745 av_assert1(!s->reordered_input_picture[0]);1739 av_assert1(!m->reordered_input_picture[0]);
1746 1740
1747 for (int i = 1; i <= MPVENC_MAX_B_FRAMES; i++)1741 for (int i = 1; i <= MPVENC_MAX_B_FRAMES; i++)
1748 s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];1742 m->reordered_input_picture[i - 1] = m->reordered_input_picture[i];
1749 s->reordered_input_picture[MPVENC_MAX_B_FRAMES] = NULL;1743 m->reordered_input_picture[MPVENC_MAX_B_FRAMES] = NULL;
1750 1744
1751 ret = set_bframe_chain_length(m);1745 ret = set_bframe_chain_length(m);
1752 av_assert1(!s->input_picture[0]);1746 av_assert1(!m->input_picture[0]);
1753 if (ret < 0)1747 if (ret < 0)
1754 return ret;1748 return ret;
1755 1749
1756 av_frame_unref(s->new_pic);1750 av_frame_unref(s->new_pic);
1757 1751
1758 if (s->reordered_input_picture[0]) {1752 if (m->reordered_input_picture[0]) {
1759 s->reordered_input_picture[0]->reference =1753 m->reordered_input_picture[0]->reference =
1760 s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B;1754 m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B;
1761 1755
1762 if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {1756 if (m->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {
1763 // input is a shared pix, so we can't modify it -> allocate a new1757 // input is a shared pix, so we can't modify it -> allocate a new
1764 // one & ensure that the shared one is reuseable1758 // one & ensure that the shared one is reuseable
1765 av_frame_move_ref(s->new_pic, s->reordered_input_picture[0]->f);1759 av_frame_move_ref(s->new_pic, m->reordered_input_picture[0]->f);
1766 1760
1767 ret = prepare_picture(s, s->reordered_input_picture[0]->f, s->new_pic);1761 ret = prepare_picture(s, m->reordered_input_picture[0]->f, s->new_pic);
1768 if (ret < 0)1762 if (ret < 0)
1769 goto fail;1763 goto fail;
1770 } else {1764 } else {
1771 // input is not a shared pix -> reuse buffer for current_pix1765 // input is not a shared pix -> reuse buffer for current_pix
1772 ret = av_frame_ref(s->new_pic, s->reordered_input_picture[0]->f);1766 ret = av_frame_ref(s->new_pic, m->reordered_input_picture[0]->f);
1773 if (ret < 0)1767 if (ret < 0)
1774 goto fail;1768 goto fail;
1775 for (int i = 0; i < MPV_MAX_PLANES; i++) {1769 for (int i = 0; i < MPV_MAX_PLANES; i++) {
@@ -1777,8 +1771,8 @@ static int select_input_picture(MPVMainEncContext *const m) · 1 unmodified line
1777 s->new_pic->data[i] += INPLACE_OFFSET;1771 s->new_pic->data[i] += INPLACE_OFFSET;
1778 }1772 }
1779 }1773 }
1780 s->cur_pic.ptr = s->reordered_input_picture[0];1774 s->cur_pic.ptr = m->reordered_input_picture[0];
1781 s->reordered_input_picture[0] = NULL;1775 m->reordered_input_picture[0] = NULL;
1782 av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width);1776 av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width);
1783 av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height);1777 av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height);
1784 av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride);1778 av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride);
@@ -1793,7 +1787,7 @@ static int select_input_picture(MPVMainEncContext *const m) · 8 unmodified lines
1793 }1787 }
1794 return 0;1788 return 0;
1795fail:1789fail:
1796 av_refstruct_unref(&s->reordered_input_picture[0]);1790 av_refstruct_unref(&m->reordered_input_picture[0]);
1797 return ret;1791 return ret;
1798}1792}
1799 1793
libavcodec/mpegvideoenc.h+3−0
@@ -47,6 +47,9 @@ typedef struct MPVMainEncContext { · 46 unmodified lines
47 int input_picture_number; ///< used to set pic->display_picture_number47 int input_picture_number; ///< used to set pic->display_picture_number
48 int coded_picture_number; ///< used to set pic->coded_picture_number48 int coded_picture_number; ///< used to set pic->coded_picture_number
49 49
50 MPVPicture *input_picture[MPVENC_MAX_B_FRAMES + 1]; ///< next pictures in display order
51 MPVPicture *reordered_input_picture[MPVENC_MAX_B_FRAMES + 1]; ///< next pictures in coded order
52
50 int64_t user_specified_pts; ///< last non-zero pts from user-supplied AVFrame53 int64_t user_specified_pts; ///< last non-zero pts from user-supplied AVFrame
51 /**54 /**
52 * pts difference between the first and second input frame, used for55 * pts difference between the first and second input frame, used for

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t