mvhd.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:4k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_mvhd_init(quicktime_mvhd_t *mvhd)
  3. {
  4. int i;
  5. mvhd->version = 0;
  6. mvhd->flags = 0;
  7. mvhd->creation_time = quicktime_current_time();
  8. mvhd->modification_time = quicktime_current_time();
  9. mvhd->time_scale = 90000;
  10. mvhd->duration = 0;
  11. mvhd->preferred_rate = 1.0;
  12. mvhd->preferred_volume = 0.996094;
  13. for(i = 0; i < 10; i++) mvhd->reserved[i] = 0;
  14. quicktime_matrix_init(&(mvhd->matrix));
  15. mvhd->preview_time = 0;
  16. mvhd->preview_duration = 0;
  17. mvhd->poster_time = 0;
  18. mvhd->selection_time = 0;
  19. mvhd->selection_duration = 0;
  20. mvhd->current_time = 0;
  21. mvhd->next_track_id = 1;
  22. return 0;
  23. }
  24. int quicktime_mvhd_delete(quicktime_mvhd_t *mvhd)
  25. {
  26. return 0;
  27. }
  28. int quicktime_mvhd_dump(quicktime_mvhd_t *mvhd)
  29. {
  30. printf(" movie headern");
  31. printf("  version %dn", mvhd->version);
  32. printf("  flags %ldn", mvhd->flags);
  33. printf("  creation_time %un", mvhd->creation_time);
  34. printf("  modification_time %un", mvhd->modification_time);
  35. printf("  time_scale %ldn", mvhd->time_scale);
  36. printf("  duration %ldn", mvhd->duration);
  37. printf("  preferred_rate %fn", mvhd->preferred_rate);
  38. printf("  preferred_volume %fn", mvhd->preferred_volume);
  39. quicktime_print_chars("  reserved ", mvhd->reserved, 10);
  40. quicktime_matrix_dump(&(mvhd->matrix));
  41. printf("  preview_time %ldn", mvhd->preview_time);
  42. printf("  preview_duration %ldn", mvhd->preview_duration);
  43. printf("  poster_time %ldn", mvhd->poster_time);
  44. printf("  selection_time %ldn", mvhd->selection_time);
  45. printf("  selection_duration %ldn", mvhd->selection_duration);
  46. printf("  current_time %ldn", mvhd->current_time);
  47. printf("  next_track_id %ldn", mvhd->next_track_id);
  48. }
  49. int quicktime_read_mvhd(quicktime_t *file, quicktime_mvhd_t *mvhd)
  50. {
  51. mvhd->version = quicktime_read_char(file);
  52. mvhd->flags = quicktime_read_int24(file);
  53. mvhd->creation_time = quicktime_read_int32(file);
  54. mvhd->modification_time = quicktime_read_int32(file);
  55. mvhd->time_scale = quicktime_read_int32(file);
  56. mvhd->duration = quicktime_read_int32(file);
  57. mvhd->preferred_rate = quicktime_read_fixed32(file);
  58. mvhd->preferred_volume = quicktime_read_fixed16(file);
  59. quicktime_read_data(file, mvhd->reserved, 10);
  60. quicktime_read_matrix(file, &(mvhd->matrix));
  61. mvhd->preview_time = quicktime_read_int32(file);
  62. mvhd->preview_duration = quicktime_read_int32(file);
  63. mvhd->poster_time = quicktime_read_int32(file);
  64. mvhd->selection_time = quicktime_read_int32(file);
  65. mvhd->selection_duration = quicktime_read_int32(file);
  66. mvhd->current_time = quicktime_read_int32(file);
  67. mvhd->next_track_id = quicktime_read_int32(file);
  68. }
  69. int quicktime_write_mvhd(quicktime_t *file, quicktime_mvhd_t *mvhd)
  70. {
  71. quicktime_atom_t atom;
  72. quicktime_atom_write_header(file, &atom, "mvhd");
  73. quicktime_write_char(file, mvhd->version);
  74. quicktime_write_int24(file, mvhd->flags);
  75. quicktime_write_int32(file, mvhd->creation_time);
  76. quicktime_write_int32(file, mvhd->modification_time);
  77. quicktime_write_int32(file, mvhd->time_scale);
  78. quicktime_write_int32(file, mvhd->duration);
  79. if (file->use_mp4) {
  80. int i;
  81. quicktime_write_int32(file, 0x00010000);
  82. quicktime_write_int16(file, 0x0100);
  83. quicktime_write_int16(file, 0x0000);
  84. quicktime_write_int32(file, 0x00000000);
  85. quicktime_write_int32(file, 0x00000000);
  86. quicktime_write_int32(file, 0x00010000);
  87. for (i = 0; i < 3; i++) {
  88. quicktime_write_int32(file, 0x00000000);
  89. }
  90. quicktime_write_int32(file, 0x00010000);
  91. for (i = 0; i < 3; i++) {
  92. quicktime_write_int32(file, 0x00000000);
  93. }
  94. quicktime_write_int32(file, 0x40000000);
  95. for (i = 0; i < 6; i++) {
  96. quicktime_write_int32(file, 0x00000000);
  97. }
  98. } else {
  99. quicktime_write_fixed32(file, mvhd->preferred_rate);
  100. quicktime_write_fixed16(file, mvhd->preferred_volume);
  101. quicktime_write_data(file, mvhd->reserved, 10);
  102. quicktime_write_matrix(file, &(mvhd->matrix));
  103. quicktime_write_int32(file, mvhd->preview_time);
  104. quicktime_write_int32(file, mvhd->preview_duration);
  105. quicktime_write_int32(file, mvhd->poster_time);
  106. quicktime_write_int32(file, mvhd->selection_time);
  107. quicktime_write_int32(file, mvhd->selection_duration);
  108. quicktime_write_int32(file, mvhd->current_time);
  109. }
  110. quicktime_write_int32(file, mvhd->next_track_id);
  111. quicktime_atom_write_footer(file, &atom);
  112. }