Skip to content

Commit da5497a

Browse files
committed
avfilter/vf_codecview: added new options for block
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
1 parent 9f40b5b commit da5497a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

doc/filters.texi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8184,6 +8184,9 @@ means. For example, some MPEG based codecs export motion vectors through the
81848184
The filter accepts the following option:
81858185

81868186
@table @option
8187+
@item block
8188+
Display block partition structure using the luma plane.
8189+
81878190
@item mv
81888191
Set motion vectors to visualize.
81898192

libavfilter/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#define LIBAVFILTER_VERSION_MAJOR 8
3333
#define LIBAVFILTER_VERSION_MINOR 10
34-
#define LIBAVFILTER_VERSION_MICRO 100
34+
#define LIBAVFILTER_VERSION_MICRO 101
3535

3636

3737
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \

libavfilter/vf_codecview.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "libavutil/imgutils.h"
3333
#include "libavutil/motion_vector.h"
3434
#include "libavutil/opt.h"
35+
#include "libavutil/video_enc_params.h"
3536
#include "avfilter.h"
3637
#include "qp_table.h"
3738
#include "internal.h"
@@ -52,6 +53,7 @@ typedef struct CodecViewContext {
5253
unsigned mv_type;
5354
int hsub, vsub;
5455
int qp;
56+
int block;
5557
} CodecViewContext;
5658

5759
#define OFFSET(x) offsetof(CodecViewContext, x)
@@ -73,6 +75,7 @@ static const AVOption codecview_options[] = {
7375
CONST("if", "I-frames", FRAME_TYPE_I, "frame_type"),
7476
CONST("pf", "P-frames", FRAME_TYPE_P, "frame_type"),
7577
CONST("bf", "B-frames", FRAME_TYPE_B, "frame_type"),
78+
{ "block", "set block partitioning structure to visualize", OFFSET(block), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
7679
{ NULL }
7780
};
7881

@@ -210,6 +213,21 @@ static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
210213
draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
211214
}
212215

216+
static void draw_block_rectangle(uint8_t *buf, int sx, int sy, int w, int h, int stride, int color)
217+
{
218+
for (int x = sx; x < sx + w; x++)
219+
buf[x] = color;
220+
221+
for (int y = sy; y < sy + h; y++) {
222+
buf[sx] = color;
223+
buf[sx + w - 1] = color;
224+
buf += stride;
225+
}
226+
227+
for (int x = sx; x < sx + w; x++)
228+
buf[x] = color;
229+
}
230+
213231
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
214232
{
215233
AVFilterContext *ctx = inlink->dst;
@@ -247,6 +265,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
247265
av_freep(&qp_table);
248266
}
249267

268+
if (s->block) {
269+
AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
270+
if (sd) {
271+
AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
272+
const int stride = frame->linesize[0];
273+
274+
if (par->nb_blocks) {
275+
for (int block_idx = 0; block_idx < par->nb_blocks; block_idx++) {
276+
AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
277+
uint8_t *buf = frame->data[0] + b->src_y * stride;
278+
279+
draw_block_rectangle(buf, b->src_x, b->src_y, b->w, b->h, stride, 100);
280+
}
281+
}
282+
}
283+
}
284+
250285
if (s->mv || s->mv_type) {
251286
AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MOTION_VECTORS);
252287
if (sd) {

0 commit comments

Comments
 (0)