mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
subparse: Add support for parsing LRC subtitles
https://bugzilla.gnome.org/show_bug.cgi?id=678590
This commit is contained in:
parent
bc2342e4ad
commit
218d0702c9
1 changed files with 36 additions and 1 deletions
|
@ -60,7 +60,8 @@ static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS ("application/x-subtitle; application/x-subtitle-sami; "
|
GST_STATIC_CAPS ("application/x-subtitle; application/x-subtitle-sami; "
|
||||||
"application/x-subtitle-tmplayer; application/x-subtitle-mpl2; "
|
"application/x-subtitle-tmplayer; application/x-subtitle-mpl2; "
|
||||||
"application/x-subtitle-dks; application/x-subtitle-qttext")
|
"application/x-subtitle-dks; application/x-subtitle-qttext;"
|
||||||
|
"application/x-subtitle-lrc;")
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -373,6 +374,8 @@ gst_sub_parse_get_format_description (GstSubParseFormat format)
|
||||||
return "DKS";
|
return "DKS";
|
||||||
case GST_SUB_PARSE_FORMAT_QTTEXT:
|
case GST_SUB_PARSE_FORMAT_QTTEXT:
|
||||||
return "QTtext";
|
return "QTtext";
|
||||||
|
case GST_SUB_PARSE_FORMAT_LRC:
|
||||||
|
return "LRC";
|
||||||
default:
|
default:
|
||||||
case GST_SUB_PARSE_FORMAT_UNKNOWN:
|
case GST_SUB_PARSE_FORMAT_UNKNOWN:
|
||||||
break;
|
break;
|
||||||
|
@ -917,6 +920,34 @@ parse_subrip (ParserState * state, const gchar * line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
parse_lrc (ParserState * state, const gchar * line)
|
||||||
|
{
|
||||||
|
gint m, s, c;
|
||||||
|
const gchar *start;
|
||||||
|
gint milli;
|
||||||
|
|
||||||
|
if (line[0] != '[')
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (sscanf (line, "[%u:%02u.%03u]", &m, &s, &c) != 3 &&
|
||||||
|
sscanf (line, "[%u:%02u.%02u]", &m, &s, &c) != 3)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
start = strchr (line, ']');
|
||||||
|
if (start - line == 9)
|
||||||
|
milli = 10;
|
||||||
|
else
|
||||||
|
milli = 1;
|
||||||
|
|
||||||
|
state->start_time = gst_util_uint64_scale (m, 60 * GST_SECOND, 1)
|
||||||
|
+ gst_util_uint64_scale (s, GST_SECOND, 1)
|
||||||
|
+ gst_util_uint64_scale (c, milli * GST_MSECOND, 1);
|
||||||
|
state->duration = GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
|
return g_strdup (start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unescape_newlines_br (gchar * read)
|
unescape_newlines_br (gchar * read)
|
||||||
{
|
{
|
||||||
|
@ -1379,6 +1410,10 @@ gst_sub_parse_format_autodetect (GstSubParse * self)
|
||||||
qttext_context_init (&self->state);
|
qttext_context_init (&self->state);
|
||||||
return gst_caps_new_simple ("text/x-raw",
|
return gst_caps_new_simple ("text/x-raw",
|
||||||
"format", G_TYPE_STRING, "pango-markup", NULL);
|
"format", G_TYPE_STRING, "pango-markup", NULL);
|
||||||
|
case GST_SUB_PARSE_FORMAT_LRC:
|
||||||
|
self->parse_line = parse_lrc;
|
||||||
|
return gst_caps_new_simple ("text/x-raw",
|
||||||
|
"format", G_TYPE_STRING, "utf8", NULL);
|
||||||
case GST_SUB_PARSE_FORMAT_UNKNOWN:
|
case GST_SUB_PARSE_FORMAT_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
GST_DEBUG ("no subtitle format detected");
|
GST_DEBUG ("no subtitle format detected");
|
||||||
|
|
Loading…
Reference in a new issue