Browse code

lavfi: add ashowinfo filter

Useful for debugging.

Stefano Sabatini authored on 2011/08/19 01:19:55
Showing 6 changed files
... ...
@@ -44,6 +44,7 @@ easier to use. The changes are:
44 44
     * -intra option was removed, it's equivalent to -g 0.
45 45
 - XMV demuxer
46 46
 - LOAS demuxer
47
+- ashowinfo filter added
47 48
 
48 49
 
49 50
 version 0.8:
... ...
@@ -137,6 +137,56 @@ For example, to resample the input audio to 44100Hz:
137 137
 aresample=44100
138 138
 @end example
139 139
 
140
+@section ashowinfo
141
+
142
+Show a line containing various information for each input audio frame.
143
+The input audio is not modified.
144
+
145
+The shown line contains a sequence of key/value pairs of the form
146
+@var{key}:@var{value}.
147
+
148
+A description of each shown parameter follows:
149
+
150
+@table @option
151
+@item n
152
+sequential number of the input frame, starting from 0
153
+
154
+@item pts
155
+presentation TimeStamp of the input frame, expressed as a number of
156
+time base units. The time base unit depends on the filter input pad, and
157
+is usually 1/@var{sample_rate}.
158
+
159
+@item pts_time
160
+presentation TimeStamp of the input frame, expressed as a number of
161
+seconds
162
+
163
+@item pos
164
+position of the frame in the input stream, -1 if this information in
165
+unavailable and/or meanigless (for example in case of synthetic audio)
166
+
167
+@item fmt
168
+sample format name
169
+
170
+@item chlayout
171
+channel layout description
172
+
173
+@item nb_samples
174
+number of samples (per each channel) contained in the filtered frame
175
+
176
+@item rate
177
+sample rate for the audio frame
178
+
179
+@item planar
180
+if the packing format is planar, 0 if packed
181
+
182
+@item checksum
183
+Adler-32 checksum of all the planes of the input frame
184
+
185
+@item plane_checksum
186
+Adler-32 checksum for each input frame plane, expressed in the form
187
+"[@var{c0} @var{c1} @var{c2} @var{c3} @var{c4} @var{c5} @var{c6} @var{c7}]"
188
+@end table
189
+
140 190
 @c man end AUDIO FILTERS
141 191
 
142 192
 @chapter Audio Sources
... ...
@@ -22,6 +22,7 @@ OBJS-$(CONFIG_AVCODEC)                       += avcodec.o
22 22
 OBJS-$(CONFIG_AFORMAT_FILTER)                += af_aformat.o
23 23
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
24 24
 OBJS-$(CONFIG_ARESAMPLE_FILTER)              += af_aresample.o
25
+OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
25 26
 
26 27
 OBJS-$(CONFIG_ANULLSRC_FILTER)               += asrc_anullsrc.o
27 28
 
28 29
new file mode 100644
... ...
@@ -0,0 +1,99 @@
0
+/*
1
+ * Copyright (c) 2011 Stefano Sabatini
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+/**
21
+ * @file
22
+ * filter fow showing textual audio frame information
23
+ */
24
+
25
+#include "libavutil/adler32.h"
26
+#include "libavutil/audioconvert.h"
27
+#include "avfilter.h"
28
+
29
+typedef struct {
30
+    unsigned int frame;
31
+} ShowInfoContext;
32
+
33
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
34
+{
35
+    ShowInfoContext *showinfo = ctx->priv;
36
+    showinfo->frame = 0;
37
+    return 0;
38
+}
39
+
40
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
41
+{
42
+    AVFilterContext *ctx = inlink->dst;
43
+    ShowInfoContext *showinfo = ctx->priv;
44
+    uint32_t plane_checksum[8] = {0}, checksum = 0;
45
+    char chlayout_str[128];
46
+    int plane;
47
+
48
+    for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
49
+        uint8_t *data = samplesref->data[plane];
50
+        int linesize = samplesref->linesize[plane];
51
+
52
+        plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
53
+                                                  data, linesize);
54
+        checksum = av_adler32_update(checksum, data, linesize);
55
+    }
56
+
57
+    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
58
+                                 samplesref->audio->channel_layout);
59
+
60
+    av_log(ctx, AV_LOG_INFO,
61
+           "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
62
+           "fmt:%s chlayout:%s nb_samples:%d rate:%d planar:%d "
63
+           "checksum:%u plane_checksum[%u %u %u %u %u %u %u %u]\n",
64
+           showinfo->frame,
65
+           samplesref->pts, samplesref->pts * av_q2d(inlink->time_base),
66
+           samplesref->pos,
67
+           av_get_sample_fmt_name(samplesref->format),
68
+           chlayout_str,
69
+           samplesref->audio->nb_samples,
70
+           samplesref->audio->sample_rate,
71
+           samplesref->audio->planar,
72
+           checksum,
73
+           plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3],
74
+           plane_checksum[4], plane_checksum[5], plane_checksum[6], plane_checksum[7]);
75
+
76
+    showinfo->frame++;
77
+
78
+    avfilter_filter_samples(inlink->dst->outputs[0], samplesref);
79
+}
80
+
81
+AVFilter avfilter_af_ashowinfo = {
82
+    .name        = "ashowinfo",
83
+    .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
84
+
85
+    .priv_size = sizeof(ShowInfoContext),
86
+    .init      = init,
87
+
88
+    .inputs    = (AVFilterPad[]) {{ .name = "default",
89
+                                    .type             = AVMEDIA_TYPE_AUDIO,
90
+                                    .get_audio_buffer = avfilter_null_get_audio_buffer,
91
+                                    .filter_samples   = filter_samples,
92
+                                    .min_perms        = AV_PERM_READ, },
93
+                                  { .name = NULL}},
94
+
95
+    .outputs   = (AVFilterPad[]) {{ .name             = "default",
96
+                                    .type             = AVMEDIA_TYPE_AUDIO },
97
+                                  { .name = NULL}},
98
+};
... ...
@@ -37,6 +37,7 @@ void avfilter_register_all(void)
37 37
     REGISTER_FILTER (AFORMAT,     aformat,     af);
38 38
     REGISTER_FILTER (ANULL,       anull,       af);
39 39
     REGISTER_FILTER (ARESAMPLE,   aresample,   af);
40
+    REGISTER_FILTER (ASHOWINFO,   ashowinfo,   af);
40 41
 
41 42
     REGISTER_FILTER (ANULLSRC,    anullsrc,    asrc);
42 43
 
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/rational.h"
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  2
32
-#define LIBAVFILTER_VERSION_MINOR 32
32
+#define LIBAVFILTER_VERSION_MINOR 33
33 33
 #define LIBAVFILTER_VERSION_MICRO  0
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \