You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
5.7KB

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