* Set timebase for the output link.
*/
+#include <inttypes.h>
+#include <stdio.h>
+
#include "libavutil/avstring.h"
#include "libavutil/eval.h"
+#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
#include "libavutil/rational.h"
#include "avfilter.h"
#include "internal.h"
};
typedef struct {
- char tb_expr[256];
+ const AVClass *class;
+ char *tb_expr;
double var_values[VAR_VARS_NB];
} SetTBContext;
-static av_cold int init(AVFilterContext *ctx, const char *args)
-{
- SetTBContext *settb = ctx->priv;
- av_strlcpy(settb->tb_expr, "intb", sizeof(settb->tb_expr));
-
- if (args)
- sscanf(args, "%255[^:]", settb->tb_expr);
-
- return 0;
-}
-
static int config_output_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
return 0;
}
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
- AVFilterBufferRef *picref2 = picref;
if (av_cmp_q(inlink->time_base, outlink->time_base)) {
- picref2 = avfilter_ref_buffer(picref, ~0);
- picref2->pts = av_rescale_q(picref->pts, inlink->time_base, outlink->time_base);
+ int64_t orig_pts = frame->pts;
+ frame->pts = av_rescale_q(frame->pts, inlink->time_base, outlink->time_base);
av_log(ctx, AV_LOG_DEBUG, "tb:%d/%d pts:%"PRId64" -> tb:%d/%d pts:%"PRId64"\n",
- inlink ->time_base.num, inlink ->time_base.den, picref ->pts,
- outlink->time_base.num, outlink->time_base.den, picref2->pts);
- avfilter_unref_buffer(picref);
+ inlink ->time_base.num, inlink ->time_base.den, orig_pts,
+ outlink->time_base.num, outlink->time_base.den, frame->pts);
}
- ff_start_frame(outlink, picref2);
+ return ff_filter_frame(outlink, frame);
}
-AVFilter avfilter_vf_settb = {
+#define OFFSET(x) offsetof(SetTBContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+ { "expr", "Expression determining the output timebase", OFFSET(tb_expr), AV_OPT_TYPE_STRING, { .str = "intb" }, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVClass settb_class = {
+ .class_name = "settb",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVFilterPad avfilter_vf_settb_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer = ff_null_get_video_buffer,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad avfilter_vf_settb_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_output_props,
+ },
+ { NULL }
+};
+
+AVFilter ff_vf_settb = {
.name = "settb",
.description = NULL_IF_CONFIG_SMALL("Set timebase for the output link."),
- .init = init,
.priv_size = sizeof(SetTBContext),
+ .priv_class = &settb_class,
+
+ .inputs = avfilter_vf_settb_inputs,
- .inputs = (AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .get_video_buffer = ff_null_get_video_buffer,
- .start_frame = start_frame,
- .end_frame = ff_null_end_frame },
- { .name = NULL }},
-
- .outputs = (AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .config_props = config_output_props, },
- { .name = NULL}},
+ .outputs = avfilter_vf_settb_outputs,
};