C# 添加包含帧的持续时间
我有一个包含帧的持续时间:C# 添加包含帧的持续时间,c#,timespan,C#,Timespan,我有一个包含帧的持续时间: e.g1: 00:00:00:00 hh:mm:ss:FR string timecode1 = "00:05:00:04"; string timecode2 = "00:06:00:24"; int hours1 = Int32.Parse(timecode1.Substring(0,2))*90000; int minutes1 = Int32
e.g1: 00:00:00:00
hh:mm:ss:FR
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;
FR-代表帧,在中东/亚洲地区为25帧
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;
但在C中,最后一个FR是秒,也就是60秒
e.g2: 00:00:00:00
DD:hh:mm:ss
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;
现在我如何在C中添加e.g1
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;
我可以知道如何使用这种格式添加两个持续时间吗
TimeSpan t1 = TimeSpan.Parse(duration);
TimeSpan t2 = TimeSpan.Parse("00:00:30:18");
TimeSpan t3 = t1.Add(t2);
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;
在此持续时间中,00:00:30: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);
}
}
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;
然后像这样使用它:
TimeSpan t1 = TimeSpan.Parse(duration);
TimeSpan t2 = TimeSpan.Parse("00:00:30:18");
TimeSpan t3 = t1.AddWithFrames(t2);
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;
在此持续时间中,00:00:30: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);
}
}
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;
然后像这样使用它:
TimeSpan t1 = TimeSpan.Parse(duration);
TimeSpan t2 = TimeSpan.Parse("00:00:30:18");
TimeSpan t3 = t1.AddWithFrames(t2);
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;
您可以使用一个自定义类来处理SMPTE时间码的操作。 您无需重新设计控制盘,因为此项目可处理所有不同类型的帧速率和帧下降:
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;
为您提供5,28您可以使用自定义类处理SMPTE时间码的操作。
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;
您无需重新设计控制盘,因为此项目可处理所有不同类型的帧速率和帧下降:
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;
给你5,28以下是我是如何做到的,除非有人有更好的方法来简化,请分享
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;
这里是我如何做到的,除非有人有更好的方法来简化这个,请分享
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;
你能建议如何使用吗this@user726720这是一个扩展方法,如果您不知道它是什么,请告诉我详细说明,只需将此代码粘贴到类文件中,然后像以前一样使用。我将方法名称更改为不同于。添加为避免混淆,请参阅我编辑的答案尼斯和简单@FalcoAlexander Thanks这似乎不起作用,它将最后的数字相加,而不是将其视为25帧。例如,如果持续时间为00:00:10:10。它给出了00:00:40:28的结果。鉴于结果应为00:00:41:03,请您建议如何使用this@user726720这是一个扩展方法,如果您不知道它是什么,请告诉我详细说明,只需将此代码粘贴到类文件中,然后像以前一样使用。我将方法名称更改为不同于。添加为避免混淆,请参阅我编辑的答案尼斯和简单@FalcoAlexander Thanks这似乎不起作用,它将最后的数字相加,而不是将其视为25帧。例如,如果持续时间为00:00:10:10。它给出了00:00:40:28的结果。而结果应为00:00:41:03。与打开时出现错误相比,此库在2010201302015年无法打开。你以前试过这个吗。你能建议一下使用这个的方法吗。@user726720什么错误?我刚刚检查了它,添加了代码示例,运行良好,只需导入Timecode4net Nuget PackageDried这个库在2010201302015年无法打开,而打开时会出现错误。你以前试过这个吗。你能建议一下使用这个的方法吗。@user726720什么错误?我刚刚检查了它,添加了代码示例,运行良好,只需导入TimeCode4NetNuget包