Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#7947 closed enhancement (fixed)

Feature request: expose more frame properties as variables in drawtext filter

Reported by: electron.rotoscope Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: drawtext
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
Some properties available to ffprobe -show_frames are not available to the drawtext filter, but would be useful

I know patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker, but I don't have the skills to do that properly. Proposed changes in comments

Change History (7)

comment:1 by electron.rotoscope, 5 years ago

git checkout diff written by the amazing kepstin

From: Calvin Walton <calvin.walton@kepstin.ca>
Date: Fri, 7 Jun 2019 15:06:36 -0400
Subject: [PATCH] vf_drawtext: Add pkt_pos, pkt_duration, pkt_size as variables

---
 libavfilter/vf_drawtext.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index cca2cbcb88..beafe0ba81 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -88,6 +88,9 @@ static const char *const var_names[] = {
     "x",
     "y",
     "pict_type",
+    "pkt_pos",
+    "pkt_duration",
+    "pkt_size",
     NULL
 };
 
@@ -125,6 +128,9 @@ enum var_name {
     VAR_X,
     VAR_Y,
     VAR_PICT_TYPE,
+    VAR_PKT_POS,
+    VAR_PKT_DURATION,
+    VAR_PKT_SIZE,
     VAR_VARS_NB
 };
 
@@ -1487,6 +1493,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         NAN : frame->pts * av_q2d(inlink->time_base);
 
     s->var_values[VAR_PICT_TYPE] = frame->pict_type;
+    s->var_values[VAR_PKT_POS] = frame->pkt_pos;
+    s->var_values[VAR_PKT_DURATION] = frame->pkt_duration * av_q2d(inlink->time_base);
+    s->var_values[VAR_PKT_SIZE] = frame->pkt_size;
     s->metadata = frame->metadata;
 
     draw_text(ctx, frame, frame->width, frame->height);

comment:2 by electron.rotoscope, 5 years ago

documentation (with a typo fix and clarification on the expansion keyword "metadata") written as a poor attempt by me to be helpful

doc/filters.texi

@@ -8960,7 +8960,21
@item x
@item y
the x and y offset coordinates where the text is drawn.

These parameters allow the @var{x} and @var{y} expressions to refer
- each other, so you can for example specify @code{y=x/dar}.
+ to each other, so you can for example specify @code{y=x/dar}.
+ 
+ @item pict_type
+ a 1 character description of the current packet's input picture type.
+ 
+ @item pkt_pos
+ the current packet's position in the input datastream (in bytes from
+ the head of the source file)
+ 
+ @item pkt_duration
+ the current packet's input duration
+ 
+ @item pkt_size
+ the current packet's input size (in bytes)
@end table

@@ -9027,7 + 9027,10
@item metadata
Frame metadata. Takes one or two arguments.

The first argument is mandatory and specifies the metadata key.

The second argument is optional and specifies a default value, used when the
metadata key is not found or empty.
+ 
+ The metadata accessible to this function must show up using 
+ @code{ffprobe -show_packets} formatted as TAG:[metadata_key]=[metadata_value].
Last edited 5 years ago by electron.rotoscope (previous) (diff)

comment:3 by Gyan, 5 years ago

The author should send this to the ffmpeg-devel list using git format-patch.

+ The metadata accessible to this function must show up using 
+ @code{ffprobe -show_packets} formatted as TAG:[metadata_key]=[metadata_value].

Why? A user can always insert metadata inside the filtergraph using other filters.

in reply to:  3 comment:4 by electron.rotoscope, 5 years ago

Replying to Gyan:

The author should send this to the ffmpeg-devel list using git format-patch.

I'm trying to learn git and mailing list etiquette now well enough to be able to do this myself. I was hoping someone on here would be willing to help out.

+ The metadata accessible to this function must show up using 
+ @code{ffprobe -show_packets} formatted as TAG:[metadata_key]=[metadata_value].

Why? A user can always insert metadata inside the filtergraph using other filters.

I wasn't aware of that. My main goal was to let the people after me know that you can't pull, say, "duration_time" since in this context while that is information about data, it's not what ffmpeg generally means by metadata. Would this work better?

The use of the term metadata in ffmpeg refers to extra data, often user-provided or generated live during decode by other filters.
If you're trying to read data from a stream or file, run @code{ffprobe -show_frames}. If it doesn't show up formatted as TAG:[metadata_key]=[metadata_value] then it won't be visible to this option.

comment:5 by electron.rotoscope, 5 years ago

Version: unspecifiedgit-master
Last edited 5 years ago by electron.rotoscope (previous) (diff)

comment:6 by electron.rotoscope, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.