fourcc2pixfmt.c 3.5 KB

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