ソースを参照

fix the UTF-16 error while burning ass/ssa subtitles

nyanmisaka 5 年 前
コミット
0af353404c

+ 3 - 1
MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs

@@ -946,7 +946,7 @@ namespace MediaBrowser.Api.Playback.Hls
                     gopArg = string.Format(
                     gopArg = string.Format(
                         CultureInfo.InvariantCulture,
                         CultureInfo.InvariantCulture,
                         " -g {0} -keyint_min {0} -sc_threshold 0",
                         " -g {0} -keyint_min {0} -sc_threshold 0",
-                        state.SegmentLength * Math.Ceiling(Convert.ToDecimal(framerate))
+                        Math.Ceiling(state.SegmentLength * framerate.Value)
                     );
                     );
                 }
                 }
 
 
@@ -980,6 +980,8 @@ namespace MediaBrowser.Api.Playback.Hls
                     args += EncodingHelper.GetGraphicalSubtitleParam(state, encodingOptions, codec);
                     args += EncodingHelper.GetGraphicalSubtitleParam(state, encodingOptions, codec);
                 }
                 }
 
 
+                // -start_at_zero is necessary to use with -ss when seeking,
+                // otherwise the target position cannot be determined.
                 if (!(state.SubtitleStream != null && state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream))
                 if (!(state.SubtitleStream != null && state.SubtitleStream.IsExternal && !state.SubtitleStream.IsTextSubtitleStream))
                 {
                 {
                     args += " -start_at_zero";
                     args += " -start_at_zero";

+ 8 - 0
MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs

@@ -730,6 +730,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
             {
             {
                 var charset = CharsetDetector.DetectFromStream(stream).Detected?.EncodingName;
                 var charset = CharsetDetector.DetectFromStream(stream).Detected?.EncodingName;
 
 
+                // UTF16 is automatically converted to UTF8 by FFmpeg, do not specify a character encoding
+                if ((path.EndsWith(".ass") || path.EndsWith(".ssa"))
+                    && (string.Equals(charset, "utf-16le", StringComparison.OrdinalIgnoreCase)
+                        || string.Equals(charset, "utf-16be", StringComparison.OrdinalIgnoreCase)))
+                {
+                    charset = "";
+                }
+
                 _logger.LogDebug("charset {0} detected for {Path}", charset ?? "null", path);
                 _logger.LogDebug("charset {0} detected for {Path}", charset ?? "null", path);
 
 
                 return charset;
                 return charset;