Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 8 Monaten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "mov-internal.h"
  2. #include <assert.h>
  3. // ISO/IEC 14496-12:2012(E)
  4. // 8.3.2 Track Header Box (p31)
  5. // Box Type : 'tkhd'
  6. // Container : Movie Box('trak')
  7. // Mandatory : Yes
  8. // Quantity : Exactly one
  9. /*
  10. aligned(8) class TrackHeaderBox extends FullBox('tkhd', version, flags){
  11. if (version==1) {
  12. unsigned int(64) creation_time;
  13. unsigned int(64) modification_time;
  14. unsigned int(32) track_ID;
  15. const unsigned int(32) reserved = 0;
  16. unsigned int(64) duration;
  17. } else { // version==0
  18. unsigned int(32) creation_time;
  19. unsigned int(32) modification_time;
  20. unsigned int(32) track_ID;
  21. const unsigned int(32) reserved = 0;
  22. unsigned int(32) duration;
  23. }
  24. const unsigned int(32)[2] reserved = 0;
  25. template int(16) layer = 0;
  26. template int(16) alternate_group = 0;
  27. template int(16) volume = {if track_is_audio 0x0100 else 0};
  28. const unsigned int(16) reserved = 0;
  29. template int(32)[9] matrix= { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 }; // unity matrix
  30. unsigned int(32) width;
  31. unsigned int(32) height;
  32. }
  33. */
  34. int mov_read_tkhd(struct mov_t* mov, const struct mov_box_t* box)
  35. {
  36. int i;
  37. uint8_t version;
  38. uint32_t flags;
  39. uint64_t creation_time;
  40. uint64_t modification_time;
  41. uint64_t duration;
  42. uint32_t track_ID;
  43. struct mov_tkhd_t* tkhd;
  44. struct mov_track_t* track;
  45. version = mov_buffer_r8(&mov->io);
  46. flags = mov_buffer_r24(&mov->io);
  47. if (1 == version)
  48. {
  49. creation_time = mov_buffer_r64(&mov->io);
  50. modification_time = mov_buffer_r64(&mov->io);
  51. track_ID = mov_buffer_r32(&mov->io);
  52. /*reserved = */mov_buffer_r32(&mov->io);
  53. duration = mov_buffer_r64(&mov->io);
  54. }
  55. else
  56. {
  57. assert(0 == version);
  58. creation_time = mov_buffer_r32(&mov->io);
  59. modification_time = mov_buffer_r32(&mov->io);
  60. track_ID = mov_buffer_r32(&mov->io);
  61. /*reserved = */mov_buffer_r32(&mov->io);
  62. duration = mov_buffer_r32(&mov->io);
  63. }
  64. mov_buffer_skip(&mov->io, 8); // const unsigned int(32)[2] reserved = 0;
  65. track = mov_fetch_track(mov, track_ID);
  66. if (NULL == track) return -1;
  67. mov->track = track;
  68. tkhd = &mov->track->tkhd;
  69. tkhd->version = version;
  70. tkhd->flags = flags;
  71. tkhd->duration = duration;
  72. tkhd->creation_time = creation_time;
  73. tkhd->modification_time = modification_time;
  74. tkhd->layer = (int16_t)mov_buffer_r16(&mov->io);
  75. tkhd->alternate_group = (int16_t)mov_buffer_r16(&mov->io);
  76. tkhd->volume = (int16_t)mov_buffer_r16(&mov->io);
  77. mov_buffer_skip(&mov->io, 2); // const unsigned int(16) reserved = 0;
  78. for (i = 0; i < 9; i++)
  79. tkhd->matrix[i] = mov_buffer_r32(&mov->io);
  80. tkhd->width = mov_buffer_r32(&mov->io);
  81. tkhd->height = mov_buffer_r32(&mov->io);
  82. (void)box;
  83. return 0;
  84. }
  85. size_t mov_write_tkhd(const struct mov_t* mov)
  86. {
  87. // int rotation = 0; // 90/180/270
  88. uint16_t group = 0;
  89. const struct mov_tkhd_t* tkhd = &mov->track->tkhd;
  90. mov_buffer_w32(&mov->io, 92); /* size */
  91. mov_buffer_write(&mov->io, "tkhd", 4);
  92. mov_buffer_w8(&mov->io, 0); /* version */
  93. mov_buffer_w24(&mov->io, tkhd->flags); /* flags */
  94. mov_buffer_w32(&mov->io, (uint32_t)tkhd->creation_time); /* creation_time */
  95. mov_buffer_w32(&mov->io, (uint32_t)tkhd->modification_time); /* modification_time */
  96. mov_buffer_w32(&mov->io, tkhd->track_ID); /* track_ID */
  97. mov_buffer_w32(&mov->io, 0); /* reserved */
  98. mov_buffer_w32(&mov->io, (uint32_t)tkhd->duration); /* duration */
  99. mov_buffer_w32(&mov->io, 0); /* reserved */
  100. mov_buffer_w32(&mov->io, 0); /* reserved */
  101. mov_buffer_w16(&mov->io, tkhd->layer); /* layer */
  102. mov_buffer_w16(&mov->io, group); /* alternate_group */
  103. //mov_buffer_w16(&mov->io, AVSTREAM_AUDIO == track->stream_type ? 0x0100 : 0); /* volume */
  104. mov_buffer_w16(&mov->io, tkhd->volume); /* volume */
  105. mov_buffer_w16(&mov->io, 0); /* reserved */
  106. // matrix
  107. //for (i = 0; i < 9; i++)
  108. // file_reader_rb32(mov->fp, tkhd->matrix[i]);
  109. mov_buffer_w32(&mov->io, 0x00010000); /* u */
  110. mov_buffer_w32(&mov->io, 0);
  111. mov_buffer_w32(&mov->io, 0);
  112. mov_buffer_w32(&mov->io, 0); /* v */
  113. mov_buffer_w32(&mov->io, 0x00010000);
  114. mov_buffer_w32(&mov->io, 0);
  115. mov_buffer_w32(&mov->io, 0); /* w */
  116. mov_buffer_w32(&mov->io, 0);
  117. mov_buffer_w32(&mov->io, 0x40000000);
  118. mov_buffer_w32(&mov->io, tkhd->width /*track->av.video.width * 0x10000U*/); /* width */
  119. mov_buffer_w32(&mov->io, tkhd->height/*track->av.video.height * 0x10000U*/); /* height */
  120. return 92;
  121. }