jellyfin / jellyfin-plugin-dlna

GNU General Public License v3.0
24 stars 13 forks source link

[Issue]: UTF-8 subtitle encoding not supported on old DLNA device. #72

Open nestingBiscuit opened 5 months ago

nestingBiscuit commented 5 months ago

Please describe your bug

I have an older Samsung TV and it does not allow me to select UTF-8 as the subtitle encoding. It only has ISO-8859-X encodings to choose from.

Since Jellyfin always converts subtitle files to UTF-8, the decoding on the TV gets jumbled for special characters like 'é'. (See the images below)

After extensive testing, I have found that the TV does decode UTF-8 with BOM correctly.

It would be preferable if I were able to set the text encoding in the DLNA profile, but I do not have the expertise to tackle such a change. I have suggested it as a feature.

I was able to fix the issue by changing the subtitle encoding in:

https://github.com/jellyfin/jellyfin/blob/31aa44d23d12b5dbb5f9a131242cc82c9ef98f24/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs#L186

to UTF-8 with BOM:

// Create a UTF-8 encoding that supports a BOM.
Encoding utf8 = new UTF8Encoding(true);
byte[] utfBOM = [.. utf8.GetPreamble(), .. utf8.GetBytes(text)];
return new MemoryStream(utfBOM);

I have tested this change with the few DLNA devices I own and they all show subtitles as expected. (Including the old Samsung TV)

I would be happy to make a pull request if this fix is deemed appropriate.

Reproduction Steps

Play a video with an external subtitle file that includes special characters, on a device that does not support UTF-8. I used this srt to test..

Jellyfin Version

10.9.0

if other:

10.9.6

Environment

- OS: macOS
- Clients: DLNA / web client
- Browser: Firefox
- Playback Method: Direct
- Hardware Acceleration:
- Plugins: DLNA

Jellyfin logs

[12:31:49] [INF] [1] Main: Startup complete 0:00:02.5552437
[12:31:51] [INF] [9] Emby.Server.Implementations.ScheduledTasks.TaskManager: Clean up collections and playlists Completed after 0 minute(s) and 0 seconds
[12:31:52] [INF] [9] Emby.Server.Implementations.ScheduledTasks.TaskManager: Update Plugins Completed after 0 minute(s) and 0 seconds
[12:31:53] [INF] [10] Jellyfin.Plugin.Dlna.Main.DlnaHost: DLNA Session created for [TV]Samsung LED40 - UE40H6410

FFmpeg logs

No response

Please attach any browser or client logs here

No response

Please attach any screenshots here

UTF-8 error decoding: UTF-8 error decoding UTF-8-BOM correct decoding: UTF-8-BOM correct decoding

Code of Conduct

jellyfin-bot commented 5 months ago

Hi, it seems like your issue report has the following item(s) that need to be addressed:

This is an automated message, currently under testing. Please file an issue here if you encounter any problems.

nestingBiscuit commented 5 months ago

I did file using the template, but I may have made an edit that triggered the bot :)