如何延迟字幕
How to delay subtitles
我必须编写一个延迟字幕的代码。
我必须打开.srt文件更改一段时间并将其保存在另一个文件中。我知道如何打开文件并将其全部复制到其他文件。
例如,如果我打开"字幕.srt",然后输入输出文件"output"的名称,我会将"字幕.srt"的复制内容复制到"输出字幕.srt"。
这没关系,但我不知道如何延迟时间,例如如果我输入"10"
原字幕.srt00:00:01,067 --> 00:00:03,963然后我输入 10输出字幕.srt00:00:11,067 --> 00:00:13,963
我必须一直改变。
#include "stdafx.h"
#include "iostream"
#include "cstdlib"
#include "fstream"
#include "string"
using namespace std;
int main(int argc, char *argv[]){
ifstream input; //input
char input_file[32]; //names of input and output
cout << "Enter name of input fille: "; ///user gives names of input
cin >> input_file;
input.open(input_file);
if (!input.good()){
cout << "File " << input_file << " dosen't exist." << endl;
return 1;
}
string row;
while (!input.eof()){
getline(input, row);
cout << row << endl;
}
system("pause");
return 0;
}
我假设字符串格式是hour:minute:second,millisecond
.好吧,这个函数将字符串作为初始时间,并以秒为单位添加一个 int 量。如果你给它一个负时间,它可能会中断,但任何合理的正时间都可以正常工作。它返回输出字符串,因此您可以突出打印旧字符串所在的位置。
string add(string str, int amount) {
int vals[8];
sscanf(str.c_str(), "%u:%u:%u,%u --> %u:%u:%u,%u",
&vals[0], &vals[1], &vals[2], &vals[3],
&vals[4], &vals[5], &vals[6], &vals[7]);
vals[2] += amount;
vals[6] += amount;
while((vals[2]>=60) || (vals[1]>=60) ||
(vals[6]>=60) || (vals[5]>=60)) {
if(vals[2] >= 60) {
vals[2] -= 60;
vals[1]++;
}
if(vals[6] >= 60) {
vals[6] -= 60;
vals[5]++;
}
if(vals[1] >= 60) {
vals[1] -= 60;
vals[0]++;
}
if(vals[5] >= 60) {
vals[5] -= 60;
vals[4]++;
}
}
string out;
out.resize(str.length());
int n = sprintf(&out[0], "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u",
vals[0], vals[1], vals[2], vals[3],
vals[4], vals[5], vals[6], vals[7]);
return out;
};
相关文章:
- 如何仅为一个函数添加延迟
- 以在Qt中的IF语句中设置时间延迟
- 模板化类中静态成员的延迟初始化
- 在 Windows 8/10 技术中完全实时的屏幕捕获,没有延迟
- 将自定义函数传递到基抽象类中以延迟执行
- 我希望改进或要求我目前的延迟/睡眠方法。C++
- 如何在 c++ 中延迟?
- 如何测量管道延迟?
- 获取毫秒延迟的错误值
- C++异常被捕获延迟,可能导致这种情况的原因是什么?
- 我的子类的属性是延迟初始化的
- 为什么有些延迟加载 DLL 会立即使用 FFMPEG 卸载?
- 代码战士的延迟
- 为什么当通过 TCP 发送的消息速率增加时,请求-响应消息对的延迟会降低?
- C++延迟后的优化器调用函数
- 将作业传递给另一个函数,而不会延迟 arduino
- 延迟 _getch() 输入
- 为什么添加延迟会提高此多线程环境中的数据吞吐量?
- 如何延迟生成已完成的项目序列并对其进行迭代
- 如何延迟字幕