Skip to content

Commit

Permalink
[WEBVTT] Fix missing text alignment tags from output
Browse files Browse the repository at this point in the history
Legacy players, e.g. older versions of ExoPlayer, do not handle default webvtt text alignment correctly. Need to specify `align:center` explicitly cues without text alignment for backwards compatibility.

Fixes shaka-project#925.
  • Loading branch information
vish91 authored May 5, 2021
1 parent 37b16b4 commit d9124d6
Show file tree
Hide file tree
Showing 61 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</AdaptationSet>
<AdaptationSet id="2" contentType="text" subsegmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="caption"/>
<Representation id="2" bandwidth="273" mimeType="text/vtt">
<Representation id="2" bandwidth="317" mimeType="text/vtt">
<BaseURL>bear-english-text.vtt</BaseURL>
</Representation>
</AdaptationSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</AdaptationSet>
<AdaptationSet id="2" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="2" bandwidth="2056" codecs="wvtt" mimeType="application/mp4">
<Representation id="2" bandwidth="2216" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="4"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packager/app/test/testdata/segmented-webvtt-mp4/output.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Period id="0" start="PT0S">
<AdaptationSet id="0" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="2056" codecs="wvtt" mimeType="application/mp4">
<Representation id="0" bandwidth="2216" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="4"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Period id="0" start="PT0S">
<AdaptationSet id="0" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="1216" mimeType="text/vtt">
<Representation id="0" bandwidth="1320" mimeType="text/vtt">
<SegmentTemplate timescale="1000" media="bear-english-text-$Number$.vtt" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="4"/>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Period id="0" start="PT0S">
<AdaptationSet id="0" contentType="text" lang="pt" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="2056" codecs="wvtt" mimeType="application/mp4">
<Representation id="0" bandwidth="2216" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="4"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:9000
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Period id="0">
<AdaptationSet id="0" contentType="text" subsegmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="353" mimeType="text/vtt">
<Representation id="0" bandwidth="397" mimeType="text/vtt">
<BaseURL>bear-english-text.vtt</BaseURL>
</Representation>
</AdaptationSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ WEBVTT
STYLE
::cue { color:lime }
00:00:00.000 --> 00:00:00.800
00:00:00.000 --> 00:00:00.800 align:center
Yup, that's a bear, eh.

00:00:01.000 --> 00:00:04.700
00:00:01.000 --> 00:00:04.700 align:center
He 's... um... doing bear-like stuff.

2 changes: 1 addition & 1 deletion packager/app/test/testdata/video-audio-webvtt/output.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</AdaptationSet>
<AdaptationSet id="2" contentType="text" subsegmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="2" bandwidth="273" mimeType="text/vtt">
<Representation id="2" bandwidth="317" mimeType="text/vtt">
<BaseURL>bear-english-text.vtt</BaseURL>
</Representation>
</AdaptationSet>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</AdaptationSet>
<AdaptationSet id="2" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="2" bandwidth="1944" codecs="wvtt" mimeType="application/mp4">
<Representation id="2" bandwidth="2104" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="1"/>
Expand Down Expand Up @@ -56,7 +56,7 @@
</AdaptationSet>
<AdaptationSet id="2" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="2" bandwidth="2056" codecs="wvtt" mimeType="application/mp4">
<Representation id="2" bandwidth="2216" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" presentationTimeOffset="2001" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="4">
<SegmentTimeline>
<S t="2001" d="1000" r="2"/>
Expand Down
8 changes: 4 additions & 4 deletions packager/media/formats/webvtt/webvtt_muxer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEST_F(WebVttMuxerTest, WithOneSegmentAndWithOneSample) {
const char* kExpectedOutput =
"WEBVTT\n"
"\n"
"00:00:05.000 --> 00:00:06.000\n"
"00:00:05.000 --> 00:00:06.000 align:center\n"
"payload\n"
"\n";

Expand Down Expand Up @@ -122,14 +122,14 @@ TEST_F(WebVttMuxerTest, WithTwoSegmentAndWithOneSample) {
const char* kExpectedOutput1 =
"WEBVTT\n"
"\n"
"00:00:05.000 --> 00:00:06.000\n"
"00:00:05.000 --> 00:00:06.000 align:center\n"
"payload 1\n"
"\n";

const char* kExpectedOutput2 =
"WEBVTT\n"
"\n"
"00:00:15.000 --> 00:00:16.000\n"
"00:00:15.000 --> 00:00:16.000 align:center\n"
"payload 2\n"
"\n";

Expand Down Expand Up @@ -189,7 +189,7 @@ TEST_F(WebVttMuxerTest, WithAnEmptySegment) {
const char* kExpectedOutput2 =
"WEBVTT\n"
"\n"
"00:00:15.000 --> 00:00:16.000\n"
"00:00:15.000 --> 00:00:16.000 align:center\n"
"payload 2\n"
"\n";

Expand Down
1 change: 1 addition & 0 deletions packager/media/formats/webvtt/webvtt_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ std::string WebVttSettingsToString(const TextSettings& settings) {
ret += " align:right";
break;
case TextAlignment::kCenter:
ret += " align:center";
break;
}

Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/webvtt/webvtt_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ TEST(WebVttUtilsTest, SettingsToString) {
TEST(WebVttUtilsTest, SettingsToString_IgnoresDefaults) {
TextSettings settings;
settings.region = "foo";
settings.text_alignment = TextAlignment::kCenter;

const auto actual = WebVttSettingsToString(settings);
EXPECT_EQ(actual, "region:foo");
EXPECT_EQ(actual, "region:foo align:center");
}

TEST(WebVttUtilsTest, FragmentToString) {
Expand Down

0 comments on commit d9124d6

Please sign in to comment.