diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-01-14 09:52:02 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-01-14 09:54:53 +0100 |
commit | d9a52b0bbfac06ec6a5368566a3b05eec039df04 (patch) | |
tree | fb56cdce471c6c8aed912c93cd8c4fadd86acc94 /libavfilter/f_drawgraph.c | |
parent | 9e01f171f3b7d408f93ec0409d8f9be1d8b291d8 (diff) | |
download | ffmpeg-d9a52b0bbfac06ec6a5368566a3b05eec039df04.tar.gz |
avfilter/f_drawgraph: add rate/r option
Diffstat (limited to 'libavfilter/f_drawgraph.c')
-rw-r--r-- | libavfilter/f_drawgraph.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libavfilter/f_drawgraph.c b/libavfilter/f_drawgraph.c index 955047368d..7d8bc4adb7 100644 --- a/libavfilter/f_drawgraph.c +++ b/libavfilter/f_drawgraph.c @@ -40,6 +40,7 @@ typedef struct DrawGraphContext { int mode; int slide; int w, h; + AVRational frame_rate; AVFrame *out; int x; @@ -48,6 +49,7 @@ typedef struct DrawGraphContext { float *values[4]; int values_size[4]; int nb_values; + int64_t prev_pts; } DrawGraphContext; #define OFFSET(x) offsetof(DrawGraphContext, x) @@ -77,6 +79,8 @@ static const AVOption drawgraph_options[] = { {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"}, { "size", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS }, { "s", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS }, + { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS }, + { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS }, { NULL } }; @@ -159,6 +163,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVDictionary *metadata; AVDictionaryEntry *e; AVFrame *out = s->out; + AVFrame *clone = NULL; + int64_t in_pts, out_pts; int i; 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) s->nb_values++; s->x++; + in_pts = in->pts; + av_frame_free(&in); if (s->slide == 4) return 0; - return ff_filter_frame(outlink, av_frame_clone(s->out)); + out_pts = av_rescale_q(in_pts, inlink->time_base, outlink->time_base); + + if (out_pts == s->prev_pts) + return 0; + + clone = av_frame_clone(s->out); + if (!clone) + return AVERROR(ENOMEM); + + clone->pts = s->prev_pts = out_pts; + return ff_filter_frame(outlink, clone); } static int request_frame(AVFilterLink *outlink) @@ -406,6 +424,9 @@ static int config_output(AVFilterLink *outlink) outlink->w = s->w; outlink->h = s->h; outlink->sample_aspect_ratio = (AVRational){1,1}; + outlink->frame_rate = s->frame_rate; + outlink->time_base = av_inv_q(outlink->frame_rate); + s->prev_pts = AV_NOPTS_VALUE; return 0; } |