@@ -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"
@@ -32,6 +32,7 @@
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/video_enc_params.h"
#include "avcodec.h"
#include "bytestream.h"
@@ -225,6 +225,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;
}
@@ -359,6 +360,7 @@ do { \
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;
}
@@ -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
@@ -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"
@@ -1441,14 +1443,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,
@@ -58,6 +58,7 @@
#include "libavutil/opt.h"
#include "libavutil/timecode.h"
+#include "libavutil/video_enc_params.h"
#define MAX_THREADS 32
@@ -28,6 +28,7 @@
#include <inttypes.h>
#include "libavutil/imgutils.h"
+#include "libavutil/video_enc_params.h"
#include "avcodec.h"
#include "error_resilience.h"
@@ -26,6 +26,7 @@
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
+#include "libavutil/video_enc_params.h"
#include "avcodec.h"
#include "error_resilience.h"
@@ -27,6 +27,14 @@
enum AVVideoEncParamsType {
AV_VIDEO_ENC_PARAMS_NONE = -1,
+
+ /**
+ * 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,
};
/**