History

mpegvideo: use the AVVideoEncParams API for exporting QP tables

Do it only when requested with the AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS flag. Drop previous code using the long-deprecated AV_FRAME_DATA_QP_TABLE* API. Temporarily disable fate-filter-pp, fate-filter-pp7, fate-filter-spp. They will be reenabled once these filters are converted in following commits.

Anton Khirnov committed 6 years ago

Commit baecaa11 parent e15371010 files · +50 −11Browse files

Unified · Split

10 files
  1. doc/APIchanges +3 −0
  2. libavcodec/h263dec.c +2 −0
  3. libavcodec/mpeg12dec.c +1 −0
  4. libavcodec/mpegpicture.c +2 −0
  5. libavcodec/mpegpicture.h +1 −0
  6. libavcodec/mpegvideo.c +28 −7
  7. libavcodec/rv34.c +1 −0
  8. libavutil/version.h +1 −1
  9. libavutil/video_enc_params.h +8 −0
  10. tests/fate/filter-video.mak +3 −3
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2020-xx-xx - xxxxxxxxxx - lavu 56.63.100 - video_enc_params.h
19+ Add AV_VIDEO_ENC_PARAMS_MPEG2
20+
1821 2020-12-03 - xxxxxxxxxx - lavu 56.62.100 - timecode.h
1922 Add av_timecode_init_from_components.
2023
libavcodec/h263dec.c+2−0
@@ -28,6 +28,8 @@ · 27 unmodified lines
2828 #define UNCHECKED_BITSTREAM_READER 1
2929
3030 #include "libavutil/cpu.h"
31+#include "libavutil/video_enc_params.h"
32+
3133 #include "avcodec.h"
3234 #include "error_resilience.h"
3335 #include "flv.h"
libavcodec/mpeg12dec.c+1−0
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #include "libavutil/internal.h"
3434 #include "libavutil/mem_internal.h"
3535 #include "libavutil/stereo3d.h"
36+#include "libavutil/video_enc_params.h"
3637
3738 #include "avcodec.h"
3839 #include "bytestream.h"
libavcodec/mpegpicture.c+2−0
@@ -220,6 +220,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin · 219 unmodified lines
220220
221221 pic->alloc_mb_width = mb_width;
222222 pic->alloc_mb_height = mb_height;
223+ pic->alloc_mb_stride = mb_stride;
223224
224225 return 0;
225226 }
@@ -346,6 +347,7 @@ int ff_update_picture_tables(Picture *dst, Picture *src) · 120 unmodified lines
346347
347348 dst->alloc_mb_width = src->alloc_mb_width;
348349 dst->alloc_mb_height = src->alloc_mb_height;
350+ dst->alloc_mb_stride = src->alloc_mb_stride;
349351
350352 return 0;
351353 }
libavcodec/mpegpicture.h+1−0
@@ -69,6 +69,7 @@ typedef struct Picture { · 68 unmodified lines
6969
7070 int alloc_mb_width; ///< mb_width used to allocate tables
7171 int alloc_mb_height; ///< mb_height used to allocate tables
72+ int alloc_mb_stride; ///< mb_stride used to allocate tables
7273
7374 AVBufferRef *mb_mean_buf;
7475 uint8_t *mb_mean; ///< Table for MB luminance
libavcodec/mpegvideo.c+28−7
@@ -32,6 +32,8 @@ · 31 unmodified lines
3232 #include "libavutil/imgutils.h"
3333 #include "libavutil/internal.h"
3434 #include "libavutil/motion_vector.h"
35+#include "libavutil/video_enc_params.h"
36+
3537 #include "avcodec.h"
3638 #include "blockdsp.h"
3739 #include "h264chroma.h"
@@ -1422,14 +1424,33 @@ void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict) · 1384 unmodified lines
14221424
14231425 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
14241426 {
1425− AVBufferRef *ref = av_buffer_ref(p->qscale_table_buf);
1426− int offset = 2*s->mb_stride + 1;
1427− if(!ref)
1427+ AVVideoEncParams *par;
1428+ int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1;
1429+ unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
1430+ unsigned int x, y;
1431+
1432+ if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
1433+ return 0;
1434+
1435+ par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb);
1436+ if (!par)
14281437 return AVERROR(ENOMEM);
1429− av_assert0(ref->size >= offset + s->mb_stride * ((f->height+15)/16));
1430− ref->size -= offset;
1431− ref->data += offset;
1432− return av_frame_set_qp_table(f, ref, s->mb_stride, qp_type);
1438+
1439+ for (y = 0; y < p->alloc_mb_height; y++)
1440+ for (x = 0; x < p->alloc_mb_width; x++) {
1441+ const unsigned int block_idx = y * p->alloc_mb_width + x;
1442+ const unsigned int mb_xy = y * p->alloc_mb_stride + x;
1443+ AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
1444+
1445+ b->src_x = x * 16;
1446+ b->src_y = y * 16;
1447+ b->w = 16;
1448+ b->h = 16;
1449+
1450+ b->delta_qp = p->qscale_table[mb_xy] * mult;
1451+ }
1452+
1453+ return 0;
14331454 }
14341455
14351456 static inline int hpel_motion_lowres(MpegEncContext *s,
libavcodec/rv34.c+1−0
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/internal.h"
3030 #include "libavutil/mem_internal.h"
3131 #include "libavutil/thread.h"
32+#include "libavutil/video_enc_params.h"
3233
3334 #include "avcodec.h"
3435 #include "error_resilience.h"
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 62
82+#define LIBAVUTIL_VERSION_MINOR 63
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
libavutil/video_enc_params.h+8−0
@@ -55,6 +55,14 @@ enum AVVideoEncParamsType { · 54 unmodified lines
5555 * as AVVideoBlockParams.qp_delta.
5656 */
5757 AV_VIDEO_ENC_PARAMS_H264,
58+
59+ /*
60+ * MPEG-2-compatible quantizer.
61+ *
62+ * Summing the frame-level qp with the per-block delta_qp gives the
63+ * resulting quantizer for the block.
64+ */
65+ AV_VIDEO_ENC_PARAMS_MPEG2,
5866 };
5967
6068 /**
tests/fate/filter-video.mak+3−3
@@ -561,7 +561,7 @@ fate-filter-idet: CMD = framecrc -flags bitexact -idct simple -i $(SRC) -vf idet · 560 unmodified lines
561561 FATE_FILTER_VSYNTH-$(CONFIG_PAD_FILTER) += fate-filter-pad
562562 fate-filter-pad: CMD = video_filter "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
563563
564−FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp2 fate-filter-pp3 fate-filter-pp4 fate-filter-pp5 fate-filter-pp6
564+#FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp2 fate-filter-pp3 fate-filter-pp4 fate-filter-pp5 fate-filter-pp6
565565 FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
566566 $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
567567
@@ -573,11 +573,11 @@ fate-filter-pp4: CMD = video_filter "pp=be/ci" · 5 unmodified lines
573573 fate-filter-pp5: CMD = video_filter "pp=md"
574574 fate-filter-pp6: CMD = video_filter "pp=be/fd"
575575
576−FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7
576+#FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7
577577 fate-filter-pp7: fate-vsynth1-mpeg4-qprd
578578 fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7"
579579
580−FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
580+#FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
581581 fate-filter-spp: fate-vsynth1-mpeg4-qprd
582582 fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int"
583583

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