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.

131 lines
4.9KB

  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 "libavformat/avformat.h"
  22. #include "libavutil/pixdesc.h"
  23. #include "libavutil/samplefmt.h"
  24. #include "libavfilter/avfilter.h"
  25. #include "libavfilter/formats.h"
  26. #undef fprintf
  27. #undef printf
  28. static void print_formats(AVFilterContext *filter_ctx)
  29. {
  30. int i, j;
  31. #define PRINT_FMTS(inout, outin, INOUT) \
  32. for (i = 0; i < filter_ctx->inout##put_count; i++) { \
  33. if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
  34. AVFilterFormats *fmts = \
  35. filter_ctx->inout##puts[i]->outin##_formats; \
  36. for (j = 0; j < fmts->format_count; j++) \
  37. if(av_get_pix_fmt_name(fmts->formats[j])) \
  38. printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
  39. i, filter_ctx->filter->inout##puts[i].name, \
  40. av_get_pix_fmt_name(fmts->formats[j])); \
  41. } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
  42. AVFilterFormats *fmts; \
  43. \
  44. fmts = filter_ctx->inout##puts[i]->outin##_formats; \
  45. for (j = 0; j < fmts->format_count; j++) \
  46. printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
  47. i, filter_ctx->filter->inout##puts[i].name, \
  48. av_get_sample_fmt_name(fmts->formats[j])); \
  49. \
  50. fmts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
  51. for (j = 0; j < fmts->format_count; j++) { \
  52. char buf[256]; \
  53. av_get_channel_layout_string(buf, sizeof(buf), -1, \
  54. fmts->formats[j]); \
  55. printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
  56. i, filter_ctx->filter->inout##puts[i].name, 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. const char *filter_name;
  68. const char *filter_args = NULL;
  69. int i;
  70. av_log_set_level(AV_LOG_DEBUG);
  71. if (!argv[1]) {
  72. fprintf(stderr, "Missing filter name as argument\n");
  73. return 1;
  74. }
  75. filter_name = argv[1];
  76. if (argv[2])
  77. filter_args = argv[2];
  78. avfilter_register_all();
  79. /* get a corresponding filter and open it */
  80. if (!(filter = avfilter_get_by_name(filter_name))) {
  81. fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
  82. return 1;
  83. }
  84. if (avfilter_open(&filter_ctx, filter, NULL) < 0) {
  85. fprintf(stderr, "Impossible to open filter with name '%s'\n",
  86. filter_name);
  87. return 1;
  88. }
  89. if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) {
  90. fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
  91. filter_name, filter_args);
  92. return 1;
  93. }
  94. /* create a link for each of the input pads */
  95. for (i = 0; i < filter_ctx->input_count; i++) {
  96. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  97. link->type = filter_ctx->filter->inputs[i].type;
  98. filter_ctx->inputs[i] = link;
  99. }
  100. for (i = 0; i < filter_ctx->output_count; i++) {
  101. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  102. link->type = filter_ctx->filter->outputs[i].type;
  103. filter_ctx->outputs[i] = link;
  104. }
  105. if (filter->query_formats)
  106. filter->query_formats(filter_ctx);
  107. else
  108. ff_default_query_formats(filter_ctx);
  109. print_formats(filter_ctx);
  110. avfilter_free(filter_ctx);
  111. fflush(stdout);
  112. return 0;
  113. }