重叠时拆分时间跨度
Splitting timespan when overlapping
我有多个 TXT 文件,这些文件表示所选视频部分的时间跨度(以秒为单位)。例如,1.23-5.45.
我想利用这些时间跨度拍摄多个视频的这些部分,并创建一个包含所有部分的视频。
我正在将所有这些 TXT 文件解析为一组键值对列表:
List<KeyValuePair<Double, Double>>[] TagsOfSeconds= new List<KeyValuePair<Double, Double>>[]()
数组元素的每个索引代表一个TXT文件。每个元素都是一个键值对列表,其中每对是秒时间跨度的开始和结束。
我的需求是解析这些TXT文件,将时间跨度分割成5秒的片段(以5秒为例,片段值由用户提供),并将优先级高的片段排序为最小的片段值(发生在其他段之前),如果两个相等,则取 TagsOfSeconds 数组中的第一个。
这是一个例子。段顺序是我想要实现的目标:
我创建了以下结构来跟踪从文本文件中解析的部分:
public struct PortionInfo
{
public Double Start, End;
public int VideoIndex, PortionIndex;
public Double PortionLength;
}
这是我根据开始时间跨度和 TXT 文件索引对加载的片段进行排序的代码:
private void OrderVideoPortions(List<KeyValuePair<Double, Double>>[] videoPortionslist)
{
videoPortionsOrder = new List<PortionInfo>(); //videoPortionsOrder.Sort()
for(int i=0;i< videoPortionslist.Length;i++)
{
for (int j = 0; j < videoPortionslist[i].Count; j++)
{
PortionInfo currentPortionInfo = new PortionInfo();
currentPortionInfo.VideoIndex = i;
currentPortionInfo.PortionIndex = j;
currentPortionInfo.Start = videoPortionslist[i][j].Key;
currentPortionInfo.End = videoPortionslist[i][j].Value;
currentPortionInfo.PortionLength = currentPortionInfo.End - currentPortionInfo.Start;
videoPortionsOrder.Add(currentPortionInfo);
}
}
videoPortionsOrder.Sort(SortAscending);
}
public static int SortAscending(PortionInfo p1, PortionInfo p2)
{
int returnVal = p1.Start.CompareTo(p2.Start);
if (returnVal == 0)
{
return p1.VideoIndex.CompareTo(p2.VideoIndex);
}
else
return returnVal;
}
现在我必须从排序列表中生成段。
任何人都可以帮助我实现这一目标吗?我只需要有关确定交叉点和线段的帮助或指导。
我修改了 PortionInfo 结构,使其具有构造函数和一个在创建结构时自动设置为 true 的 bool Active。
private void CreateFinalSegments(List<PortionInfo> orderedVideoPortions)
{
int segmentSize = int.Parse(_txtTimeSegments.Text);
int extrSegmentDuration = int.Parse(_txtExtraDurationAllowed.Text);
PortionInfo currentPortion = new PortionInfo();
finalSegments = new List<PortionInfo>();
if (_txtExtraDurationAllowed.Text == "0" || _txtTimeSegments.Text == "0")
{
return;//Check that still needs to be handled
}
else
{
for (int i=0;i< orderedVideoPortions.Count;i++)
{
if (orderedVideoPortions[i].Active)
{
if (orderedVideoPortions[i].PortionLength <= (segmentSize + extrSegmentDuration))
{
finalSegments.Add(orderedVideoPortions[i]);
currentPortion = orderedVideoPortions[i];
currentPortion.Active = false;
orderedVideoPortions[i]=currentPortion ;
}
else
{
currentPortion = orderedVideoPortions[i];
finalSegments.Add(new PortionInfo(currentPortion.Start, currentPortion.Start+ segmentSize, currentPortion.VideoIndex, currentPortion.PortionIndex));
currentPortion.Start += segmentSize;
currentPortion.PortionLength = currentPortion.End - currentPortion.Start;
orderedVideoPortions[i] = currentPortion;
orderedVideoPortions.Sort(SortAscending);
i = 0;//Note: Needs to be rechecked because --i should be enough.
}
}
}
Application.DoEvents();
_lblStatus.Text = "Video segments generated. Now Working on generating final video";
}
}
我有多个 TXT 文件,这些文件表示所选视频部分的时间跨度(以秒为单位)。例如,1.23-5.45.
我想利用这些时间跨度拍摄多个视频的这些部分,并创建一个包含所有部分的视频。
我正在将所有这些 TXT 文件解析为一组键值对列表:
List<KeyValuePair<Double, Double>>[] TagsOfSeconds= new List<KeyValuePair<Double, Double>>[]()
数组元素的每个索引代表一个TXT文件。每个元素都是一个键值对列表,其中每对是秒时间跨度的开始和结束。
我的需求是解析这些TXT文件,将时间跨度分割成5秒的片段(以5秒为例,片段值由用户提供),并将优先级高的片段排序为最小的片段值(发生在其他段之前),如果两个相等,则取 TagsOfSeconds 数组中的第一个。
这是一个例子。段顺序是我想要实现的目标:
public struct PortionInfo
{
public Double Start, End;
public int VideoIndex, PortionIndex;
public Double PortionLength;
}
这是我根据开始时间跨度和 TXT 文件索引对加载的片段进行排序的代码:
private void OrderVideoPortions(List<KeyValuePair<Double, Double>>[] videoPortionslist)
{
videoPortionsOrder = new List<PortionInfo>(); //videoPortionsOrder.Sort()
for(int i=0;i< videoPortionslist.Length;i++)
{
for (int j = 0; j < videoPortionslist[i].Count; j++)
{
PortionInfo currentPortionInfo = new PortionInfo();
currentPortionInfo.VideoIndex = i;
currentPortionInfo.PortionIndex = j;
currentPortionInfo.Start = videoPortionslist[i][j].Key;
currentPortionInfo.End = videoPortionslist[i][j].Value;
currentPortionInfo.PortionLength = currentPortionInfo.End - currentPortionInfo.Start;
videoPortionsOrder.Add(currentPortionInfo);
}
}
videoPortionsOrder.Sort(SortAscending);
}
public static int SortAscending(PortionInfo p1, PortionInfo p2)
{
int returnVal = p1.Start.CompareTo(p2.Start);
if (returnVal == 0)
{
return p1.VideoIndex.CompareTo(p2.VideoIndex);
}
else
return returnVal;
}
现在我必须从排序列表中生成段。
任何人都可以帮助我实现这一目标吗?我只需要有关确定交叉点和线段的帮助或指导。
我修改了 PortionInfo 结构,使其具有构造函数和一个在创建结构时自动设置为 true 的 bool Active。
private void CreateFinalSegments(List<PortionInfo> orderedVideoPortions)
{
int segmentSize = int.Parse(_txtTimeSegments.Text);
int extrSegmentDuration = int.Parse(_txtExtraDurationAllowed.Text);
PortionInfo currentPortion = new PortionInfo();
finalSegments = new List<PortionInfo>();
if (_txtExtraDurationAllowed.Text == "0" || _txtTimeSegments.Text == "0")
{
return;//Check that still needs to be handled
}
else
{
for (int i=0;i< orderedVideoPortions.Count;i++)
{
if (orderedVideoPortions[i].Active)
{
if (orderedVideoPortions[i].PortionLength <= (segmentSize + extrSegmentDuration))
{
finalSegments.Add(orderedVideoPortions[i]);
currentPortion = orderedVideoPortions[i];
currentPortion.Active = false;
orderedVideoPortions[i]=currentPortion ;
}
else
{
currentPortion = orderedVideoPortions[i];
finalSegments.Add(new PortionInfo(currentPortion.Start, currentPortion.Start+ segmentSize, currentPortion.VideoIndex, currentPortion.PortionIndex));
currentPortion.Start += segmentSize;
currentPortion.PortionLength = currentPortion.End - currentPortion.Start;
orderedVideoPortions[i] = currentPortion;
orderedVideoPortions.Sort(SortAscending);
i = 0;//Note: Needs to be rechecked because --i should be enough.
}
}
}
Application.DoEvents();
_lblStatus.Text = "Video segments generated. Now Working on generating final video";
}
}