[FFmpeg-devel] [PATCH] lavfi: add ashowinfo filter
Stefano Sabatini
stefano.sabatini-lala at poste.it
Fri Aug 19 00:51:00 CEST 2011
---
libavfilter/Makefile | 1 +
libavfilter/af_ashowinfo.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
libavfilter/allfilters.c | 1 +
3 files changed, 95 insertions(+), 0 deletions(-)
create mode 100644 libavfilter/af_ashowinfo.c
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index db84d50..c7782b7 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -23,6 +23,7 @@ OBJS-$(CONFIG_AVCODEC) += avcodec.o
OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o
OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o
+OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o
OBJS-$(CONFIG_AMOVIE_FILTER) += movie.o
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
new file mode 100644
index 0000000..a17207a
--- /dev/null
+++ b/libavfilter/af_ashowinfo.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * filter fow showing textual audio frame information
+ */
+
+#include "libavutil/adler32.h"
+#include "libavutil/audioconvert.h"
+#include "avfilter.h"
+
+typedef struct {
+ unsigned int frame;
+} ShowInfoContext;
+
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ ShowInfoContext *showinfo = ctx->priv;
+ showinfo->frame = 0;
+ return 0;
+}
+
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
+{
+ AVFilterContext *ctx = inlink->dst;
+ ShowInfoContext *showinfo = ctx->priv;
+ uint32_t plane_checksum[8] = {0}, checksum = 0;
+ int plane;
+
+ for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
+ uint8_t *data = samplesref->data[plane];
+ int linesize = samplesref->linesize[plane];
+
+ plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
+ data, linesize);
+ checksum = av_adler32_update(checksum, data, linesize);
+ }
+
+ av_log(ctx, AV_LOG_INFO,
+ "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
+ "fmt:%s rate:%d nb_samples:%d checksum:%u "
+ "plane_checksum[%u %u %u %u %u %u %u %u]\n",
+ showinfo->frame,
+ samplesref->pts, samplesref->pts * av_q2d(inlink->time_base),
+ samplesref->pos,
+ av_get_sample_fmt_name(samplesref->format),
+ samplesref->audio->sample_rate,
+ samplesref->audio->nb_samples,
+ checksum,
+ plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3],
+ plane_checksum[4], plane_checksum[5], plane_checksum[6], plane_checksum[7]);
+
+ showinfo->frame++;
+
+ avfilter_filter_samples(inlink->dst->outputs[0], samplesref);
+}
+
+AVFilter avfilter_af_ashowinfo = {
+ .name = "ashowinfo",
+ .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
+
+ .priv_size = sizeof(ShowInfoContext),
+ .init = init,
+
+ .inputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .get_audio_buffer = avfilter_null_get_audio_buffer,
+ .filter_samples = filter_samples,
+ .min_perms = AV_PERM_READ, },
+ { .name = NULL}},
+
+ .outputs = (AVFilterPad[]) {{ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO },
+ { .name = NULL}},
+};
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 85985dd..57a856b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -37,6 +37,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (AFORMAT, aformat, af);
REGISTER_FILTER (ANULL, anull, af);
REGISTER_FILTER (ARESAMPLE, aresample, af);
+ REGISTER_FILTER (ASHOWINFO, ashowinfo, af);
REGISTER_FILTER (AMOVIE, amovie, asrc);
REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
--
1.7.2.5
More information about the ffmpeg-devel
mailing list