Skip to content

Commit

Permalink
Merge pull request #250 from mediaminister/fixttml
Browse files Browse the repository at this point in the history
fixed ttml subtitles problem, peak3d/inpustream.adaptive#247
  • Loading branch information
peak3d committed May 21, 2019
2 parents 1367f3b + 899b265 commit 51662f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/parser/TTML.cpp
Expand Up @@ -136,6 +136,8 @@ start(void *data, const char *el, const char **attr)
*attr = nssep + 1;
if (strcmp((const char*)*attr, "tickRate") == 0)
ttml->m_tickRate = atoll((const char*)*(attr + 1));
else if (strcmp((const char*)*attr, "frameRate") == 0)
ttml->m_frameRate = atoll((const char*)*(attr + 1));
attr += 2;
}
}
Expand Down Expand Up @@ -290,15 +292,22 @@ uint64_t TTML2SRT::GetTime(const char *tmchar)
}
else
{
unsigned int th, tm, ts, tms;
char del, ctms[3];
if (sscanf(tmchar, "%u:%u:%u%c%3c", &th, &tm, &ts, &del, ctms) == 5)
unsigned int th, tm, ts, tf;
char del, ctf [4];
if (sscanf(tmchar, "%u:%u:%u%c%s", &th, &tm, &ts, &del, ctf) == 5)
{
sscanf(ctms, "%3u", &tms);
if (strlen(ctms) == 2)
tms = tms*10;
sscanf(ctf, "%u", &tf);
if (strlen(ctf) == 2 && del == '.')
tf = tf * 10;
else if (strlen(ctf) == 2 && del == ':')
{
if (m_frameRate)
tf = (tf * 1000 / m_frameRate);
else
tf = (tf * 1000 / 30);
}
ret = th * 3600 + tm * 60 + ts;
ret = ret * 1000 + tms;
ret = ret * 1000 + tf;
ret = (ret * m_timescale) / 1000;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/TTML.h
Expand Up @@ -26,7 +26,7 @@
class TTML2SRT
{
public:
TTML2SRT() :m_node(0), m_pos(0), m_tickRate(0), m_timescale(0), m_ptsOffset(0) { m_styleStack.push_back(STYLE()); };
TTML2SRT() :m_node(0), m_pos(0), m_tickRate(0), m_frameRate(0), m_timescale(0), m_ptsOffset(0) { m_styleStack.push_back(STYLE()); };

bool Parse(const void *buffer, size_t buffer_size, uint64_t timescale, uint64_t ptsOffset);

Expand Down Expand Up @@ -75,7 +75,7 @@ class TTML2SRT
static const uint32_t NODE_SPAN = 1 << 13;

uint32_t m_node, m_pos;
uint64_t m_tickRate;
uint64_t m_tickRate, m_frameRate;
private:
uint64_t GetTime(const char * tm);

Expand Down

0 comments on commit 51662f7

Please sign in to comment.