Commit c72d5264 authored by Anton Khirnov's avatar Anton Khirnov

lavfi/vf_qp: convert to the video_enc_params API

Temporarily disable fate-filter-qp until vf_pp is converted.
parent baecaa16
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/video_enc_params.h"
#include "avfilter.h" #include "avfilter.h"
#include "formats.h" #include "formats.h"
#include "internal.h" #include "internal.h"
...@@ -89,38 +91,59 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -89,38 +91,59 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0]; AVFilterLink *outlink = ctx->outputs[0];
QPContext *s = ctx->priv; QPContext *s = ctx->priv;
AVBufferRef *out_qp_table_buf;
AVFrame *out = NULL; AVFrame *out = NULL;
const int8_t *in_qp_table; int ret;
int type, stride, ret;
AVFrameSideData *sd_in;
AVVideoEncParams *par_in = NULL;
int8_t in_qp_global = 0;
AVVideoEncParams *par_out;
if (!s->qp_expr_str || ctx->is_disabled) if (!s->qp_expr_str || ctx->is_disabled)
return ff_filter_frame(outlink, in); return ff_filter_frame(outlink, in);
out_qp_table_buf = av_buffer_alloc(s->h * s->qstride); sd_in = av_frame_get_side_data(in, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
if (!out_qp_table_buf) { if (sd_in && sd_in->size >= sizeof(AVVideoEncParams)) {
ret = AVERROR(ENOMEM); par_in = (AVVideoEncParams*)sd_in->data;
goto fail;
// we accept the input QP table only if it is of the MPEG2 type
// and contains either no blocks at all or 16x16 macroblocks
if (par_in->type == AV_VIDEO_ENC_PARAMS_MPEG2 &&
(par_in->nb_blocks == s->h * s->qstride || !par_in->nb_blocks)) {
in_qp_global = par_in->qp;
if (!par_in->nb_blocks)
par_in = NULL;
} else
par_in = NULL;
} }
out = av_frame_clone(in); out = av_frame_clone(in);
if (!out) { if (!out) {
av_buffer_unref(&out_qp_table_buf);
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
in_qp_table = av_frame_get_qp_table(in, &stride, &type); par_out = av_video_enc_params_create_side_data(out, AV_VIDEO_ENC_PARAMS_MPEG2,
av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, type); (s->evaluate_per_mb || sd_in) ?
s->h * s->qstride : 0);
if (!par_out) {
ret = AVERROR(ENOMEM);
goto fail;
}
#define BLOCK_QP_DELTA(block_idx) \
(par_in ? av_video_enc_params_block(par_in, block_idx)->delta_qp : 0)
if (s->evaluate_per_mb) { if (s->evaluate_per_mb) {
int y, x; int y, x;
for (y = 0; y < s->h; y++) for (y = 0; y < s->h; y++)
for (x = 0; x < s->qstride; x++) { for (x = 0; x < s->qstride; x++) {
int qp = in_qp_table ? in_qp_table[x + stride * y] : NAN; unsigned int block_idx = y * s->qstride + x;
double var_values[] = { !!in_qp_table, qp, x, y, s->qstride, s->h, 0}; AVVideoBlockParams *b = av_video_enc_params_block(par_out, block_idx);
int qp = sd_in ? in_qp_global + BLOCK_QP_DELTA(block_idx) : NAN;
double var_values[] = { !!sd_in, qp, x, y, s->qstride, s->h, 0};
static const char *var_names[] = { "known", "qp", "x", "y", "w", "h", NULL }; static const char *var_names[] = { "known", "qp", "x", "y", "w", "h", NULL };
double temp_val; double temp_val;
...@@ -129,21 +152,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -129,21 +152,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
NULL, NULL, NULL, NULL, 0, 0, ctx); NULL, NULL, NULL, NULL, 0, 0, ctx);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
out_qp_table_buf->data[x + s->qstride * y] = lrintf(temp_val); b->delta_qp = lrintf(temp_val);
} }
} else if (in_qp_table) { } else if (sd_in) {
int y, x; int y, x;
for (y = 0; y < s->h; y++) for (y = 0; y < s->h; y++)
for (x = 0; x < s->qstride; x++) for (x = 0; x < s->qstride; x++) {
out_qp_table_buf->data[x + s->qstride * y] = s->lut[129 + unsigned int block_idx = y * s->qstride + x;
((int8_t)in_qp_table[x + stride * y])]; AVVideoBlockParams *b = av_video_enc_params_block(par_out, block_idx);
b->delta_qp = s->lut[129 + (int8_t)(in_qp_global + BLOCK_QP_DELTA(block_idx))];
}
} else { } else {
int y, x, qp = s->lut[0]; par_out->qp = s->lut[0];
for (y = 0; y < s->h; y++)
for (x = 0; x < s->qstride; x++)
out_qp_table_buf->data[x + s->qstride * y] = qp;
} }
ret = ff_filter_frame(outlink, out); ret = ff_filter_frame(outlink, out);
......
...@@ -567,8 +567,8 @@ $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd ...@@ -567,8 +567,8 @@ $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
fate-filter-pp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp=be/hb/vb/tn/l5/al" fate-filter-pp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp=be/hb/vb/tn/l5/al"
fate-filter-pp1: CMD = video_filter "pp=fq|4/be/hb/vb/tn/l5/al" fate-filter-pp1: CMD = video_filter "pp=fq|4/be/hb/vb/tn/l5/al"
fate-filter-pp2: CMD = video_filter "qp=x+y,pp=be/h1/v1/lb" fate-filter-pp2: CMD = video_filter "qp=2*(x+y),pp=be/h1/v1/lb"
fate-filter-pp3: CMD = video_filter "qp=x+y,pp=be/ha|128|7/va/li" fate-filter-pp3: CMD = video_filter "qp=2*(x+y),pp=be/ha|128|7/va/li"
fate-filter-pp4: CMD = video_filter "pp=be/ci" fate-filter-pp4: CMD = video_filter "pp=be/ci"
fate-filter-pp5: CMD = video_filter "pp=md" fate-filter-pp5: CMD = video_filter "pp=md"
fate-filter-pp6: CMD = video_filter "pp=be/fd" fate-filter-pp6: CMD = video_filter "pp=be/fd"
...@@ -585,8 +585,8 @@ FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview ...@@ -585,8 +585,8 @@ FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview
fate-filter-codecview: fate-vsynth1-mpeg4-qprd fate-filter-codecview: fate-vsynth1-mpeg4-qprd
fate-filter-codecview: CMD = framecrc -flags bitexact -idct simple -flags2 +export_mvs -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf codecview=mv=pf+bf+bb fate-filter-codecview: CMD = framecrc -flags bitexact -idct simple -flags2 +export_mvs -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf codecview=mv=pf+bf+bb
FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp #FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp
fate-filter-qp: CMD = video_filter "qp=17,pp=be/hb/vb/tn/l5/al" fate-filter-qp: CMD = video_filter "qp=34,pp=be/hb/vb/tn/l5/al"
FATE_FILTER_VSYNTH-$(CONFIG_SELECT_FILTER) += fate-filter-select FATE_FILTER_VSYNTH-$(CONFIG_SELECT_FILTER) += fate-filter-select
fate-filter-select: CMD = framecrc -flags bitexact -idct simple -i $(SRC) -vf "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))" -frames:v 25 -flags +bitexact fate-filter-select: CMD = framecrc -flags bitexact -idct simple -i $(SRC) -vf "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))" -frames:v 25 -flags +bitexact
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment