Skip to content

Commit

Permalink
support span tss:color
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed Sep 25, 2019
1 parent 2a57492 commit fca16d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/parser/TTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ start(void *data, const char *el, const char **attr)
else if (strcmp(el, "span") == 0)
{
const char *style(0);
for (; *attr && !style; attr += 2)
for (; *attr;)
{
if ((nssep = strchr((const char*)*attr, ':')))
*attr = nssep + 1;
if (strcmp((const char*)*attr, "style") == 0)
style = (const char*)*(attr + 1);
else if (strcmp((const char*)*attr, "color") == 0) {
TTML2SRT::STYLE cstyle = ttml->GetStyle(style);
std::string color = (const char*)*(attr + 1);
std::string id = color;
cstyle.id = id;
cstyle.color = color;
ttml->InsertStyle(cstyle);
style = id.c_str();
}
attr += 2;
}
ttml->StackStyle(style);

Expand Down Expand Up @@ -370,6 +380,21 @@ void TTML2SRT::StackText()
m_strSubtitle.clear();
}

TTML2SRT::STYLE TTML2SRT::GetStyle(const char* styleId)
{
if (styleId)
{
for (auto const s : m_styles)
{
if (s.id == styleId)
{
return s;
break;
}
}
}
}

void TTML2SRT::StackStyle(const char* styleId)
{
if (styleId)
Expand All @@ -386,6 +411,8 @@ void TTML2SRT::StackStyle(const char* styleId)
if (sp)
{
STYLE s(m_styleStack.back());
if (!sp->id.empty())
s.id = sp->id;
if (!sp->color.empty())
s.color = sp->color;
if (sp->bold != 0xFF)
Expand Down
1 change: 1 addition & 0 deletions src/parser/TTML.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TTML2SRT
uint8_t dummy;
};
void InsertStyle(const STYLE &style) { m_styles.push_back(style); };
TTML2SRT::STYLE GetStyle(const char* styleId);

struct SUBTITLE
{
Expand Down

3 comments on commit fca16d9

@dagwieers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this already submitted to upstream?

@mediaminister
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was just an experiment/hack with VRT NU streams. And I'm also not sure if the implementation is according to TTML standards. This is completely untested. It should be tested with different TTML sources. I currently have no time to take another look at this.

@dagwieers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

Please sign in to comment.