History

avfilter/f_drawgraph: add rate/r option

Paul B Mahol committed 6 years ago

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

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/f_drawgraph.c+22−1
@@ -40,6 +40,7 @@ typedef struct DrawGraphContext { · 39 unmodified lines
4040 int mode;
4141 int slide;
4242 int w, h;
43+ AVRational frame_rate;
4344
4445 AVFrame *out;
4546 int x;
@@ -48,6 +49,7 @@ typedef struct DrawGraphContext { · 2 unmodified lines
4849 float *values[4];
4950 int values_size[4];
5051 int nb_values;
52+ int64_t prev_pts;
5153 } DrawGraphContext;
5254
5355 #define OFFSET(x) offsetof(DrawGraphContext, x)
@@ -77,6 +79,8 @@ static const AVOption drawgraph_options[] = { · 23 unmodified lines
7779 {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},
7880 { "size", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },
7981 { "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 },
8084 { NULL }
8185 };
8286
@@ -159,6 +163,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 76 unmodified lines
159163 AVDictionary *metadata;
160164 AVDictionaryEntry *e;
161165 AVFrame *out = s->out;
166+ AVFrame *clone = NULL;
167+ int64_t in_pts, out_pts;
162168 int i;
163169
164170 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
309315 s->nb_values++;
310316 s->x++;
311317
318+ in_pts = in->pts;
319+
312320 av_frame_free(&in);
313321
314322 if (s->slide == 4)
315323 return 0;
316324
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);
318336 }
319337
320338 static int request_frame(AVFilterLink *outlink)
@@ -406,6 +424,9 @@ static int config_output(AVFilterLink *outlink) · 85 unmodified lines
406424 outlink->w = s->w;
407425 outlink->h = s->h;
408426 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;
409430
410431 return 0;
411432 }

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