From 9842d6707fd660fc8dfd3a29c48a55c1293adeca Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Mon, 29 Jun 2015 07:38:16 +0000 Subject: avfilter/avf_showvolume: optionally display channel names Signed-off-by: Paul B Mahol --- libavfilter/avf_showvolume.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/avf_showvolume.c b/libavfilter/avf_showvolume.c index 8636de61c5..72e18d5d09 100644 --- a/libavfilter/avf_showvolume.c +++ b/libavfilter/avf_showvolume.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavutil/xga_font_data.h" #include "avfilter.h" #include "formats.h" #include "audio.h" @@ -38,6 +39,7 @@ typedef struct ShowVolumeContext { AVFrame *out; AVExpr *c_expr; + int draw_text; } ShowVolumeContext; #define OFFSET(x) offsetof(ShowVolumeContext, x) @@ -51,6 +53,7 @@ static const AVOption showvolume_options[] = { { "h", "set channel height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=20}, 1, 100, FLAGS }, { "f", "set fade", OFFSET(f), AV_OPT_TYPE_INT, {.i64=20}, 1, 255, FLAGS }, { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="if(gte(VOLUME,-2), if(gte(VOLUME,-1),0xff, 0xffff),0xff00)"}, 0, 0, FLAGS }, + { "t", "display channel names", OFFSET(draw_text), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS }, { NULL } }; @@ -133,6 +136,29 @@ static int config_output(AVFilterLink *outlink) return 0; } +static void drawtext(AVFrame *pic, int x, int y, const char *txt) +{ + const uint8_t *font; + int font_height; + int i; + + font = avpriv_cga_font, font_height = 8; + + for (i = 0; txt[i]; i++) { + int char_y, mask; + uint8_t *p = pic->data[0] + y*pic->linesize[0] + (x + i*8)*4; + + for (char_y = 0; char_y < font_height; char_y++) { + for (mask = 0x80; mask; mask >>= 1) { + if (font[txt[i] * font_height + char_y] & mask) + AV_WN32(p, ~AV_RN32(p)); + p += 4; + } + p += pic->linesize[0] - 8*4; + } + } +} + static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) { AVFilterContext *ctx = inlink->dst; @@ -183,6 +209,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) for (k = 0; k < s->w * max; k++) AV_WN32A(dst + k * 4, color); } + + if (s->h >= 8 && s->draw_text) + drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, + av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c))); } av_frame_free(&insamples); -- cgit v1.2.3