MythTV  master
srtwriter.cpp
Go to the documentation of this file.
1 #include "captions/srtwriter.h"
2 
3 // SRTWriter implementation
4 
8 void SRTWriter::AddSubtitle(const OneSubtitle &sub, int number)
9 {
10  m_outStream << number << Qt::endl;
11 
12  m_outStream << FormatTime(sub.m_startTime) << " --> ";
13  m_outStream << FormatTime(sub.m_startTime + sub.m_length) << Qt::endl;
14 
15  if (!sub.m_text.isEmpty())
16  {
17  for (const auto & text : std::as_const(sub.m_text))
18  m_outStream << text << Qt::endl;
19  m_outStream << Qt::endl;
20  }
21 }
22 
26 QString SRTWriter::FormatTime(std::chrono::milliseconds time_in_msec)
27 {
28  QTime time = QTime::fromMSecsSinceStartOfDay(time_in_msec.count());
29  return time.toString("HH:mm:ss,zzz");
30 }
SRTWriter::FormatTime
static QString FormatTime(std::chrono::milliseconds time_in_msec)
Formats time to format appropriate to SubRip file.
Definition: srtwriter.cpp:26
OneSubtitle
Represents one subtitle record.
Definition: mythccextractorplayer.h:29
SRTWriter::AddSubtitle
void AddSubtitle(const OneSubtitle &sub, int number)
Adds next subtitle.
Definition: srtwriter.cpp:8
srtwriter.h
OneSubtitle::m_length
std::chrono::milliseconds m_length
Time we have to show subtitle, msec.
Definition: mythccextractorplayer.h:35
SRTWriter::m_outStream
QTextStream m_outStream
Output stream associated with m_outFile.
Definition: srtwriter.h:68
OneSubtitle::m_text
QStringList m_text
Lines of text of subtitles.
Definition: mythccextractorplayer.h:39
OneSubtitle::m_startTime
std::chrono::milliseconds m_startTime
Time we have to start showing subtitle, msec.
Definition: mythccextractorplayer.h:33