代码之家  ›  专栏  ›  技术社区  ›  user726720

添加包含帧的持续时间

  •  1
  • user726720  · 技术社区  · 6 年前

    e.g1: 00:00:00:00
         hh:mm:ss:FR
    

    FR-表示帧,对于中东/亚洲地区为25帧。

    但在C#中,最后一个FR是秒(即60秒)。

     e.g2: 00:00:00:00
          DD:hh:mm:ss
    

      TimeSpan t1 = TimeSpan.Parse(duration);
      TimeSpan t2 = TimeSpan.Parse("00:00:30:18");
      TimeSpan t3 = t1.Add(t2);
    
    3 回复  |  直到 6 年前
        1
  •  2
  •   Ashkan Mobayen Khiabani    6 年前

    在此期间 "00:00:30:18" 18被认为是毫秒而不是帧,所以 Timespan.Duration

    public static class Extensions
    {
        public static TimeSpan AddWithFrames(this TimeSpan x, TimeSpan ts)
        {
            int fr = ts.Seconds + x.Seconds;
            TimeSpan result = x.Add(ts).Add(new TimeSpan(0,0,fr/25,0));
            return new TimeSpan(result.Days, result.Hours, result.Minutes, fr % 25);
        }
    }
    

    使用方法如下:

     TimeSpan t1 = TimeSpan.Parse(duration);
      TimeSpan t2 = TimeSpan.Parse("00:00:30:18");
      TimeSpan t3 = t1.AddWithFrames(t2);
    
        2
  •  2
  •   Falco Alexander    6 年前

    可以使用自定义类来处理SMPTE时间码的操作。 您不需要重新发明轮子,因为此项目可以处理所有不同类型的帧速率和帧放置:

    https://github.com/ailen0ada/Timecode4net

    using Timecode4net;
    
    var start = Timecode.FromString(input: "00:00:05:15", frameRate: FrameRate.fps25, isDropFrame: false);
    var end = Timecode.FromString("00:00:10:22", FrameRate.fps25, false);
    Console.WriteLine((end.TotalFrames - start.TotalFrames)/25.0);
    

    给你5,28

        3
  •  0
  •   user726720    6 年前

                string timecode1 = "00:05:00:04";
                string timecode2 = "00:06:00:24";
    
                int   hours1 = Int32.Parse(timecode1.Substring(0,2))*90000;
                int   minutes1 =  Int32.Parse(timecode1.Substring(3, 2))*1500;
                int seconds1 = Int32.Parse(timecode1.Substring(6, 2))*25;
                int frames1 = Int32.Parse(timecode1.Substring(9, 2));
    
                int hours2 = Int32.Parse(timecode2.Substring(0, 2)) * 90000;
                int minutes2 = Int32.Parse(timecode2.Substring(3, 2)) * 1500;
                int seconds2 = Int32.Parse(timecode2.Substring(6, 2)) * 25;
                int frames2 = Int32.Parse(timecode2.Substring(9, 2));
    
                int time1 = hours1 + minutes1 + seconds1 + frames1;
                int time2 = hours2 + minutes2 + seconds2 + frames2;
    
                int totaltime = time1 + time2;
    
                int hours = totaltime / 90000;
               int minutes = ((totaltime % 90000)) / 1500;
                int seconds = ((totaltime % 90000) % 1500 )/ 25;
                int frames = ((totaltime % 90000) % 1500) % 25;