diff options
author | Paul B Mahol <onemda@gmail.com> | 2015-06-29 07:38:16 +0000 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2015-06-29 07:53:56 +0000 |
commit | 9842d6707fd660fc8dfd3a29c48a55c1293adeca (patch) | |
tree | 4b90e2e43bd2240b8d45e1a6b2ab2fd85986165a | |
parent | e55e5be982a6d2429e9fc3516683da4c30b179f4 (diff) | |
download | ffmpeg-9842d6707fd660fc8dfd3a29c48a55c1293adeca.tar.gz |
avfilter/avf_showvolume: optionally display channel names
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r-- | doc/filters.texi | 3 | ||||
-rw-r--r-- | libavfilter/avf_showvolume.c | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index 8b2c5ea541..6365c0a580 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12023,6 +12023,9 @@ The expression can use the following variables: @item VOLUME Current max volume of channel in dB. @end table + +@item t +If set, displays channel names. Default is enabled. @end table @section showwaves 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); |