https://bugs.kde.org/show_bug.cgi?id=526408

            Bug ID: 526408
           Summary: Subtitle files written without explicit UTF-8
                    encoding, corrupts non-Latin text on Windows
    Classification: Applications
           Product: kdenlive
      Version First git-master
       Reported In:
          Platform: Microsoft Windows
                OS: Microsoft Windows
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Rendering & Export
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 196672
  --> https://bugs.kde.org/attachment.cgi?id=196672&action=edit
Image is showing how a text in Editor (how it should be) and how it on video
(after render)

In SubtitleModel::saveSubtitleData() (subtitlemodel.cpp, ~line 1280),
subtitle data is written using:

    QTextStream out(&outF);

No encoding is set on the QTextStream. On Linux this defaults to UTF-8
(because the locale is usually UTF-8), but on Windows it defaults to the
system codepage (e.g. CP1252 for Western European locales). This means
that subtitle text containing Sinhala, Arabic, Chinese, or any non-Latin
Unicode characters is silently corrupted in the output .ass / .srt file
on Windows.

This is an asymmetry: the import side (importSubtitle(), ~lines 237-239
and 305-308) already calls stream.setEncoding(inputEncoding.value())
correctly, but the write side does not.

Proposed fix (one line):
    QTextStream out(&outF);
    out.setEncoding(QStringConverter::Utf8);  // add this line

This matches the import side and guarantees that all subtitle files
written by Kdenlive are valid UTF-8, which is what libass/FFmpeg expects.

Additionally, it would be useful to expose the av.fontsdir parameter
of the avfilter.subtitles MLT filter in the SubtitleStyleEdit dialog.
This would allow users to specify a directory of fonts (e.g. Noto Sans
Sinhala) for libass to use when the subtitle font is not installed
system-wide. libass already uses HarfBuzz for correct complex script
shaping — the only missing piece is font discovery.

Reproducible on Windows:
1. Create a subtitle with Sinhala text: ආයුබෝවන්
2. Save the project and inspect the .ass file with a hex editor.
3. On Windows with a non-UTF-8 system codepage, the Sinhala bytes
   will be wrongly encoded.

Version: master (fd2da39516)
OS: Primarily Windows; Linux unaffected due to default UTF-8 locale

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to