2
0

DvdTime.cs 895 B

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