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.start_time) << " --> ";
13  m_outStream << FormatTime(sub.start_time + sub.length) << endl;
14 
15  if (!sub.text.isEmpty())
16  {
17  QStringList::const_iterator it = sub.text.begin();
18  for (; it != sub.text.end(); ++it)
19  m_outStream << *it << endl;
20  m_outStream << endl;
21  }
22 }
23 
27 QString SRTWriter::FormatTime(uint64_t time_in_msec)
28 {
29  uint64_t msec = time_in_msec % 1000;
30  time_in_msec /= 1000;
31 
32  uint64_t ss = time_in_msec % 60;
33  time_in_msec /= 60;
34 
35  uint64_t mm = time_in_msec % 60;
36  time_in_msec /= 60;
37 
38  uint64_t hh = time_in_msec;
39 
40  return QString("%1:%2:%3,%4")
41  .arg(hh,2,10,QChar('0'))
42  .arg(mm,2,10,QChar('0'))
43  .arg(ss,2,10,QChar('0'))
44  .arg(msec,3,10,QChar('0'));
45 }
QTextStream m_outStream
Output stream associated with m_outFile.
Definition: srtwriter.h:60
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:27
int length
Time we have to show subtitle, msec.
Represents one subtitle record.
QStringList text
Lines of text of subtitles.
int64_t start_time
Time we have to start showing subtitle, msec.