[FFmpeg-cvslog] avfilter/avf_showvolume: optionally display channel names

Paul B Mahol git at videolan.org
Mon Jun 29 18:32:42 CEST 2015


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Jun 29 07:38:16 2015 +0000| [9842d6707fd660fc8dfd3a29c48a55c1293adeca] | committer: Paul B Mahol

avfilter/avf_showvolume: optionally display channel names

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9842d6707fd660fc8dfd3a29c48a55c1293adeca
---

 doc/filters.texi             |    3 +++
 libavfilter/avf_showvolume.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 8b2c5ea..6365c0a 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
+
+ at 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 8636de6..72e18d5 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);



More information about the ffmpeg-cvslog mailing list