tkhd.c
上传用户:luping1608
上传日期:2007-01-06
资源大小:38k
文件大小:3k
源码类别:

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_tkhd_init(quicktime_tkhd_t *tkhd)
  3. {
  4. int i;
  5. tkhd->version = 0;
  6. tkhd->flags = 15;
  7. tkhd->creation_time = quicktime_current_time();
  8. tkhd->modification_time = quicktime_current_time();
  9. tkhd->track_id;
  10. tkhd->reserved1 = 0;
  11. tkhd->duration = 0;      // need to set this when closing
  12. for(i = 0; i < 8; i++) tkhd->reserved2[i] = 0;
  13. tkhd->layer = 0;
  14. tkhd->alternate_group = 0;
  15. tkhd->volume = 0.996094;
  16. tkhd->reserved3 = 0;
  17. quicktime_matrix_init(&(tkhd->matrix));
  18. tkhd->track_width = 0;
  19. tkhd->track_height = 0;
  20. return 0;
  21. }
  22. int quicktime_tkhd_delete(quicktime_tkhd_t *tkhd)
  23. {
  24. return 0;
  25. }
  26. int quicktime_tkhd_dump(quicktime_tkhd_t *tkhd)
  27. {
  28. printf("  track headern");
  29. printf("   version %dn", tkhd->version);
  30. printf("   flags %ldn", tkhd->flags);
  31. printf("   creation_time %un", tkhd->creation_time);
  32. printf("   modification_time %un", tkhd->modification_time);
  33. printf("   track_id %dn", tkhd->track_id);
  34. printf("   reserved1 %ldn", tkhd->reserved1);
  35. printf("   duration %ldn", tkhd->duration);
  36. quicktime_print_chars("   reserved2 ", tkhd->reserved2, 8);
  37. printf("   layer %dn", tkhd->layer);
  38. printf("   alternate_group %dn", tkhd->alternate_group);
  39. printf("   volume %fn", tkhd->volume);
  40. printf("   reserved3 %dn", tkhd->reserved3);
  41. quicktime_matrix_dump(&(tkhd->matrix));
  42. printf("   track_width %fn", tkhd->track_width);
  43. printf("   track_height %fn", tkhd->track_height);
  44. }
  45. int quicktime_read_tkhd(quicktime_t *file, quicktime_tkhd_t *tkhd)
  46. {
  47. tkhd->version = quicktime_read_char(file);
  48. tkhd->flags = quicktime_read_int24(file);
  49. tkhd->creation_time = quicktime_read_int32(file);
  50. tkhd->modification_time = quicktime_read_int32(file);
  51. tkhd->track_id = quicktime_read_int32(file);
  52. tkhd->reserved1 = quicktime_read_int32(file);
  53. tkhd->duration = quicktime_read_int32(file);
  54. quicktime_read_data(file, tkhd->reserved2, 8);
  55. tkhd->layer = quicktime_read_int16(file);
  56. tkhd->alternate_group = quicktime_read_int16(file);
  57. tkhd->volume = quicktime_read_fixed16(file);
  58. tkhd->reserved3 = quicktime_read_int16(file);
  59. quicktime_read_matrix(file, &(tkhd->matrix));
  60. tkhd->track_width = quicktime_read_fixed32(file);
  61. tkhd->track_height = quicktime_read_fixed32(file);
  62. }
  63. int quicktime_write_tkhd(quicktime_t *file, quicktime_tkhd_t *tkhd)
  64. {
  65. quicktime_atom_t atom;
  66. quicktime_atom_write_header(file, &atom, "tkhd");
  67. quicktime_write_char(file, tkhd->version);
  68. quicktime_write_int24(file, tkhd->flags);
  69. quicktime_write_int32(file, tkhd->creation_time);
  70. quicktime_write_int32(file, tkhd->modification_time);
  71. quicktime_write_int32(file, tkhd->track_id);
  72. quicktime_write_int32(file, tkhd->reserved1);
  73. quicktime_write_int32(file, tkhd->duration);
  74. quicktime_write_data(file, tkhd->reserved2, 8);
  75. quicktime_write_int16(file, tkhd->layer);
  76. quicktime_write_int16(file, tkhd->alternate_group);
  77. quicktime_write_fixed16(file, tkhd->volume);
  78. quicktime_write_int16(file, tkhd->reserved3);
  79. quicktime_write_matrix(file, &(tkhd->matrix));
  80. quicktime_write_fixed32(file, tkhd->track_width);
  81. quicktime_write_fixed32(file, tkhd->track_height);
  82. quicktime_atom_write_footer(file, &atom);
  83. }
  84. int quicktime_tkhd_init_video(quicktime_t *file, 
  85. quicktime_tkhd_t *tkhd, 
  86. int frame_w, 
  87. int frame_h)
  88. {
  89. tkhd->track_width = frame_w;
  90. tkhd->track_height = frame_h;
  91. tkhd->volume = 0;
  92. }