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.

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