History

avfilter/f_drawgraph: add rate/r option

Paul B Mahol committed 6 years ago

Commit d9a52b01 parent 9e01f172 files · +25 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +3 −0
  2. libavfilter/f_drawgraph.c +22 −1
doc/filters.texi+3−0
@@ -9321,6 +9321,9 @@ Set size of graph video. For the syntax of this option, check the · 9320 unmodified lines
9321@ref{video size syntax,,"Video size" section in the ffmpeg-utils manual,ffmpeg-utils}.9321@ref{video size syntax,,"Video size" section in the ffmpeg-utils manual,ffmpeg-utils}.
9322The default value is @code{900x256}.9322The default value is @code{900x256}.
9323 9323
9324@item rate, r
9325Set the output frame rate. Default value is @code{25}.
9326
9324The foreground color expressions can use the following variables:9327The foreground color expressions can use the following variables:
9325@table @option9328@table @option
9326@item MIN9329@item MIN
libavfilter/f_drawgraph.c+22−1
@@ -40,6 +40,7 @@ typedef struct DrawGraphContext { · 39 unmodified lines
40 int mode;40 int mode;
41 int slide;41 int slide;
42 int w, h;42 int w, h;
43 AVRational frame_rate;
43 44
44 AVFrame *out;45 AVFrame *out;
45 int x;46 int x;
@@ -48,6 +49,7 @@ typedef struct DrawGraphContext { · 2 unmodified lines
48 float *values[4];49 float *values[4];
49 int values_size[4];50 int values_size[4];
50 int nb_values;51 int nb_values;
52 int64_t prev_pts;
51} DrawGraphContext;53} DrawGraphContext;
52 54
53#define OFFSET(x) offsetof(DrawGraphContext, x)55#define OFFSET(x) offsetof(DrawGraphContext, x)
@@ -77,6 +79,8 @@ static const AVOption drawgraph_options[] = { · 23 unmodified lines
77 {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},79 {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},
78 { "size", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },80 { "size", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },
79 { "s", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },81 { "s", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },
82 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
83 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
80 { NULL }84 { NULL }
81};85};
82 86
@@ -159,6 +163,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 76 unmodified lines
159 AVDictionary *metadata;163 AVDictionary *metadata;
160 AVDictionaryEntry *e;164 AVDictionaryEntry *e;
161 AVFrame *out = s->out;165 AVFrame *out = s->out;
166 AVFrame *clone = NULL;
167 int64_t in_pts, out_pts;
162 int i;168 int i;
163 169
164 if (s->slide == 4 && s->nb_values >= s->values_size[0] / sizeof(float)) {170 if (s->slide == 4 && s->nb_values >= s->values_size[0] / sizeof(float)) {
@@ -309,12 +315,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 144 unmodified lines
309 s->nb_values++;315 s->nb_values++;
310 s->x++;316 s->x++;
311 317
318 in_pts = in->pts;
319
312 av_frame_free(&in);320 av_frame_free(&in);
313 321
314 if (s->slide == 4)322 if (s->slide == 4)
315 return 0;323 return 0;
316 324
317 return ff_filter_frame(outlink, av_frame_clone(s->out));325 out_pts = av_rescale_q(in_pts, inlink->time_base, outlink->time_base);
326
327 if (out_pts == s->prev_pts)
328 return 0;
329
330 clone = av_frame_clone(s->out);
331 if (!clone)
332 return AVERROR(ENOMEM);
333
334 clone->pts = s->prev_pts = out_pts;
335 return ff_filter_frame(outlink, clone);
318}336}
319 337
320static int request_frame(AVFilterLink *outlink)338static int request_frame(AVFilterLink *outlink)
@@ -406,6 +424,9 @@ static int config_output(AVFilterLink *outlink) · 85 unmodified lines
406 outlink->w = s->w;424 outlink->w = s->w;
407 outlink->h = s->h;425 outlink->h = s->h;
408 outlink->sample_aspect_ratio = (AVRational){1,1};426 outlink->sample_aspect_ratio = (AVRational){1,1};
427 outlink->frame_rate = s->frame_rate;
428 outlink->time_base = av_inv_q(outlink->frame_rate);
429 s->prev_pts = AV_NOPTS_VALUE;
409 430
410 return 0;431 return 0;
411}432}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t