]> git.sesse.net Git - ffmpeg/commitdiff
mpegvideo: use the AVVideoEncParams API for exporting QP tables
authorAnton Khirnov <anton@khirnov.net>
Tue, 10 Mar 2020 10:45:55 +0000 (11:45 +0100)
committerAnton Khirnov <anton@khirnov.net>
Fri, 1 Jan 2021 13:23:19 +0000 (14:23 +0100)
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.

doc/APIchanges
libavcodec/h263dec.c
libavcodec/mpeg12dec.c
libavcodec/mpegpicture.c
libavcodec/mpegpicture.h
libavcodec/mpegvideo.c
libavcodec/rv34.c
libavutil/version.h
libavutil/video_enc_params.h
tests/fate/filter-video.mak

index 3fb9e125253507c121aeb5a883c0b1c4ed77168a..6c1d73515a1d2c873e6f4288e334c6614e34ba39 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xxxxxxxxxx - lavu 56.63.100 - video_enc_params.h
+  Add AV_VIDEO_ENC_PARAMS_MPEG2
+
 2020-12-03 - xxxxxxxxxx - lavu 56.62.100 - timecode.h
   Add av_timecode_init_from_components.
 
index 8b441b295130fe2045944d1f7d5b8fa1f9fd0c59..dafa54d8d4c34a06d573d03fabc0554467169e2a 100644 (file)
@@ -28,6 +28,8 @@
 #define UNCHECKED_BITSTREAM_READER 1
 
 #include "libavutil/cpu.h"
+#include "libavutil/video_enc_params.h"
+
 #include "avcodec.h"
 #include "error_resilience.h"
 #include "flv.h"
index 7b98d488a2f39267341b222b4977f783c383d2d4..b9bd7daa25e223572a7e084a85e731911d447dd2 100644 (file)
@@ -33,6 +33,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/video_enc_params.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
index 13c11ec4926e4fb45305efcc79cf690a2bd29366..e495e315e662738adfa4b30356aa93f09e9a8a13 100644 (file)
@@ -220,6 +220,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin
 
     pic->alloc_mb_width  = mb_width;
     pic->alloc_mb_height = mb_height;
+    pic->alloc_mb_stride = mb_stride;
 
     return 0;
 }
@@ -346,6 +347,7 @@ int ff_update_picture_tables(Picture *dst, Picture *src)
 
     dst->alloc_mb_width  = src->alloc_mb_width;
     dst->alloc_mb_height = src->alloc_mb_height;
+    dst->alloc_mb_stride = src->alloc_mb_stride;
 
     return 0;
 }
index 2db3d6733a82066531dbb47a26093dfe383116e8..4bcd666797980ae4804408b48ddbee7999139ae9 100644 (file)
@@ -69,6 +69,7 @@ typedef struct Picture {
 
     int alloc_mb_width;         ///< mb_width used to allocate tables
     int alloc_mb_height;        ///< mb_height used to allocate tables
+    int alloc_mb_stride;        ///< mb_stride used to allocate tables
 
     AVBufferRef *mb_mean_buf;
     uint8_t *mb_mean;           ///< Table for MB luminance
index 60ed716865ba26a3f74bbefcd0f56f963b6507a7..988dd18a330acccc9ebf7cf139bab5740c35aed1 100644 (file)
@@ -32,6 +32,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/motion_vector.h"
+#include "libavutil/video_enc_params.h"
+
 #include "avcodec.h"
 #include "blockdsp.h"
 #include "h264chroma.h"
@@ -1422,14 +1424,33 @@ void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
 
 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
 {
-    AVBufferRef *ref = av_buffer_ref(p->qscale_table_buf);
-    int offset = 2*s->mb_stride + 1;
-    if(!ref)
+    AVVideoEncParams *par;
+    int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1;
+    unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
+    unsigned int x, y;
+
+    if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
+        return 0;
+
+    par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb);
+    if (!par)
         return AVERROR(ENOMEM);
-    av_assert0(ref->size >= offset + s->mb_stride * ((f->height+15)/16));
-    ref->size -= offset;
-    ref->data += offset;
-    return av_frame_set_qp_table(f, ref, s->mb_stride, qp_type);
+
+    for (y = 0; y < p->alloc_mb_height; y++)
+        for (x = 0; x < p->alloc_mb_width; x++) {
+            const unsigned int block_idx = y * p->alloc_mb_width + x;
+            const unsigned int     mb_xy = y * p->alloc_mb_stride + x;
+            AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
+
+            b->src_x = x * 16;
+            b->src_y = y * 16;
+            b->w     = 16;
+            b->h     = 16;
+
+            b->delta_qp = p->qscale_table[mb_xy] * mult;
+        }
+
+    return 0;
 }
 
 static inline int hpel_motion_lowres(MpegEncContext *s,
index 6434f784d6cee11834f3366ba0ce656a1a29e1af..7e5bfe0e22d818b1b1a1f804b8ef49f690563173 100644 (file)
@@ -29,6 +29,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
+#include "libavutil/video_enc_params.h"
 
 #include "avcodec.h"
 #include "error_resilience.h"
index 085c4e30f912a8d43ab540b796100f4604a2c159..5e6fe02d8831e511841fd89d1770acb658315a8c 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  62
+#define LIBAVUTIL_VERSION_MINOR  63
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
index e3b422d6f3f1b3d5ef18f9ad819393b2f57f4384..fc0c3bc1a514f035bd5b8edec03e492bea93c007 100644 (file)
@@ -55,6 +55,14 @@ enum AVVideoEncParamsType {
      *   as AVVideoBlockParams.qp_delta.
      */
     AV_VIDEO_ENC_PARAMS_H264,
+
+    /*
+     * MPEG-2-compatible quantizer.
+     *
+     * Summing the frame-level qp with the per-block delta_qp gives the
+     * resulting quantizer for the block.
+     */
+    AV_VIDEO_ENC_PARAMS_MPEG2,
 };
 
 /**
index a2967de3aef4d29faeadafb8e84d0a6bcbe79a4e..34cfc38aba69ec128f3d933140dd558d8e0101c4 100644 (file)
@@ -561,7 +561,7 @@ fate-filter-idet: CMD = framecrc -flags bitexact -idct simple -i $(SRC) -vf idet
 FATE_FILTER_VSYNTH-$(CONFIG_PAD_FILTER) += fate-filter-pad
 fate-filter-pad: CMD = video_filter "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
 
-FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp2 fate-filter-pp3 fate-filter-pp4 fate-filter-pp5 fate-filter-pp6
+#FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp2 fate-filter-pp3 fate-filter-pp4 fate-filter-pp5 fate-filter-pp6
 FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
 $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
 
@@ -573,11 +573,11 @@ fate-filter-pp4: CMD = video_filter "pp=be/ci"
 fate-filter-pp5: CMD = video_filter "pp=md"
 fate-filter-pp6: CMD = video_filter "pp=be/fd"
 
-FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7
+#FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7
 fate-filter-pp7: fate-vsynth1-mpeg4-qprd
 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"
 
-FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
+#FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
 fate-filter-spp: fate-vsynth1-mpeg4-qprd
 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"