Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed ttml subtitles problem, peak3d/inpustream.adaptive#247 #250

Merged
merged 1 commit into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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