gpt4 book ai didi

delphi - 如何纠正/移动 SRT (SubRip) 文件中的字幕时间?

转载 作者:行者123 更新时间:2023-12-03 15:00:11 25 4
gpt4 key购买 nike

如何向前或向后修正/移动字幕时间?字幕时间格式如下:00:00:52,656 --> 00:00:56,326

如果字幕和音频不同步,例如,字幕显示在语音/音频之前,则显示字幕行的所有时间(时间格式:00:00:52,656 --> 00:00:56,326)应该更正。

所以,如果所有字幕行的时间必须更改/移动 2 秒。向前,然后,这次字幕行: 00:00:52,656 --> 00:00:56,326 应更改为:00:00:54,656 --> 00:00:58,326

这指的是字幕文件中的所有时间,而不仅仅是一行文本/一次。

<小时/>

SubRip (.srt) 文件的外观示例:

1
00:00:52,656 --> 00:00:56,326
Kanalska Zona: Panama

2
00:00:56,335 --> 00:00:59,755
Francuzi su pokušali da izgrade
kanal pre Amerikanaca.

最佳答案

假设输入中每行的格式始终为 00:00:00,000 --> 00:00:00,000,则此例程会将字符串时间转换为 TDateTime,添加或减去移位,然后重写该行:

procedure ShiftSubtitleTimes(Lines: TStrings; Diff: TTime);
var
FS: TFormatSettings;
I: Integer;
T1: TDateTime;
T2: TDateTime;
begin
// Ensure using the correct time separator
FS.TimeSeparator := ':';
// Parse each line separately
for I := 0 to Lines.Count - 1 do
begin
// Convert the two time strings to time values
if not TryStrToTime(Copy(Lines[I], 1, 8), T1, FS) then
// But skip line in case of wrong format
Continue;
T1 := T1 + StrToInt(Copy(Lines[I], 10, 3)) / MSecsPerDay;
T2 := StrToTime(Copy(Lines[I], 18, 8), FS);
T2 := T2 + StrToInt(Copy(Lines[I], 27, 3)) / MSecsPerDay;
// Add the shift
T1 := T1 + Diff;
T2 := T2 + Diff;
// Rewrite the line
Lines[I] := FormatDateTime('hh:nn:ss,zzz --> ', T1, FS) +
FormatDateTime('hh:nn:ss,zzz', T2, FS);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
begin
List := TStringList.Create;
try
List.LoadFromFile('Filename.dat');
Memo1.Lines.Add('Input:');
Memo1.Lines.AddStrings(List);
Memo1.Lines.Add('');
// Shift 3,5 seconds backwards:
ShiftSubtitleTimes(List, -3.5 / SecsPerDay);
Memo1.Lines.Add('Output:');
Memo1.Lines.AddStrings(List);
finally
List.Free;
end;
end;

enter image description here

编辑:

由于您的编辑,现在输入可能包含也不需要转换的“错误”行。

关于delphi - 如何纠正/移动 SRT (SubRip) 文件中的字幕时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12864047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com