[FFmpeg-devel] [PATCH] lavfi: implement asettb filter.
Stefano Sabatini
stefasab at gmail.com
Sat Jun 23 15:06:16 CEST 2012
On date Saturday 2012-06-23 12:22:59 +0200, Nicolas George encoded:
>
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
> libavfilter/Makefile | 1 +
> libavfilter/allfilters.c | 1 +
> libavfilter/vf_settb.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 45 insertions(+), 1 deletion(-)
>
>
> Afterwards, vf_settb.c should be renamed f_settb.c.
>
> Another solution would be to implement some kind of ".type = ANY" for filter
> pads, which would allow to use the same filter, and the same name, for audio
> and video. In the long run, it is probably better.
I agree, but I'm fine with the lazy solution in the short run.
>
>
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 088ab8f..42acdd7 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -54,6 +54,7 @@ OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o
> OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
> OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o
> OBJS-$(CONFIG_ASETNSAMPLES_FILTER) += af_asetnsamples.o
> +OBJS-$(CONFIG_ASETTB_FILTER) += vf_settb.o
> OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o
> OBJS-$(CONFIG_ASPLIT_FILTER) += split.o
> OBJS-$(CONFIG_ASTREAMSYNC_FILTER) += af_astreamsync.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 3590b81..5e15413 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -42,6 +42,7 @@ void avfilter_register_all(void)
> REGISTER_FILTER (ANULL, anull, af);
> REGISTER_FILTER (ARESAMPLE, aresample, af);
> REGISTER_FILTER (ASETNSAMPLES, asetnsamples, af);
> + REGISTER_FILTER (ASETTB, asettb, af);
> REGISTER_FILTER (ASHOWINFO, ashowinfo, af);
> REGISTER_FILTER (ASPLIT, asplit, af);
> REGISTER_FILTER (ASTREAMSYNC, astreamsync, af);
> diff --git a/libavfilter/vf_settb.c b/libavfilter/vf_settb.c
> index 9f4c1b2..9284142 100644
> --- a/libavfilter/vf_settb.c
> +++ b/libavfilter/vf_settb.c
> @@ -29,6 +29,7 @@
> #include "libavutil/rational.h"
> #include "avfilter.h"
> #include "internal.h"
> +#include "audio.h"
> #include "video.h"
>
> static const char *const var_names[] = {
> @@ -113,9 +114,28 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
> ff_start_frame(outlink, picref2);
> }
>
> +static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
> +{
> + AVFilterContext *ctx = inlink->dst;
> + AVFilterLink *outlink = ctx->outputs[0];
> + AVFilterBufferRef *outsamples = insamples;
> +
> + if (av_cmp_q(inlink->time_base, outlink->time_base)) {
> + outsamples = avfilter_ref_buffer(insamples, ~0);
> + outsamples->pts = av_rescale_q(insamples->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, insamples ->pts,
> + outlink->time_base.num, outlink->time_base.den, outsamples->pts);
Possibly unrelated: av_ts2str?
> + avfilter_unref_buffer(insamples);
> + }
> +
> + ff_filter_samples(outlink, outsamples);
> +}
> +
> +#if CONFIG_SETTB_FILTER
> AVFilter avfilter_vf_settb = {
> .name = "settb",
> - .description = NULL_IF_CONFIG_SMALL("Set timebase for the output link."),
> + .description = NULL_IF_CONFIG_SMALL("Set timebase for the video output link."),
> .init = init,
>
> .priv_size = sizeof(SetTBContext),
> @@ -132,3 +152,25 @@ AVFilter avfilter_vf_settb = {
> .config_props = config_output_props, },
> { .name = NULL}},
> };
> +#endif
> +
> +#if CONFIG_ASETTB_FILTER
> +AVFilter avfilter_af_asettb = {
> + .name = "asettb",
> + .description = NULL_IF_CONFIG_SMALL("Set timebase for the audio output link."),
> + .init = init,
> +
> + .priv_size = sizeof(SetTBContext),
> +
> + .inputs = (const AVFilterPad[]) {{ .name = "default",
> + .type = AVMEDIA_TYPE_AUDIO,
> + .get_video_buffer = ff_null_get_video_buffer,
uh?
> + .filter_samples = filter_samples, },
> + { .name = NULL }},
> +
> + .outputs = (const AVFilterPad[]) {{ .name = "default",
> + .type = AVMEDIA_TYPE_AUDIO,
> + .config_props = config_output_props, },
> + { .name = NULL}},
> +};
Also weird reindent, and please update filters.texi accordingly.
--
FFmpeg = Forgiving and Fascinating Mastodontic Portable Elitarian Goblin
More information about the ffmpeg-devel
mailing list