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.

126 lines
3.9KB

  1. #include "mov-internal.h"
  2. #include <assert.h>
  3. // ISO/IEC 14496-12:2012(E)
  4. // 8.2.2.1 Movie Header Box (p30)
  5. // Box Type : 'mvhd'
  6. // Container : Movie Box('moov')
  7. // Mandatory : Yes
  8. // Quantity : Exactly one
  9. /*
  10. aligned(8) class MovieHeaderBox extends FullBox('mvhd', version, 0) {
  11. if (version==1) {
  12. unsigned int(64) creation_time;
  13. unsigned int(64) modification_time;
  14. unsigned int(32) timescale;
  15. unsigned int(64) duration;
  16. } else { // version==0
  17. unsigned int(32) creation_time;
  18. unsigned int(32) modification_time;
  19. unsigned int(32) timescale;
  20. unsigned int(32) duration;
  21. }
  22. template int(32) rate = 0x00010000; // typically 1.0
  23. template int(16) volume = 0x0100; // typically, full volume
  24. const bit(16) reserved = 0;
  25. const unsigned int(32)[2] reserved = 0;
  26. template int(32)[9] matrix = {
  27. 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000
  28. }; // Unity matrix
  29. bit(32)[6] pre_defined = 0;
  30. unsigned int(32) next_track_ID;
  31. }
  32. */
  33. int mov_read_mvhd(struct mov_t* mov, const struct mov_box_t* box)
  34. {
  35. int i;
  36. struct mov_mvhd_t* mvhd = &mov->mvhd;
  37. mvhd->version = mov_buffer_r8(&mov->io);
  38. mvhd->flags = mov_buffer_r24(&mov->io);
  39. if (1 == mvhd->version)
  40. {
  41. mvhd->creation_time = mov_buffer_r64(&mov->io);
  42. mvhd->modification_time = mov_buffer_r64(&mov->io);
  43. mvhd->timescale = mov_buffer_r32(&mov->io);
  44. mvhd->duration = mov_buffer_r64(&mov->io);
  45. }
  46. else
  47. {
  48. assert(0 == mvhd->version);
  49. mvhd->creation_time = mov_buffer_r32(&mov->io);
  50. mvhd->modification_time = mov_buffer_r32(&mov->io);
  51. mvhd->timescale = mov_buffer_r32(&mov->io);
  52. mvhd->duration = mov_buffer_r32(&mov->io);
  53. }
  54. mvhd->rate = mov_buffer_r32(&mov->io);
  55. mvhd->volume = (uint16_t)mov_buffer_r16(&mov->io);
  56. //mvhd->reserved = mov_buffer_r16(&mov->io);
  57. //mvhd->reserved2[0] = mov_buffer_r32(&mov->io);
  58. //mvhd->reserved2[1] = mov_buffer_r32(&mov->io);
  59. mov_buffer_skip(&mov->io, 10);
  60. for (i = 0; i < 9; i++)
  61. mvhd->matrix[i] = mov_buffer_r32(&mov->io);
  62. #if 0
  63. for (i = 0; i < 6; i++)
  64. mvhd->pre_defined[i] = mov_buffer_r32(&mov->io);
  65. #else
  66. mov_buffer_r32(&mov->io); /* preview time */
  67. mov_buffer_r32(&mov->io); /* preview duration */
  68. mov_buffer_r32(&mov->io); /* poster time */
  69. mov_buffer_r32(&mov->io); /* selection time */
  70. mov_buffer_r32(&mov->io); /* selection duration */
  71. mov_buffer_r32(&mov->io); /* current time */
  72. #endif
  73. mvhd->next_track_ID = mov_buffer_r32(&mov->io);
  74. (void)box;
  75. return 0;
  76. }
  77. size_t mov_write_mvhd(const struct mov_t* mov)
  78. {
  79. // int rotation = 0; // 90/180/270
  80. const struct mov_mvhd_t* mvhd = &mov->mvhd;
  81. mov_buffer_w32(&mov->io, 108); /* size */
  82. mov_buffer_write(&mov->io, "mvhd", 4);
  83. mov_buffer_w32(&mov->io, 0); /* version & flags */
  84. mov_buffer_w32(&mov->io, (uint32_t)mvhd->creation_time); /* creation_time */
  85. mov_buffer_w32(&mov->io, (uint32_t)mvhd->modification_time); /* modification_time */
  86. mov_buffer_w32(&mov->io, mvhd->timescale); /* timescale */
  87. mov_buffer_w32(&mov->io, (uint32_t)mvhd->duration); /* duration */
  88. mov_buffer_w32(&mov->io, 0x00010000); /* rate 1.0 */
  89. mov_buffer_w16(&mov->io, 0x0100); /* volume 1.0 = normal */
  90. mov_buffer_w16(&mov->io, 0); /* reserved */
  91. mov_buffer_w32(&mov->io, 0); /* reserved */
  92. mov_buffer_w32(&mov->io, 0); /* reserved */
  93. // matrix
  94. mov_buffer_w32(&mov->io, 0x00010000); /* u */
  95. mov_buffer_w32(&mov->io, 0);
  96. mov_buffer_w32(&mov->io, 0);
  97. mov_buffer_w32(&mov->io, 0); /* v */
  98. mov_buffer_w32(&mov->io, 0x00010000);
  99. mov_buffer_w32(&mov->io, 0);
  100. mov_buffer_w32(&mov->io, 0); /* w */
  101. mov_buffer_w32(&mov->io, 0);
  102. mov_buffer_w32(&mov->io, 0x40000000);
  103. mov_buffer_w32(&mov->io, 0); /* reserved (preview time) */
  104. mov_buffer_w32(&mov->io, 0); /* reserved (preview duration) */
  105. mov_buffer_w32(&mov->io, 0); /* reserved (poster time) */
  106. mov_buffer_w32(&mov->io, 0); /* reserved (selection time) */
  107. mov_buffer_w32(&mov->io, 0); /* reserved (selection duration) */
  108. mov_buffer_w32(&mov->io, 0); /* reserved (current time) */
  109. mov_buffer_w32(&mov->io, mvhd->next_track_ID); /* Next track id */
  110. return 108;
  111. }