aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter
diff options
context:
space:
mode:
authorNicolas George <george@nsup.org>2016-12-20 17:13:04 +0100
committerNicolas George <george@nsup.org>2017-01-12 14:06:16 +0100
commite7e4c8dfbe9d4be289d1181365fa6e5d9fef5349 (patch)
treed82a0ebba01a3e827ef692e9b5f8f6bbae4e11fa /libavfilter
parent0e3d2496e2eec1c911b169682067d53ea9a0388c (diff)
downloadffmpeg-e7e4c8dfbe9d4be289d1181365fa6e5d9fef5349.tar.gz
lavfi: add ff_inlink_evaluate_timeline_at_frame().
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/avfilter.c34
-rw-r--r--libavfilter/filters.h8
2 files changed, 29 insertions, 13 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 1699df8795..c72447d1e0 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1100,7 +1100,6 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
AVFilterContext *dstctx = link->dst;
AVFilterPad *dst = link->dstpad;
int ret;
- int64_t pts;
if (!(filter_frame = dst->filter_frame))
filter_frame = default_filter_frame;
@@ -1112,24 +1111,15 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
}
ff_inlink_process_commands(link, frame);
+ dstctx->is_disabled = !ff_inlink_evaluate_timeline_at_frame(link, frame);
- pts = frame->pts;
- if (dstctx->enable_str) {
- int64_t pos = av_frame_get_pkt_pos(frame);
- dstctx->var_values[VAR_N] = link->frame_count_out;
- dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base);
- dstctx->var_values[VAR_W] = link->w;
- dstctx->var_values[VAR_H] = link->h;
- dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
-
- dstctx->is_disabled = fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) < 0.5;
+ /* TODO reindent */
if (dstctx->is_disabled &&
(dstctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC))
filter_frame = default_filter_frame;
- }
ret = filter_frame(link, frame);
link->frame_count_out++;
- ff_update_link_current_pts(link, pts);
+ ff_update_link_current_pts(link, frame->pts);
return ret;
fail:
@@ -1575,6 +1565,24 @@ int ff_inlink_process_commands(AVFilterLink *link, const AVFrame *frame)
return 0;
}
+int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *frame)
+{
+ AVFilterContext *dstctx = link->dst;
+ int64_t pts = frame->pts;
+ int64_t pos = av_frame_get_pkt_pos(frame);
+
+ if (!dstctx->enable_str)
+ return 1;
+
+ dstctx->var_values[VAR_N] = link->frame_count_out;
+ dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base);
+ dstctx->var_values[VAR_W] = link->w;
+ dstctx->var_values[VAR_H] = link->h;
+ dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
+
+ return fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) >= 0.5;
+}
+
const AVClass *avfilter_get_class(void)
{
return &avfilter_class;
diff --git a/libavfilter/filters.h b/libavfilter/filters.h
index 7535f1df90..0da1d8bd99 100644
--- a/libavfilter/filters.h
+++ b/libavfilter/filters.h
@@ -47,6 +47,14 @@ void ff_filter_set_ready(AVFilterContext *filter, unsigned priority);
int ff_inlink_process_commands(AVFilterLink *link, const AVFrame *frame);
/**
+ * Evaluate the timeline expression of the link for the time and properties
+ * of the frame.
+ * @return >0 if enabled, 0 if disabled
+ * @note It does not update link->dst->is_disabled.
+ */
+int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *frame);
+
+/**
* Make sure a frame is writable.
* This is similar to av_frame_make_writable() except it uses the link's
* buffer allocation callback, and therefore allows direct rendering.