fourcc2pixfmt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, char sep)
  45. {
  46. int i;
  47. for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
  48. if (ff_raw_pix_fmt_tags[i].pix_fmt == pix_fmt) {
  49. char buf[32];
  50. av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
  51. printf("%s%c", buf, sep);
  52. }
  53. }
  54. }
  55. int main(int argc, char **argv)
  56. {
  57. int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
  58. const char *pix_fmt_name = NULL;
  59. char c;
  60. if (argc == 1) {
  61. usage();
  62. return 0;
  63. }
  64. while ((c = getopt(argc, argv, "hp:lL")) != -1) {
  65. switch (c) {
  66. case 'h':
  67. usage();
  68. return 0;
  69. case 'l':
  70. list_fourcc_pix_fmt = 1;
  71. break;
  72. case 'L':
  73. list_pix_fmt_fourccs = 1;
  74. break;
  75. case 'p':
  76. pix_fmt_name = optarg;
  77. break;
  78. case '?':
  79. usage();
  80. return 1;
  81. }
  82. }
  83. if (list_fourcc_pix_fmt) {
  84. for (i = 0; ff_raw_pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
  85. char buf[32];
  86. av_get_codec_tag_string(buf, sizeof(buf), ff_raw_pix_fmt_tags[i].fourcc);
  87. printf("%s: %s\n", buf, av_get_pix_fmt_name(ff_raw_pix_fmt_tags[i].pix_fmt));
  88. }
  89. }
  90. if (list_pix_fmt_fourccs) {
  91. for (i = 0; i < AV_PIX_FMT_NB; i++) {
  92. const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
  93. if (!pix_desc->name || pix_desc->flags & PIX_FMT_HWACCEL)
  94. continue;
  95. printf("%s: ", pix_desc->name);
  96. print_pix_fmt_fourccs(i, ' ');
  97. printf("\n");
  98. }
  99. }
  100. if (pix_fmt_name) {
  101. enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
  102. if (pix_fmt == AV_PIX_FMT_NONE) {
  103. fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
  104. return 1;
  105. }
  106. print_pix_fmt_fourccs(pix_fmt, '\n');
  107. }
  108. return 0;
  109. }