lavfi-showfiltfmts.c 5.3 KB

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