]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_ashowinfo.c
lavfi: add audio silencedetect filter.
[ffmpeg] / libavfilter / af_ashowinfo.c
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * filter for showing textual audio frame information
24  */
25
26 #include "libavutil/adler32.h"
27 #include "libavutil/audioconvert.h"
28 #include "avfilter.h"
29
30 typedef struct {
31     unsigned int frame;
32 } ShowInfoContext;
33
34 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
35 {
36     ShowInfoContext *showinfo = ctx->priv;
37     showinfo->frame = 0;
38     return 0;
39 }
40
41 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
42 {
43     AVFilterContext *ctx = inlink->dst;
44     ShowInfoContext *showinfo = ctx->priv;
45     uint32_t plane_checksum[8] = {0}, checksum = 0;
46     char chlayout_str[128];
47     int plane;
48     int linesize =
49         samplesref->audio->nb_samples *
50         av_get_bytes_per_sample(samplesref->format);
51     if (!samplesref->audio->planar) /* packed layout */
52         linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
53
54     for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
55         uint8_t *data = samplesref->data[plane];
56
57         plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
58                                                   data, linesize);
59         checksum = av_adler32_update(checksum, data, linesize);
60     }
61
62     av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
63                                  samplesref->audio->channel_layout);
64
65     av_log(ctx, AV_LOG_INFO,
66            "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
67            "fmt:%s chlayout:%s nb_samples:%d rate:%d planar:%d "
68            "checksum:%08X plane_checksum[%08X %08X %08X %08X %08X %08X %08X %08X]\n",
69            showinfo->frame,
70            samplesref->pts, samplesref->pts * av_q2d(inlink->time_base),
71            samplesref->pos,
72            av_get_sample_fmt_name(samplesref->format),
73            chlayout_str,
74            samplesref->audio->nb_samples,
75            samplesref->audio->sample_rate,
76            samplesref->audio->planar,
77            checksum,
78            plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3],
79            plane_checksum[4], plane_checksum[5], plane_checksum[6], plane_checksum[7]);
80
81     showinfo->frame++;
82
83     avfilter_filter_samples(inlink->dst->outputs[0], samplesref);
84 }
85
86 AVFilter avfilter_af_ashowinfo = {
87     .name        = "ashowinfo",
88     .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
89
90     .priv_size = sizeof(ShowInfoContext),
91     .init      = init,
92
93     .inputs    = (const AVFilterPad[]) {{ .name       = "default",
94                                     .type             = AVMEDIA_TYPE_AUDIO,
95                                     .get_audio_buffer = avfilter_null_get_audio_buffer,
96                                     .filter_samples   = filter_samples,
97                                     .min_perms        = AV_PERM_READ, },
98                                   { .name = NULL}},
99
100     .outputs   = (const AVFilterPad[]) {{ .name       = "default",
101                                     .type             = AVMEDIA_TYPE_AUDIO },
102                                   { .name = NULL}},
103 };