mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
using System.Runtime.InteropServices; |
|
|
|
namespace ErsatzTV.FFmpeg.Filter; |
|
|
|
public class SubtitlesFilter : BaseFilter |
|
{ |
|
private readonly string _fontsDir; |
|
private readonly SubtitleInputFile _subtitleInputFile; |
|
|
|
public SubtitlesFilter(string fontsDir, SubtitleInputFile subtitleInputFile) |
|
{ |
|
_fontsDir = fontsDir; |
|
_subtitleInputFile = subtitleInputFile; |
|
} |
|
|
|
public override string Filter |
|
{ |
|
get |
|
{ |
|
string fontsDir = _fontsDir; |
|
string effectiveFile = _subtitleInputFile.Path; |
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
|
{ |
|
fontsDir = fontsDir |
|
.Replace(@"\", @"/\") |
|
.Replace(@":/", @"\\:/"); |
|
|
|
effectiveFile = effectiveFile |
|
.Replace(@"\", @"/\"); |
|
|
|
if (!effectiveFile.StartsWith("http", StringComparison.OrdinalIgnoreCase)) |
|
{ |
|
effectiveFile = effectiveFile.Replace(@":/", @"\\:/"); |
|
} |
|
} |
|
|
|
// escape brackets after escaping for windows |
|
effectiveFile = effectiveFile |
|
.Replace(@"[", @"\[") |
|
.Replace(@"]", @"\]") |
|
.Replace(@"http://localhost:", @"http\\://localhost\\:"); |
|
|
|
return $"subtitles={effectiveFile}:fontsdir={fontsDir}"; |
|
} |
|
} |
|
|
|
public override FrameState NextState(FrameState currentState) => |
|
currentState with { FrameDataLocation = FrameDataLocation.Software }; |
|
}
|
|
|