filtfmts.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2009 Stefano Sabatini
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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/mem.h"
  22. #include "libavutil/pixdesc.h"
  23. #include "libavfilter/avfilter.h"
  24. #include "libavfilter/formats.h"
  25. int main(int argc, char **argv)
  26. {
  27. AVFilter *filter;
  28. AVFilterContext *filter_ctx;
  29. AVFilterGraph *graph_ctx;
  30. const char *filter_name;
  31. const char *filter_args = NULL;
  32. int i, j, ret = 0;
  33. av_log_set_level(AV_LOG_DEBUG);
  34. if (!argv[1]) {
  35. fprintf(stderr, "Missing filter name as argument\n");
  36. return 1;
  37. }
  38. filter_name = argv[1];
  39. if (argv[2])
  40. filter_args = argv[2];
  41. /* allocate graph */
  42. graph_ctx = avfilter_graph_alloc();
  43. if (!graph_ctx)
  44. return 1;
  45. avfilter_register_all();
  46. /* get a corresponding filter and open it */
  47. if (!(filter = avfilter_get_by_name(filter_name))) {
  48. fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
  49. return 1;
  50. }
  51. /* open filter and add it to the graph */
  52. if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
  53. fprintf(stderr, "Impossible to open filter with name '%s'\n",
  54. filter_name);
  55. return 1;
  56. }
  57. if (avfilter_init_str(filter_ctx, filter_args) < 0) {
  58. fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
  59. filter_name, filter_args);
  60. return 1;
  61. }
  62. /* create a link for each of the input pads */
  63. for (i = 0; i < filter_ctx->nb_inputs; i++) {
  64. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  65. if (!link) {
  66. fprintf(stderr, "Unable to allocate memory for filter input link\n");
  67. ret = 1;
  68. goto fail;
  69. }
  70. link->type = avfilter_pad_get_type(filter_ctx->filter->inputs, i);
  71. filter_ctx->inputs[i] = link;
  72. }
  73. for (i = 0; i < filter_ctx->nb_outputs; i++) {
  74. AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
  75. if (!link) {
  76. fprintf(stderr, "Unable to allocate memory for filter output link\n");
  77. ret = 1;
  78. goto fail;
  79. }
  80. link->type = avfilter_pad_get_type(filter_ctx->filter->outputs, i);
  81. filter_ctx->outputs[i] = link;
  82. }
  83. if (filter->query_formats)
  84. filter->query_formats(filter_ctx);
  85. else
  86. ff_default_query_formats(filter_ctx);
  87. /* print the supported formats in input */
  88. for (i = 0; i < filter_ctx->nb_inputs; i++) {
  89. AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
  90. for (j = 0; j < fmts->nb_formats; j++)
  91. printf("INPUT[%d] %s: %s\n",
  92. i, avfilter_pad_get_name(filter_ctx->filter->inputs, i),
  93. av_get_pix_fmt_name(fmts->formats[j]));
  94. }
  95. /* print the supported formats in output */
  96. for (i = 0; i < filter_ctx->nb_outputs; i++) {
  97. AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
  98. for (j = 0; j < fmts->nb_formats; j++)
  99. printf("OUTPUT[%d] %s: %s\n",
  100. i, avfilter_pad_get_name(filter_ctx->filter->outputs, i),
  101. av_get_pix_fmt_name(fmts->formats[j]));
  102. }
  103. fail:
  104. avfilter_free(filter_ctx);
  105. avfilter_graph_free(&graph_ctx);
  106. fflush(stdout);
  107. return ret;
  108. }