filtfmts.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2009 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. #include <stdio.h>
  21. #include "libavutil/channel_layout.h"
  22. #include "libavutil/mem.h"
  23. #include "libavutil/pixdesc.h"
  24. #include "libavutil/samplefmt.h"
  25. #include "libavfilter/avfilter.h"
  26. #include "libavfilter/formats.h"
  27. static void print_formats(AVFilterContext *filter_ctx)
  28. {
  29. int i, j;
  30. #define PRINT_FMTS(inout, outin, INOUT) \
  31. for (i = 0; i < filter_ctx->nb_##inout##puts; i++) { \
  32. if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
  33. AVFilterFormats *fmts = \
  34. filter_ctx->inout##puts[i]->outin##_formats; \
  35. for (j = 0; j < fmts->nb_formats; j++) \
  36. if(av_get_pix_fmt_name(fmts->formats[j])) \
  37. printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
  38. i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), \
  39. av_get_pix_fmt_name(fmts->formats[j])); \
  40. } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
  41. AVFilterFormats *fmts; \
  42. AVFilterChannelLayouts *layouts; \
  43. \
  44. fmts = filter_ctx->inout##puts[i]->outin##_formats; \
  45. for (j = 0; j < fmts->nb_formats; j++) \
  46. printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
  47. i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), \
  48. av_get_sample_fmt_name(fmts->formats[j])); \
  49. \
  50. layouts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
  51. for (j = 0; j < layouts->nb_channel_layouts; j++) { \
  52. char buf[256]; \
  53. av_get_channel_layout_string(buf, sizeof(buf), -1, \
  54. layouts->channel_layouts[j]); \
  55. printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
  56. i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), buf); \
  57. } \
  58. } \
  59. } \
  60. PRINT_FMTS(in, out, IN);
  61. PRINT_FMTS(out, in, OUT);
  62. }
  63. int main(int argc, char **argv)
  64. {
  65. AVFilter *filter;
  66. AVFilterContext *filter_ctx;
  67. AVFilterGraph *graph_ctx;
  68. const char *filter_name;
  69. const char *filter_args = NULL;
  70. int i;
  71. av_log_set_level(AV_LOG_DEBUG);
  72. if (argc < 2) {
  73. fprintf(stderr, "Missing filter name as argument\n");
  74. return 1;
  75. }
  76. filter_name = argv[1];
  77. if (argc > 2)
  78. filter_args = argv[2];
  79. /* allocate graph */
  80. graph_ctx = avfilter_graph_alloc();
  81. if (!graph_ctx)
  82. return 1;
  83. avfilter_register_all();
  84. /* get a corresponding filter and open it */
  85. if (!(filter = avfilter_get_by_name(filter_name))) {
  86. fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
  87. return 1;
  88. }
  89. /* open filter and add it to the graph */
  90. if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
  91. fprintf(stderr, "Impossible to open filter with name '%s'\n",
  92. filter_name);
  93. return 1;
  94. }
  95. if (avfilter_init_str(filter_ctx, filter_args) < 0) {
  96. fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
  97. filter_name, filter_args);
  98. return 1;
  99. }
  100. /* create a link for each of the input pads */
  101. for (i = 0; i < filter_ctx->nb_inputs; i++) {
  102. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  103. link->type = avfilter_pad_get_type(filter_ctx->input_pads, i);
  104. filter_ctx->inputs[i] = link;
  105. }
  106. for (i = 0; i < filter_ctx->nb_outputs; i++) {
  107. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  108. link->type = avfilter_pad_get_type(filter_ctx->output_pads, i);
  109. filter_ctx->outputs[i] = link;
  110. }
  111. if (filter->query_formats)
  112. filter->query_formats(filter_ctx);
  113. else
  114. ff_default_query_formats(filter_ctx);
  115. print_formats(filter_ctx);
  116. avfilter_free(filter_ctx);
  117. avfilter_graph_free(&graph_ctx);
  118. fflush(stdout);
  119. return 0;
  120. }