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.

74 rivejä
2.4 KiB

  1. using JT1078.FMp4.Interfaces;
  2. using JT1078.FMp4.MessagePack;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace JT1078.FMp4
  7. {
  8. /// <summary>
  9. /// mvhd
  10. /// </summary>
  11. public class MovieHeaderBox : FullBox, IFMp4MessagePackFormatter
  12. {
  13. /// <summary>
  14. /// mvhd
  15. /// </summary>
  16. /// <param name="version"></param>
  17. /// <param name="flags"></param>
  18. public MovieHeaderBox(byte version, uint flags=0) : base("mvhd", version, flags)
  19. {
  20. }
  21. public ulong CreationTime { get; set; }
  22. public ulong ModificationTime { get; set; }
  23. public uint Timescale { get; set;}
  24. public ulong Duration { get; set; }
  25. public int Rate { get; set; } = 0x00010000;
  26. public short Volume { get; set; } = 0x0100;
  27. public byte[] Reserved1 { get; set; } = new byte[2];
  28. public uint[] Reserved2 { get; set; } = new uint[2];
  29. public int[] Matrix { get; set; }=new int [9]{ 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 };
  30. public byte[] PreDefined { get; set; } = new byte[24];
  31. public uint NextTrackID { get; set; }= uint.MaxValue;
  32. public void ToBuffer(ref FMp4MessagePackWriter writer)
  33. {
  34. Start(ref writer);
  35. WriterFullBoxToBuffer(ref writer);
  36. if (Version == 1)
  37. {
  38. writer.WriteUInt64(CreationTime);
  39. writer.WriteUInt64(ModificationTime);
  40. writer.WriteUInt32(Timescale);
  41. writer.WriteUInt64(Duration);
  42. }
  43. else
  44. {
  45. writer.WriteUInt32((uint)CreationTime);
  46. writer.WriteUInt32((uint)ModificationTime);
  47. writer.WriteUInt32(Timescale);
  48. writer.WriteUInt32((uint)Duration);
  49. }
  50. writer.WriteInt32(Rate);
  51. writer.WriteInt16(Volume);
  52. foreach(var r in Reserved1)
  53. {
  54. writer.WriteByte(r);
  55. }
  56. foreach (var r in Reserved2)
  57. {
  58. writer.WriteUInt32(r);
  59. }
  60. foreach(var m in Matrix)
  61. {
  62. writer.WriteInt32(m);
  63. }
  64. foreach (var pd in PreDefined)
  65. {
  66. writer.WriteByte(pd);
  67. }
  68. writer.WriteUInt32(NextTrackID);
  69. End(ref writer);
  70. }
  71. }
  72. }