2
0

DvdTime.cs 963 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace DvdLib.Ifo
  6. {
  7. public class DvdTime
  8. {
  9. public readonly byte Hour, Minute, Second, Frames, FrameRate;
  10. public DvdTime(byte[] data)
  11. {
  12. Hour = GetBCDValue(data[0]);
  13. Minute = GetBCDValue(data[1]);
  14. Second = GetBCDValue(data[2]);
  15. Frames = GetBCDValue((byte)(data[3] & 0x3F));
  16. if ((data[3] & 0x80) != 0) FrameRate = 30;
  17. else if ((data[3] & 0x40) != 0) FrameRate = 25;
  18. }
  19. private byte GetBCDValue(byte data)
  20. {
  21. return (byte)((((data & 0xF0) >> 4) * 10) + (data & 0x0F));
  22. }
  23. public static explicit operator TimeSpan(DvdTime time)
  24. {
  25. int ms = (int)(((1.0 / (double)time.FrameRate) * time.Frames) * 1000.0);
  26. return new TimeSpan(0, time.Hour, time.Minute, time.Second, ms);
  27. }
  28. }
  29. }