[FFmpeg-devel] [PATCH 2/7] vf_drawtext: Add ability to show AFD value

Devin Heitmueller devin.heitmueller at ltnglobal.com
Wed Jun 7 23:22:22 EEST 2023


Add an "afd" variable which shows the current AFD side data for
the given frame.  This is to assist in debugging as it allows us
to burn the current AFD right into the video.

Example usage:

./ffmpeg -y -i afd.ts -vf drawtext=fontfile=/Library/Fonts/Verdana.ttf:text="AFD=%{afd}":fontsize=32:x=10:y=50:fontcolor=blue burnin.ts

Signed-off-by: Devin Heitmueller <dheitmueller at ltnglobal.com>
---
 doc/filters.texi          |  5 +++++
 libavfilter/vf_drawtext.c | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index a46357b..9179c20 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -12601,6 +12601,11 @@ The following functions are available:
 
 @table @command
 
+ at item afd
+The Active Format Descriptor value of the current frame (as specified in the
+frame's side data).  This can be useful for debugging aspect ratio issues.
+See standards ETSI TS 101 154 or SMPTE ST2016-1 for more details on its meaning.
+
 @item expr, e
 The expression evaluation result.
 
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 71ab851..32accfb 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -221,6 +221,7 @@ typedef struct DrawTextContext {
     int text_shaping;               ///< 1 to shape the text before drawing it
 #endif
     AVDictionary *metadata;
+    AVFrame *frame;
 } DrawTextContext;
 
 #define OFFSET(x) offsetof(DrawTextContext, x)
@@ -1056,6 +1057,22 @@ static int func_metadata(AVFilterContext *ctx, AVBPrint *bp,
     return 0;
 }
 
+static int func_afd(AVFilterContext *ctx, AVBPrint *bp,
+                    char *fct, unsigned argc, char **argv, int tag)
+{
+    DrawTextContext *s = ctx->priv;
+    AVFrameSideData *side_data;
+
+    side_data = av_frame_get_side_data(s->frame, AV_FRAME_DATA_AFD);
+    if (side_data) {
+        av_bprintf(bp, "0x%02x", side_data->data[0]);
+    } else {
+        av_bprintf(bp, "none");
+    }
+
+    return 0;
+}
+
 static int func_strftime(AVFilterContext *ctx, AVBPrint *bp,
                          char *fct, unsigned argc, char **argv, int tag)
 {
@@ -1234,6 +1251,7 @@ static const struct drawtext_function {
     { "frame_num", 0, 0, 0,   func_frame_num },
     { "n",         0, 0, 0,   func_frame_num },
     { "metadata",  1, 2, 0,   func_metadata },
+    { "afd",       0, 0, 0,   func_afd },
 };
 
 static int eval_function(AVFilterContext *ctx, AVBPrint *bp, char *fct,
@@ -1680,6 +1698,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     s->var_values[VAR_DURATION] = frame->duration * av_q2d(inlink->time_base);
 
     s->metadata = frame->metadata;
+    s->frame = frame;
 
     for (int i = 0; i < loop; i++) {
         if (header) {
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list