MythTV  master
srtwriter.cpp
Go to the documentation of this file.
1 #include "srtwriter.h"
2 
3 // SRTWriter implementation
4 
8 void SRTWriter::AddSubtitle(const OneSubtitle &sub, int number)
9 {
10  m_outStream << number << endl;
11 
12  m_outStream << FormatTime(sub.m_startTime) << " --> ";
13  m_outStream << FormatTime(sub.m_startTime + sub.m_length) << endl;
14 
15  if (!sub.m_text.isEmpty())
16  {
17  foreach (const auto & text, sub.m_text)
18  m_outStream << text << endl;
19  m_outStream << endl;
20  }
21 }
22 
26 QString SRTWriter::FormatTime(uint64_t time_in_msec)
27 {
28  uint64_t msec = time_in_msec % 1000;
29  time_in_msec /= 1000;
30 
31  uint64_t ss = time_in_msec % 60;
32  time_in_msec /= 60;
33 
34  uint64_t mm = time_in_msec % 60;
35  time_in_msec /= 60;
36 
37  uint64_t hh = time_in_msec;
38 
39  return QString("%1:%2:%3,%4")
40  .arg(hh,2,10,QChar('0'))
41  .arg(mm,2,10,QChar('0'))
42  .arg(ss,2,10,QChar('0'))
43  .arg(msec,3,10,QChar('0'));
44 }
QTextStream m_outStream
Output stream associated with m_outFile.
Definition: srtwriter.h:60
int64_t m_startTime
Time we have to start showing subtitle, msec.
int m_length
Time we have to show subtitle, msec.
QStringList m_text
Lines of text of subtitles.
void AddSubtitle(const OneSubtitle &sub, int number)
Adds next subtitle.
Definition: srtwriter.cpp:8
static QString FormatTime(uint64_t time_in_msec)
Formats time to format appropriate to SubRip file.
Definition: srtwriter.cpp:26
Represents one subtitle record.