af_ashowinfo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @file
  22. * filter for showing textual audio frame information
  23. */
  24. #include "libavutil/adler32.h"
  25. #include "libavutil/audioconvert.h"
  26. #include "libavutil/timestamp.h"
  27. #include "audio.h"
  28. #include "avfilter.h"
  29. typedef struct {
  30. unsigned int frame;
  31. } ShowInfoContext;
  32. static av_cold int init(AVFilterContext *ctx, const char *args)
  33. {
  34. ShowInfoContext *showinfo = ctx->priv;
  35. showinfo->frame = 0;
  36. return 0;
  37. }
  38. static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
  39. {
  40. AVFilterContext *ctx = inlink->dst;
  41. ShowInfoContext *showinfo = ctx->priv;
  42. uint32_t plane_checksum[8] = {0}, checksum = 0;
  43. char chlayout_str[128];
  44. int plane;
  45. int linesize =
  46. samplesref->audio->nb_samples *
  47. av_get_bytes_per_sample(samplesref->format);
  48. if (!av_sample_fmt_is_planar(samplesref->format))
  49. linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
  50. for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
  51. uint8_t *data = samplesref->data[plane];
  52. plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
  53. data, linesize);
  54. checksum = av_adler32_update(checksum, data, linesize);
  55. }
  56. av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
  57. samplesref->audio->channel_layout);
  58. av_log(ctx, AV_LOG_INFO,
  59. "n:%d pts:%s pts_time:%s pos:%"PRId64" "
  60. "fmt:%s chlayout:%s nb_samples:%d rate:%d "
  61. "checksum:%08X plane_checksum[%08X",
  62. showinfo->frame,
  63. av_ts2str(samplesref->pts), av_ts2timestr(samplesref->pts, &inlink->time_base),
  64. samplesref->pos,
  65. av_get_sample_fmt_name(samplesref->format),
  66. chlayout_str,
  67. samplesref->audio->nb_samples,
  68. samplesref->audio->sample_rate,
  69. checksum,
  70. plane_checksum[0]);
  71. for (plane = 1; samplesref->data[plane] && plane < 8; plane++)
  72. av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
  73. av_log(ctx, AV_LOG_INFO, "]\n");
  74. showinfo->frame++;
  75. return ff_filter_samples(inlink->dst->outputs[0], samplesref);
  76. }
  77. AVFilter avfilter_af_ashowinfo = {
  78. .name = "ashowinfo",
  79. .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
  80. .priv_size = sizeof(ShowInfoContext),
  81. .init = init,
  82. .inputs = (const AVFilterPad[]) {{ .name = "default",
  83. .type = AVMEDIA_TYPE_AUDIO,
  84. .get_audio_buffer = ff_null_get_audio_buffer,
  85. .filter_samples = filter_samples,
  86. .min_perms = AV_PERM_READ, },
  87. { .name = NULL}},
  88. .outputs = (const AVFilterPad[]) {{ .name = "default",
  89. .type = AVMEDIA_TYPE_AUDIO },
  90. { .name = NULL}},
  91. };