diff mbox series

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

Message ID 1688161135-11774-3-git-send-email-dheitmueller@ltnglobal.com
State New
Headers show
Series Misc AFD improvements and support for Bar Data | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Devin Heitmueller June 30, 2023, 9:38 p.m. UTC
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@ltnglobal.com>

Conflicts:
	libavfilter/vf_drawtext.c
---
 doc/filters.texi          |  5 +++++
 libavfilter/vf_drawtext.c | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index f17488c..793868b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -12698,6 +12698,11 @@  The following functions are available:
 
 @table @command
 
+@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 7854362..76ab016 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -319,7 +319,6 @@  typedef struct DrawTextContext {
     int text_shaping;               ///< 1 to shape the text before drawing it
 #endif
     AVDictionary *metadata;
-
     int boxw;                       ///< the value of the boxw parameter
     int boxh;                       ///< the value of the boxh parameter
     int text_align;                 ///< the horizontal and vertical text alignment
@@ -331,6 +330,7 @@  typedef struct DrawTextContext {
     int tab_count;                  ///< the number of tab characters
     int blank_advance64;            ///< the size of the space character
     int tab_warning_printed;        ///< ensure the tab warning to be printed only once
+    AVFrame *frame;
 } DrawTextContext;
 
 #define OFFSET(x) offsetof(DrawTextContext, x)
@@ -1251,6 +1251,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)
 {
@@ -1429,6 +1445,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,
@@ -2153,6 +2170,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) {