Skip to content

Commit d49f573

Browse files
jbreeWyattBlue
authored andcommitted
Fix subtitle UTF-8 handling
1 parent 6d968c9 commit d49f573

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

av/subtitles/subtitle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def dialogue(self):
297297
i: cython.Py_ssize_t = 0
298298
state: cython.bint = False
299299
ass_text: bytes = self.ass
300-
char, next_char = cython.declare(cython.char)
300+
char, next_char = cython.declare(cython.uchar)
301301
result: bytearray = bytearray()
302302
text_len: cython.Py_ssize_t = len(ass_text)
303303

tests/test_subtitles.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ def test_subtitle_set_create(self) -> None:
119119
assert len(subtitle) == 1
120120
assert cast(AssSubtitle, subtitle[0]).ass == text
121121

122+
def test_subtitle_dialogue_extended_chars(self) -> None:
123+
"""Test handling of extended UTF-8 characters in subtitle dialogue."""
124+
from av.subtitles.subtitle import SubtitleSet
125+
126+
text = "0,0,Default,,0,0,0,,♪ Hey, hey, hey ♪".encode("utf-8")
127+
subtitle = SubtitleSet.create(text=text, start=0, end=2000, pts=0)
128+
sub = cast(AssSubtitle, subtitle[0])
129+
130+
assert sub.dialogue == "♪ Hey, hey, hey ♪".encode("utf-8")
131+
122132
def test_subtitle_encode_mp4(self) -> None:
123133
"""Test encoding subtitles to MP4 container."""
124134
from av.subtitles.subtitle import SubtitleSet

0 commit comments

Comments
 (0)