diff mbox

[FFmpeg-devel] vf_drawtext: Add pkt_pos, pkt_duration, pkt_size as variables

Message ID CAFrfS6anU9qLQMP3U2p8C9AHqucLW=6jT2oFwHwMtYgGDeQtBg@mail.gmail.com
State Superseded
Headers show

Commit Message

greg Luce June 10, 2019, 11:05 p.m. UTC
I created this issue on the bugtracker but I'm trying to format it
properly for this channel
https://trac.ffmpeg.org/ticket/7947
The actual filter change was written by Calvin Walton <calvin.walton@kepstin.ca>

---

     draw_text(ctx, frame, frame->width, frame->height);
---

Comments

greg Luce June 10, 2019, 11:34 p.m. UTC | #1
On Mon, 10 Jun 2019 at 19:05, greg Luce <electron.rotoscope@gmail.com> wrote:
> +If you're trying to read data from teh frames in a stream or file, run
Sorry, this should read "the" not "teh"
Gyan Doshi June 11, 2019, 6:32 a.m. UTC | #2
On 11-06-2019 04:35 AM, greg Luce wrote:
> I created this issue on the bugtracker but I'm trying to format it
> properly for this channel
> https://trac.ffmpeg.org/ticket/7947
> The actual filter change was written by Calvin Walton <calvin.walton@kepstin.ca>
>
> ---
> diff --git a/doc/filters.texi b/doc/filters.texi
> index ec1c7c7591..332f4ddc80 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -8584,6 +8584,17 @@ The thickness of the drawn box.
>
>   These constants allow the @var{x}, @var{y}, @var{w}, @var{h} and
> @var{t} expressions to refer to
>   each other, so you may for example specify @code{y=x/dar} or @code{h=w/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)
Add a note that a value of -1 indicates this info is not available.
> +
> +@item pkt_duration
> +The current packet's input duration
> +
> +@item pkt_size
> +The current packet's input size (in bytes)
>
>   @end table
>
> @@ -9032,6 +9043,14 @@ 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 use of the term metadata in ffmpeg refers to extra data,
> +often user-provided or generated live during decode by other filters.
Extradata in ffmpeg parlance refers primarily to codec configuration. 
Metadata is typically exported as strings by the demuxer.
(Also, filters operate *after* decoding).

> +If you're trying to read data from teh frames in a stream or file, run
> +@code{ffprobe -show_frames}. If the information doesn't show up between
> +@code{[FRAME]} and @code{[/FRAME]} in the form
> @code{TAG:[metadata_key]=[metadata_value]}
> +then it won't be visible to this function.

This isn't accurate. Metadata may be generated during filtering and 
discarded before output. In which case, drawtext inserted after 
generation can still access it but it won't show up in the input. I 
believe you are trying to document that packet fields (like the three in 
this patch) aren't available, unless specifically supported

Rewrite it as a positive statement.

"
Available metadata can be identified by inspecting entries starting with 
TAG included within each frame section printed by running @code{ffprobe 
-show_frames}.
String metadata generated in filters leading to the drawtext filter are 
also available.
  "

>   @item n, frame_num
>   The frame number, starting from 0.
>
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index 01cd7fa122..8f4badbdb5 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
>   };
>
> @@ -1516,6 +1522,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);
> ---
> _______________________________________________

Gyan
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index ec1c7c7591..332f4ddc80 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8584,6 +8584,17 @@  The thickness of the drawn box.

 These constants allow the @var{x}, @var{y}, @var{w}, @var{h} and
@var{t} expressions to refer to
 each other, so you may for example specify @code{y=x/dar} or @code{h=w/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

@@ -9032,6 +9043,14 @@  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 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 teh frames in a stream or file, run
+@code{ffprobe -show_frames}. If the information doesn't show up between
+@code{[FRAME]} and @code{[/FRAME]} in the form
@code{TAG:[metadata_key]=[metadata_value]}
+then it won't be visible to this function.
+
 @item n, frame_num
 The frame number, starting from 0.

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 01cd7fa122..8f4badbdb5 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
 };

@@ -1516,6 +1522,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;