fourcc2pixfmt.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2012 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 "config.h"
  21. #if HAVE_UNISTD_H
  22. #include <unistd.h> /* getopt */
  23. #endif
  24. #include "libavutil/pixdesc.h"
  25. #include "libavcodec/avcodec.h"
  26. #include "libavutil/common.h"
  27. #include "libavcodec/raw.h"
  28. #undef printf
  29. #undef fprintf
  30. #if !HAVE_GETOPT
  31. #include "compat/getopt.c"
  32. #endif
  33. static void usage(void)
  34. {
  35. printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
  36. printf("usage: fourcc2pixfmt [OPTIONS]\n");
  37. printf("\n"
  38. "Options:\n"
  39. "-l list the pixel format for each fourcc\n"
  40. "-L list the fourccs for each pixel format\n"
  41. "-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
  42. "-h print this help\n");
  43. }
  44. static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
  45. {
  46. int i;
  47. for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++)
  48. if (pix_fmt_tags[i].pix_fmt == pix_fmt)
  49. printf("%s%c", av_fourcc2str(pix_fmt_tags[i].fourcc), sep);
  50. }
  51. int main(int argc, char **argv)
  52. {
  53. int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
  54. const PixelFormatTag *pix_fmt_tags = avpriv_get_raw_pix_fmt_tags();
  55. const char *pix_fmt_name = NULL;
  56. char c;
  57. if (argc == 1) {
  58. usage();
  59. return 0;
  60. }
  61. while ((c = getopt(argc, argv, "hp:lL")) != -1) {
  62. switch (c) {
  63. case 'h':
  64. usage();
  65. return 0;
  66. case 'l':
  67. list_fourcc_pix_fmt = 1;
  68. break;
  69. case 'L':
  70. list_pix_fmt_fourccs = 1;
  71. break;
  72. case 'p':
  73. pix_fmt_name = optarg;
  74. break;
  75. case '?':
  76. usage();
  77. return 1;
  78. }
  79. }
  80. if (list_fourcc_pix_fmt)
  81. for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++)
  82. printf("%s: %s\n", av_fourcc2str(pix_fmt_tags[i].fourcc),
  83. av_get_pix_fmt_name(pix_fmt_tags[i].pix_fmt));
  84. if (list_pix_fmt_fourccs) {
  85. for (i = 0; av_pix_fmt_desc_get(i); i++) {
  86. const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
  87. if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
  88. continue;
  89. printf("%s: ", pix_desc->name);
  90. print_pix_fmt_fourccs(i, pix_fmt_tags, ' ');
  91. printf("\n");
  92. }
  93. }
  94. if (pix_fmt_name) {
  95. enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
  96. if (pix_fmt == AV_PIX_FMT_NONE) {
  97. fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
  98. return 1;
  99. }
  100. print_pix_fmt_fourccs(pix_fmt, pix_fmt_tags, '\n');
  101. }
  102. return 0;
  103. }