1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Emby.Server.Implementations;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Migrations.PreStartupRoutines;
/// <inheritdoc />
#pragma warning disable CS0618 // Type or member is obsolete
[JellyfinMigration("2025-04-20T03:00:00", nameof(MigrateEncodingOptions), "A8E61960-7726-4450-8F3D-82C12DAABBCB", Stage = Stages.JellyfinMigrationStageTypes.PreInitialisation)]
public class MigrateEncodingOptions : IMigrationRoutine
#pragma warning restore CS0618 // Type or member is obsolete
{
private readonly ServerApplicationPaths _applicationPaths;
private readonly ILogger<MigrateEncodingOptions> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="MigrateEncodingOptions"/> class.
/// </summary>
/// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
/// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
public MigrateEncodingOptions(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
{
_applicationPaths = applicationPaths;
_logger = loggerFactory.CreateLogger<MigrateEncodingOptions>();
}
/// <inheritdoc />
public void Perform()
{
string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "encoding.xml");
var oldSerializer = new XmlSerializer(typeof(OldEncodingOptions), new XmlRootAttribute("EncodingOptions"));
OldEncodingOptions? oldConfig = null;
try
{
using var xmlReader = XmlReader.Create(path);
oldConfig = (OldEncodingOptions?)oldSerializer.Deserialize(xmlReader);
}
catch (InvalidOperationException ex)
{
_logger.LogError(ex, "Migrate EncodingOptions deserialize Invalid Operation error");
}
catch (Exception ex)
{
_logger.LogError(ex, "Migrate EncodingOptions deserialize error");
}
if (oldConfig is null)
{
return;
}
var hardwareAccelerationType = HardwareAccelerationType.none;
if (Enum.TryParse<HardwareAccelerationType>(oldConfig.HardwareAccelerationType, true, out var parsedHardwareAccelerationType))
{
hardwareAccelerationType = parsedHardwareAccelerationType;
}
var tonemappingAlgorithm = TonemappingAlgorithm.none;
if (Enum.TryParse<TonemappingAlgorithm>(oldConfig.TonemappingAlgorithm, true, out var parsedTonemappingAlgorithm))
{
tonemappingAlgorithm = parsedTonemappingAlgorithm;
}
var tonemappingMode = TonemappingMode.auto;
if (Enum.TryParse<TonemappingMode>(oldConfig.TonemappingMode, true, out var parsedTonemappingMode))
{
tonemappingMode = parsedTonemappingMode;
}
var tonemappingRange = TonemappingRange.auto;
if (Enum.TryParse<TonemappingRange>(oldConfig.TonemappingRange, true, out var parsedTonemappingRange))
{
tonemappingRange = parsedTonemappingRange;
}
var encoderPreset = EncoderPreset.superfast;
if (Enum.TryParse<EncoderPreset>(oldConfig.TonemappingRange, true, out var parsedEncoderPreset))
{
encoderPreset = parsedEncoderPreset;
}
var deinterlaceMethod = DeinterlaceMethod.yadif;
if (Enum.TryParse<DeinterlaceMethod>(oldConfig.TonemappingRange, true, out var parsedDeinterlaceMethod))
{
deinterlaceMethod = parsedDeinterlaceMethod;
}
var encodingOptions = new EncodingOptions()
{
EncodingThreadCount = oldConfig.EncodingThreadCount,
TranscodingTempPath = oldConfig.TranscodingTempPath,
FallbackFontPath = oldConfig.FallbackFontPath,
EnableFallbackFont = oldConfig.EnableFallbackFont,
EnableAudioVbr = oldConfig.EnableAudioVbr,
DownMixAudioBoost = oldConfig.DownMixAudioBoost,
DownMixStereoAlgorithm = oldConfig.DownMixStereoAlgorithm,
MaxMuxingQueueSize = oldConfig.MaxMuxingQueueSize,
EnableThrottling = oldConfig.EnableThrottling,
ThrottleDelaySeconds = oldConfig.ThrottleDelaySeconds,
EnableSegmentDeletion = oldConfig.EnableSegmentDeletion,
SegmentKeepSeconds = oldConfig.SegmentKeepSeconds,
HardwareAccelerationType = hardwareAccelerationType,
EncoderAppPath = oldConfig.EncoderAppPath,
EncoderAppPathDisplay = oldConfig.EncoderAppPathDisplay,
VaapiDevice = oldConfig.VaapiDevice,
EnableTonemapping = oldConfig.EnableTonemapping,
EnableVppTonemapping = oldConfig.EnableVppTonemapping,
EnableVideoToolboxTonemapping = oldConfig.EnableVideoToolboxTonemapping,
TonemappingAlgorithm = tonemappingAlgorithm,
TonemappingMode = tonemappingMode,
TonemappingRange = tonemappingRange,
TonemappingDesat = oldConfig.TonemappingDesat,
TonemappingPeak = oldConfig.TonemappingPeak,
TonemappingParam = oldConfig.TonemappingParam,
VppTonemappingBrightness = oldConfig.VppTonemappingBrightness,
VppTonemappingContrast = oldConfig.VppTonemappingContrast,
H264Crf = oldConfig.H264Crf,
H265Crf = oldConfig.H265Crf,
EncoderPreset = encoderPreset,
DeinterlaceDoubleRate = oldConfig.DeinterlaceDoubleRate,
DeinterlaceMethod = deinterlaceMethod,
EnableDecodingColorDepth10Hevc = oldConfig.EnableDecodingColorDepth10Hevc,
EnableDecodingColorDepth10Vp9 = oldConfig.EnableDecodingColorDepth10Vp9,
EnableEnhancedNvdecDecoder = oldConfig.EnableEnhancedNvdecDecoder,
PreferSystemNativeHwDecoder = oldConfig.PreferSystemNativeHwDecoder,
EnableIntelLowPowerH264HwEncoder = oldConfig.EnableIntelLowPowerH264HwEncoder,
EnableIntelLowPowerHevcHwEncoder = oldConfig.EnableIntelLowPowerHevcHwEncoder,
EnableHardwareEncoding = oldConfig.EnableHardwareEncoding,
AllowHevcEncoding = oldConfig.AllowHevcEncoding,
AllowAv1Encoding = oldConfig.AllowAv1Encoding,
EnableSubtitleExtraction = oldConfig.EnableSubtitleExtraction,
HardwareDecodingCodecs = oldConfig.HardwareDecodingCodecs,
AllowOnDemandMetadataBasedKeyframeExtractionForExtensions = oldConfig.AllowOnDemandMetadataBasedKeyframeExtractionForExtensions
};
var newSerializer = new XmlSerializer(typeof(EncodingOptions));
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
newSerializer.Serialize(xmlWriter, encodingOptions);
}
#pragma warning disable
public sealed class OldEncodingOptions
{
public int EncodingThreadCount { get; set; }
public string TranscodingTempPath { get; set; }
public string FallbackFontPath { get; set; }
public bool EnableFallbackFont { get; set; }
public bool EnableAudioVbr { get; set; }
public double DownMixAudioBoost { get; set; }
public DownMixStereoAlgorithms DownMixStereoAlgorithm { get; set; }
public int MaxMuxingQueueSize { get; set; }
public bool EnableThrottling { get; set; }
public int ThrottleDelaySeconds { get; set; }
public bool EnableSegmentDeletion { get; set; }
public int SegmentKeepSeconds { get; set; }
public string HardwareAccelerationType { get; set; }
public string EncoderAppPath { get; set; }
public string EncoderAppPathDisplay { get; set; }
public string VaapiDevice { get; set; }
public bool EnableTonemapping { get; set; }
public bool EnableVppTonemapping { get; set; }
public bool EnableVideoToolboxTonemapping { get; set; }
public string TonemappingAlgorithm { get; set; }
public string TonemappingMode { get; set; }
public string TonemappingRange { get; set; }
public double TonemappingDesat { get; set; }
public double TonemappingPeak { get; set; }
public double TonemappingParam { get; set; }
public double VppTonemappingBrightness { get; set; }
public double VppTonemappingContrast { get; set; }
public int H264Crf { get; set; }
public int H265Crf { get; set; }
public string EncoderPreset { get; set; }
public bool DeinterlaceDoubleRate { get; set; }
public string DeinterlaceMethod { get; set; }
public bool EnableDecodingColorDepth10Hevc { get; set; }
public bool EnableDecodingColorDepth10Vp9 { get; set; }
public bool EnableEnhancedNvdecDecoder { get; set; }
public bool PreferSystemNativeHwDecoder { get; set; }
public bool EnableIntelLowPowerH264HwEncoder { get; set; }
public bool EnableIntelLowPowerHevcHwEncoder { get; set; }
public bool EnableHardwareEncoding { get; set; }
public bool AllowHevcEncoding { get; set; }
public bool AllowAv1Encoding { get; set; }
public bool EnableSubtitleExtraction { get; set; }
public string[] HardwareDecodingCodecs { get; set; }
public string[] AllowOnDemandMetadataBasedKeyframeExtractionForExtensions { get; set; }
}
}
|