You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.7KB

  1. /*
  2. * ISO Media common code
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. * Copyright (c) 2002 Francois Revol <revol@free.fr>
  5. * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "avformat.h"
  24. #include "riff.h"
  25. #include "isom.h"
  26. /* http://gpac.sourceforge.net/tutorial/mediatypes.htm */
  27. const AVCodecTag ff_mov_obj_type[] = {
  28. { CODEC_ID_MPEG4 , 32 },
  29. { CODEC_ID_H264 , 33 },
  30. { CODEC_ID_AAC , 64 },
  31. { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */
  32. { CODEC_ID_MPEG2VIDEO, 97 }, /* MPEG2 Main */
  33. { CODEC_ID_MPEG2VIDEO, 98 }, /* MPEG2 SNR */
  34. { CODEC_ID_MPEG2VIDEO, 99 }, /* MPEG2 Spatial */
  35. { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */
  36. { CODEC_ID_MPEG2VIDEO, 101 }, /* MPEG2 422 */
  37. { CODEC_ID_AAC , 102 }, /* MPEG2 AAC Main */
  38. { CODEC_ID_AAC , 103 }, /* MPEG2 AAC Low */
  39. { CODEC_ID_AAC , 104 }, /* MPEG2 AAC SSR */
  40. { CODEC_ID_MP3 , 105 },
  41. { CODEC_ID_MPEG1VIDEO, 106 },
  42. { CODEC_ID_MP2 , 107 },
  43. { CODEC_ID_MJPEG , 108 },
  44. { CODEC_ID_PCM_S16LE , 224 },
  45. { CODEC_ID_VORBIS , 221 },
  46. { CODEC_ID_QCELP , 225 },
  47. { CODEC_ID_AC3 , 226 },
  48. { CODEC_ID_PCM_ALAW , 227 },
  49. { CODEC_ID_PCM_MULAW , 228 },
  50. { CODEC_ID_PCM_S16BE , 230 },
  51. { CODEC_ID_H263 , 242 },
  52. { CODEC_ID_H261 , 243 },
  53. { 0, 0 },
  54. };
  55. /* map numeric codes from mdhd atom to ISO 639 */
  56. /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
  57. /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
  58. /* deprecated by putting the code as 3*5bit ascii */
  59. static const char *mov_mdhd_language_map[] = {
  60. /* 0-9 */
  61. "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
  62. "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/,
  63. "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", NULL,
  64. "fo ", NULL, "rus", "chi", NULL, "iri", "alb", "ron", "ces", "slk",
  65. "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
  66. /*?*/
  67. "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", NULL, "pus",
  68. "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
  69. "pa ", "ori", "mal", "kan", "tam", "tel", NULL, "bur", "khm", "lao",
  70. /* roman? arabic? */
  71. "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
  72. /*==rundi?*/
  73. NULL, "run", NULL, "mlg", "epo", NULL, NULL, NULL, NULL, NULL,
  74. /* 100 */
  75. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  76. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  77. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "wel", "baq",
  78. "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
  79. };
  80. int ff_mov_iso639_to_lang(const char *lang, int mp4)
  81. {
  82. int i, code = 0;
  83. /* old way, only for QT? */
  84. for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
  85. if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
  86. return i;
  87. }
  88. /* XXX:can we do that in mov too? */
  89. if (!mp4)
  90. return 0;
  91. /* handle undefined as such */
  92. if (lang[0] == '\0')
  93. lang = "und";
  94. /* 5bit ascii */
  95. for (i = 0; i < 3; i++) {
  96. unsigned char c = (unsigned char)lang[i];
  97. if (c < 0x60)
  98. return 0;
  99. if (c > 0x60 + 0x1f)
  100. return 0;
  101. code <<= 5;
  102. code |= (c - 0x60);
  103. }
  104. return code;
  105. }
  106. int ff_mov_lang_to_iso639(int code, char *to)
  107. {
  108. int i;
  109. /* is it the mangled iso code? */
  110. /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
  111. if (code > 138) {
  112. for (i = 2; i >= 0; i--) {
  113. to[i] = 0x60 + (code & 0x1f);
  114. code >>= 5;
  115. }
  116. return 1;
  117. }
  118. /* old fashion apple lang code */
  119. if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
  120. return 0;
  121. if (!mov_mdhd_language_map[code])
  122. return 0;
  123. strncpy(to, mov_mdhd_language_map[code], 4);
  124. return 1;
  125. }