History

lavfi: add frame counter into AVFilterLink and use it in filters.

Clément Bœsch committed 13 years ago

Commit b8a5c761 parent f4596e815 files · +27 −33Browse files

Unified · Split

15 files
  1. libavfilter/avfilter.c +1 −0
  2. libavfilter/avfilter.h +5 −0
  3. libavfilter/f_select.c +1 −1
  4. libavfilter/vf_blackdetect.c +2 −4
  5. libavfilter/vf_blend.c +1 −2
  6. libavfilter/vf_crop.c +1 −2
  7. libavfilter/vf_decimate.c +1 −2
  8. libavfilter/vf_drawtext.c +3 −4
  9. libavfilter/vf_fieldmatch.c +3 −5
  10. libavfilter/vf_framestep.c +2 −2
  11. libavfilter/vf_geq.c +1 −2
  12. libavfilter/vf_hue.c +1 −2
  13. libavfilter/vf_overlay.c +1 −1
  14. libavfilter/vf_separatefields.c +3 −4
  15. libavfilter/vf_telecine.c +1 −2
libavfilter/avfilter.c+1−0
@@ -915,6 +915,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) · 914 unmodified lines
915915
916916 pts = out->pts;
917917 ret = filter_frame(link, out);
918+ link->frame_count++;
918919 link->frame_requested = 0;
919920 ff_update_link_current_pts(link, pts);
920921 return ret;
libavfilter/avfilter.h+5−0
@@ -718,6 +718,11 @@ struct AVFilterLink { · 717 unmodified lines
718718 * Link processing flags.
719719 */
720720 unsigned flags;
721+
722+ /**
723+ * Number of past frames sent through the link.
724+ */
725+ int64_t frame_count;
721726 };
722727
723728 /**
libavfilter/f_select.c+1−1
@@ -283,6 +283,7 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) · 282 unmodified lines
283283 if (isnan(select->var_values[VAR_START_T]))
284284 select->var_values[VAR_START_T] = TS2D(frame->pts) * av_q2d(inlink->time_base);
285285
286+ select->var_values[VAR_N ] = inlink->frame_count;
286287 select->var_values[VAR_PTS] = TS2D(frame->pts);
287288 select->var_values[VAR_T ] = TS2D(frame->pts) * av_q2d(inlink->time_base);
288289 select->var_values[VAR_POS] = av_frame_get_pkt_pos(frame) == -1 ? NAN : av_frame_get_pkt_pos(frame);
@@ -352,7 +353,6 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) · 63 unmodified lines
352353 select->var_values[VAR_CONSUMED_SAMPLES_N] += frame->nb_samples;
353354 }
354355
355− select->var_values[VAR_N] += 1.0;
356356 select->var_values[VAR_PREV_PTS] = select->var_values[VAR_PTS];
357357 select->var_values[VAR_PREV_T] = select->var_values[VAR_T];
358358 }
libavfilter/vf_blackdetect.c+2−4
@@ -43,7 +43,6 @@ typedef struct { · 42 unmodified lines
4343 double pixel_black_th;
4444 unsigned int pixel_black_th_i;
4545
46− unsigned int frame_count; ///< frame number
4746 unsigned int nb_black_pixels; ///< number of black pixels counted so far
4847 } BlackDetectContext;
4948
@@ -149,8 +148,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) · 99 unmodified lines
149148 picture_black_ratio = (double)blackdetect->nb_black_pixels / (inlink->w * inlink->h);
150149
151150 av_log(ctx, AV_LOG_DEBUG,
152− "frame:%u picture_black_ratio:%f pts:%s t:%s type:%c\n",
153− blackdetect->frame_count, picture_black_ratio,
151+ "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n",
152+ inlink->frame_count, picture_black_ratio,
154153 av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base),
155154 av_get_picture_type_char(picref->pict_type));
156155
@@ -168,7 +167,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) · 11 unmodified lines
168167 }
169168
170169 blackdetect->last_picref_pts = picref->pts;
171− blackdetect->frame_count++;
172170 blackdetect->nb_black_pixels = 0;
173171 return ff_filter_frame(inlink->dst->outputs[0], picref);
174172 }
libavfilter/vf_blend.c+1−2
@@ -81,7 +81,6 @@ typedef struct { · 80 unmodified lines
8181 struct FFBufQueue queue_bottom;
8282 int hsub, vsub; ///< chroma subsampling values
8383 int frame_requested;
84− int framenum;
8584 char *all_expr;
8685 enum BlendMode all_mode;
8786 double all_opacity;
@@ -382,7 +381,7 @@ static void blend_frame(AVFilterContext *ctx, · 294 unmodified lines
382381 uint8_t *bottom = bottom_buf->data[plane];
383382
384383 param = &b->params[plane];
385− param->values[VAR_N] = b->framenum++;
384+ param->values[VAR_N] = inlink->frame_count;
386385 param->values[VAR_T] = dst_buf->pts == AV_NOPTS_VALUE ? NAN : dst_buf->pts * av_q2d(inlink->time_base);
387386 param->values[VAR_W] = outw;
388387 param->values[VAR_H] = outh;
libavfilter/vf_crop.c+1−2
@@ -259,6 +259,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) · 258 unmodified lines
259259 frame->width = crop->w;
260260 frame->height = crop->h;
261261
262+ crop->var_values[VAR_N] = link->frame_count;
262263 crop->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ?
263264 NAN : frame->pts * av_q2d(link->time_base);
264265 crop->var_values[VAR_POS] = av_frame_get_pkt_pos(frame) == -1 ?
@@ -299,8 +300,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) · 34 unmodified lines
299300 frame->data[3] += crop->x * crop->max_step[3];
300301 }
301302
302− crop->var_values[VAR_N] += 1.0;
303−
304303 return ff_filter_frame(link->dst->outputs[0], frame);
305304 }
306305
libavfilter/vf_decimate.c+1−2
@@ -40,7 +40,6 @@ typedef struct { · 39 unmodified lines
4040 int fid; ///< current frame id in the queue
4141 int filled; ///< 1 if the queue is filled, 0 otherwise
4242 AVFrame *last; ///< last frame from the previous queue
43− int64_t frame_count; ///< output frame counter
4443 AVFrame **clean_src; ///< frame queue for the clean source
4544 int got_frame[2]; ///< frame request flag for each input stream
4645 double ts_unit; ///< timestamp units for the output frames
@@ -215,7 +214,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 168 unmodified lines
215214 av_frame_free(&frame);
216215 frame = dm->clean_src[i];
217216 }
218− frame->pts = dm->frame_count++ * dm->ts_unit;
217+ frame->pts = outlink->frame_count * dm->ts_unit;
219218 ret = ff_filter_frame(outlink, frame);
220219 if (ret < 0)
221220 break;
libavfilter/vf_drawtext.c+3−4
@@ -164,7 +164,6 @@ typedef struct { · 163 unmodified lines
164164 AVRational tc_rate; ///< frame rate for timecode
165165 AVTimecode tc; ///< timecode context
166166 int tc24hmax; ///< 1 if timecode is wrapped to 24 hours, 0 otherwise
167− int frame_id;
168167 int reload; ///< reload text file for each frame
169168 } DrawTextContext;
170169
@@ -820,6 +819,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, · 649 unmodified lines
820819 int width, int height)
821820 {
822821 DrawTextContext *dtext = ctx->priv;
822+ AVFilterLink *inlink = ctx->inputs[0];
823823 uint32_t code = 0, prev_code = 0;
824824 int x = 0, y = 0, i = 0, ret;
825825 int max_text_line_w = 0, len;
@@ -857,7 +857,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, · 31 unmodified lines
857857
858858 if (dtext->tc_opt_string) {
859859 char tcbuf[AV_TIMECODE_STR_SIZE];
860− av_timecode_make_string(&dtext->tc, tcbuf, dtext->frame_id++);
860+ av_timecode_make_string(&dtext->tc, tcbuf, inlink->frame_count);
861861 av_bprint_clear(bp);
862862 av_bprintf(bp, "%s%s", dtext->text, tcbuf);
863863 }
@@ -983,6 +983,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 119 unmodified lines
983983 if ((ret = load_textfile(ctx)) < 0)
984984 return ret;
985985
986+ dtext->var_values[VAR_N] = inlink->frame_count;
986987 dtext->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ?
987988 NAN : frame->pts * av_q2d(inlink->time_base);
988989
@@ -993,8 +994,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 4 unmodified lines
993994 (int)dtext->var_values[VAR_TEXT_W], (int)dtext->var_values[VAR_TEXT_H],
994995 dtext->x, dtext->y);
995996
996− dtext->var_values[VAR_N] += 1.0;
997−
998997 return ff_filter_frame(outlink, frame);
999998 }
1000999
libavfilter/vf_fieldmatch.c+3−5
@@ -77,7 +77,6 @@ typedef struct { · 76 unmodified lines
7777
7878 AVFrame *prv, *src, *nxt; ///< main sliding window of 3 frames
7979 AVFrame *prv2, *src2, *nxt2; ///< sliding window of the optional second stream
80− int64_t frame_count; ///< output frame counter
8180 int got_frame[2]; ///< frame request flag for each input stream
8281 int hsub, vsub; ///< chroma subsampling values
8382 uint32_t eof; ///< bitmask for end of stream
@@ -738,7 +737,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 654 unmodified lines
738737
739738 /* scene change check */
740739 if (fm->combmatch == COMBMATCH_SC) {
741− if (fm->lastn == fm->frame_count - 1) {
740+ if (fm->lastn == outlink->frame_count - 1) {
742741 if (fm->lastscdiff > fm->scthresh)
743742 sc = 1;
744743 } else if (luma_abs_diff(fm->prv, fm->src) > fm->scthresh) {
@@ -746,7 +745,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 1 unmodified line
746745 }
747746
748747 if (!sc) {
749− fm->lastn = fm->frame_count;
748+ fm->lastn = outlink->frame_count;
750749 fm->lastscdiff = luma_abs_diff(fm->src, fm->nxt);
751750 sc = fm->lastscdiff > fm->scthresh;
752751 }
@@ -805,10 +804,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 52 unmodified lines
805804 dst->interlaced_frame = combs[match] >= fm->combpel;
806805 if (dst->interlaced_frame) {
807806 av_log(ctx, AV_LOG_WARNING, "Frame #%"PRId64" at %s is still interlaced\n",
808− fm->frame_count, av_ts2timestr(in->pts, &inlink->time_base));
807+ outlink->frame_count, av_ts2timestr(in->pts, &inlink->time_base));
809808 dst->top_field_first = field;
810809 }
811− fm->frame_count++;
812810
813811 av_log(ctx, AV_LOG_DEBUG, "SC:%d | COMBS: %3d %3d %3d %3d %3d (combpel=%d)"
814812 " match=%d combed=%s\n", sc, combs[0], combs[1], combs[2], combs[3], combs[4],
libavfilter/vf_framestep.c+2−2
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030
3131 typedef struct {
3232 const AVClass *class;
33− int frame_step, frame_count;
33+ int frame_step;
3434 } FrameStepContext;
3535
3636 #define OFFSET(x) offsetof(FrameStepContext, x)
@@ -64,7 +64,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref) · 27 unmodified lines
6464 {
6565 FrameStepContext *framestep = inlink->dst->priv;
6666
67− if (!(framestep->frame_count++ % framestep->frame_step)) {
67+ if (!(inlink->frame_count % framestep->frame_step)) {
6868 return ff_filter_frame(inlink->dst->outputs[0], ref);
6969 } else {
7070 av_frame_free(&ref);
libavfilter/vf_geq.c+1−2
@@ -36,7 +36,6 @@ typedef struct { · 35 unmodified lines
3636 const AVClass *class;
3737 AVExpr *e[4]; ///< expressions for each plane
3838 char *expr_str[4]; ///< expression strings for each plane
39− int framenum; ///< frame counter
4039 AVFrame *picref; ///< current input buffer
4140 int hsub, vsub; ///< chroma subsampling
4241 int planes; ///< number of planes
@@ -163,7 +162,7 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in) · 120 unmodified lines
163162 AVFilterLink *outlink = inlink->dst->outputs[0];
164163 AVFrame *out;
165164 double values[VAR_VARS_NB] = {
166− [VAR_N] = geq->framenum++,
165+ [VAR_N] = inlink->frame_count,
167166 [VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
168167 };
169168
libavfilter/vf_hue.c+1−2
@@ -252,6 +252,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 251 unmodified lines
252252 av_frame_copy_props(outpic, inpic);
253253 }
254254
255+ hue->var_values[VAR_N] = inlink->frame_count;
255256 hue->var_values[VAR_T] = TS2T(inpic->pts, inlink->time_base);
256257 hue->var_values[VAR_PTS] = TS2D(inpic->pts);
257258
@@ -281,8 +282,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 23 unmodified lines
281282
282283 compute_sin_and_cos(hue);
283284
284− hue->var_values[VAR_N] += 1;
285−
286285 if (!direct) {
287286 av_image_copy_plane(outpic->data[0], outpic->linesize[0],
288287 inpic->data[0], inpic->linesize[0],
libavfilter/vf_overlay.c+1−1
@@ -600,6 +600,7 @@ static int try_filter_frame(AVFilterContext *ctx, AVFrame *mainpic) · 599 unmodified lines
600600 if (over->eval_mode == EVAL_MODE_FRAME) {
601601 int64_t pos = av_frame_get_pkt_pos(mainpic);
602602
603+ over->var_values[VAR_N] = inlink->frame_count;
603604 over->var_values[VAR_T] = mainpic->pts == AV_NOPTS_VALUE ?
604605 NAN : mainpic->pts * av_q2d(inlink->time_base);
605606 over->var_values[VAR_POS] = pos == -1 ? NAN : pos;
@@ -614,7 +615,6 @@ static int try_filter_frame(AVFilterContext *ctx, AVFrame *mainpic) · 8 unmodified lines
614615 if (over->enable)
615616 blend_image(ctx, mainpic, over->overpicref, over->x, over->y);
616617
617− over->var_values[VAR_N] += 1.0;
618618 }
619619 ret = ff_filter_frame(ctx->outputs[0], mainpic);
620620 av_assert1(ret != AVERROR(EAGAIN));
libavfilter/vf_separatefields.c+3−4
@@ -24,7 +24,6 @@ · 23 unmodified lines
2424
2525 typedef struct {
2626 int nb_planes;
27− int64_t frame_count;
2827 double ts_unit;
2928 } SeparateFieldsContext;
3029
@@ -76,12 +75,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) · 45 unmodified lines
7675 second->linesize[i] *= 2;
7776 }
7877
79− inpicref->pts = sf->frame_count++ * sf->ts_unit;
80− second->pts = sf->frame_count++ * sf->ts_unit;
81−
78+ inpicref->pts = outlink->frame_count * sf->ts_unit;
8279 ret = ff_filter_frame(outlink, inpicref);
8380 if (ret < 0)
8481 return ret;
82+
83+ second->pts = outlink->frame_count * sf->ts_unit;
8584 return ff_filter_frame(outlink, second);
8685 }
8786
libavfilter/vf_telecine.c+1−2
@@ -43,7 +43,6 @@ typedef struct { · 42 unmodified lines
4343 double ts_unit;
4444 int out_cnt;
4545 int occupied;
46− int64_t frame_count;
4746
4847 int nb_planes;
4948 int planeheight[4];
@@ -233,7 +232,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) · 183 unmodified lines
233232 }
234233
235234 av_frame_copy_props(frame, inpicref);
236− frame->pts = tc->frame_count++ * tc->ts_unit;
235+ frame->pts = outlink->frame_count * tc->ts_unit;
237236 ret = ff_filter_frame(outlink, frame);
238237 }
239238 av_frame_free(&inpicref);

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