【问题标题】:Storing timepoints or durations存储时间点或持续时间
【发布时间】:2021-12-01 00:19:08
【问题描述】:

我想制作一个简单的编辑器来改变字幕时间。 WebVTT 的字幕是由这样的块组成的:

1
00:02:15.000 --> 00:02:20.000
- Hello World!

如您所见,字幕有时会出现,有时会消失。这个时间也可以点击跳转到视频文件的那个特定点。

现在我想创建一个简单的应用程序,可以将这些时间在时域中向左或向右移动给定的数量。存储这些时间点以便于计算和更改的最佳方式是什么?

例如:

struct SubtitleElement {
   std::chrono< ?????? > begin; // What is a good candidate here?
   std::chrono< ?????? > end; // What is a good candidate here?
   std::string text;  
}

稍后我想要对这些元素进行操作的函数。例如:

void shiftTime(SubtitleElement element, int millisecs) {

 // reduce begin and end of the element by millisecs

}

DURATION getDuration(SubtitleElement& element) {
  //return   end - begin 
}

   DURATION totalDuration(vector<SubtitleElement> elements) {
     // sum all the durations of the elements in vector
   }

那么最干净、最现代的方法是什么?同样重要的是,将字符串“hh:mm:ss:ZZZ”转换为该成员很容易。请注意,我认为 hh 可以远远超过 24,因为它的时间量,而不是一天中的时间!例如。一个vido文件可以长达120小时!!

【问题讨论】:

    标签: c++ c++17 chrono


    【解决方案1】:

    由于这些是相对于视频开头的时间点,而不是某个时钟,我建议保持简单并使用std::chrono::milliseconds。它们支持您需要的所有操作,除了我不确定是否存在从字符串解析它们的现有实现。但这应该很容易构建。

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 2017-12-24
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多