ChatGPT: delphi ass字幕转srt字幕

作者: cnpim CNPIM 2023年06月09日

uses  SysUtils, Classes, DateUtils;const  LineBreak = #13#10;type  TSubtitle = record    Start, Stop: TDateTime;    Text: string;  end;function ParseASS(const FileName: string; var Subtitles: TArray<TSubtitle>): Boolean;var  SL: TStringList;  I, P: Integer;  Start, Stop: TDateTime;  Line, Text: string;begin  Result := False;  Subtitles := nil;  SL := TStringList.Create;  try    SL.LoadFromFile(FileName, TEncoding.UTF8);    I := 0;    while (I < SL.Count) and (SL[I] <> '[Events]') do      Inc(I);    Inc(I);    while I < SL.Count do    begin      Line := SL[I];      if Line = '' then        Break;      if Line[1] = 'D' then      begin        Inc(I);        Text := '';        while (I < SL.Count) and (SL[I] <> '') do        begin          Text := Text + SL[I];          Inc(I);        end;        P := Pos(',', Line);        Start := EncodeTime(StrToIntDef(Copy(Line, P + 1, 2), 0),          StrToIntDef(Copy(Line, P + 4, 2), 0),          StrToIntDef(Copy(Line, P + 7, 2), 0),          StrToIntDef(Copy(Line, P + 10, 3), 0));        P := Pos(',', Line, P + 1);        Stop := EncodeTime(StrToIntDef(Copy(Line, P + 1, 2), 0),          StrToIntDef(Copy(Line, P + 4, 2), 0),          StrToIntDef(Copy(Line, P + 7, 2), 0),          StrToIntDef(Copy(Line, P + 10, 3), 0));        SetLength(Subtitles, Length(Subtitles) + 1);        Subtitles[Length(Subtitles) - 1].Start := Start;        Subtitles[Length(Subtitles) - 1].Stop := Stop;        Subtitles[Length(Subtitles) - 1].Text := Text;      end;      Inc(I);    end;    Result := True;  finally    SL.Free;  end;end;procedure SaveSRT(const FileName: string; const Subtitles: TArray<TSubtitle>);var  SL: TStringList;  I: Integer;begin  SL := TStringList.Create;  try    for I := 0 to Length(Subtitles) - 1 do    begin      SL.Add(IntToStr(I + 1));      SL

//它没有写完,不过看样子还是解析出来了ass


本文阅读量:

声明:本信息来源于网络,仅用于学习和技术交流,如有侵权或其他问题,请联系本站处理。

技术支持:CNPIM.COM