Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/main/python/ttconv/scc/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,22 @@ def _isd_progress(progress: float):
if len(captions) > 0 and captions[-1].get_end() is None:
captions[-1].set_end(begin)

if len(isd) == 0:
non_empty_region_cnt = 0
for r in isd.iter_regions():
if len(r) > 0:
non_empty_region_cnt += 1
if non_empty_region_cnt > 1:
# SCC can only handle one region at a time
LOGGER.warning("Merging multiple regions at %ss; errors may result", float(begin))
break

if non_empty_region_cnt == 0:
# skip empty ISD
is_last_empty = True
continue

is_last_empty = False

# SCC can only handle one region at a time
if len(isd) > 1:
LOGGER.warning("Merging multiple regions exist at %ss; errors may result", float(begin))
continue

caption: _Caption = _Caption.from_regions(list(isd.iter_regions()))
caption.set_begin(begin)

Expand Down
32 changes: 32 additions & 0 deletions src/test/python/test_scc_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,37 @@ def test_basic_30FPS(self):
scc_from_model = scc_writer.from_model(model, config)
self.assertEqual(scc_from_model, expected_scc)

def test_multi_regions(self):
expected_scc="""Scenarist_SCC V1.0

00:00:00;22 9420 9420 94ae 94ae 9440 9440 6180 942f 942f

00:00:01;29 942c 942c

00:00:02;22 9420 9420 94ae 94ae 9440 9440 6280 942f 942f

00:00:03;29 942c 942c"""

SAMPLE = """<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="en">
<head>
<layout>
<region xml:id="r_a" tts:origin="0% 0%" tts:extent="50% 50%" />
<region xml:id="r_b" tts:origin="50% 50%" tts:extent="50% 50%" />
</layout>
</head>
<body>
<div>
<p region="r_a" begin="00:00:01.000" end="00:00:02.000">a</p>
<p region="r_b" begin="00:00:03.000" end="00:00:04.000">b</p>
</div>
</body>
</tt>

"""

model = imsc_reader.to_model(et.ElementTree(et.fromstring(SAMPLE)))
scc_from_model = scc_writer.from_model(model)
self.assertEqual(scc_from_model, expected_scc)

if __name__ == '__main__':
unittest.main()