| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591, SA1401 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Globalization; |
| | 8 | | using System.Linq; |
| | 9 | | using Jellyfin.Data.Enums; |
| | 10 | | using Jellyfin.Database.Implementations.Entities; |
| | 11 | | using MediaBrowser.Model.Dlna; |
| | 12 | | using MediaBrowser.Model.Drawing; |
| | 13 | | using MediaBrowser.Model.Dto; |
| | 14 | | using MediaBrowser.Model.Entities; |
| | 15 | | using MediaBrowser.Model.MediaInfo; |
| | 16 | | using MediaBrowser.Model.Net; |
| | 17 | | using MediaBrowser.Model.Session; |
| | 18 | |
|
| | 19 | | namespace MediaBrowser.Controller.MediaEncoding |
| | 20 | | { |
| | 21 | | // For now, a common base class until the API and MediaEncoding classes are unified |
| | 22 | | public class EncodingJobInfo |
| | 23 | | { |
| 0 | 24 | | private static readonly char[] _separators = ['|', ',']; |
| | 25 | |
|
| | 26 | | private TranscodeReason? _transcodeReasons = null; |
| | 27 | |
|
| | 28 | | public EncodingJobInfo(TranscodingJobType jobType) |
| | 29 | | { |
| 0 | 30 | | TranscodingType = jobType; |
| 0 | 31 | | RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
| 0 | 32 | | SupportedAudioCodecs = Array.Empty<string>(); |
| 0 | 33 | | SupportedVideoCodecs = Array.Empty<string>(); |
| 0 | 34 | | SupportedSubtitleCodecs = Array.Empty<string>(); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | public int? OutputAudioBitrate { get; set; } |
| | 38 | |
|
| | 39 | | public int? OutputAudioChannels { get; set; } |
| | 40 | |
|
| | 41 | | public TranscodeReason TranscodeReasons |
| | 42 | | { |
| | 43 | | get |
| | 44 | | { |
| 0 | 45 | | if (!_transcodeReasons.HasValue) |
| | 46 | | { |
| 0 | 47 | | if (BaseRequest.TranscodeReasons is null) |
| | 48 | | { |
| 0 | 49 | | _transcodeReasons = 0; |
| 0 | 50 | | return 0; |
| | 51 | | } |
| | 52 | |
|
| 0 | 53 | | _ = Enum.TryParse<TranscodeReason>(BaseRequest.TranscodeReasons, out var reason); |
| 0 | 54 | | _transcodeReasons = reason; |
| | 55 | | } |
| | 56 | |
|
| 0 | 57 | | return _transcodeReasons.Value; |
| | 58 | | } |
| | 59 | | } |
| | 60 | |
|
| | 61 | | public IProgress<double> Progress { get; set; } |
| | 62 | |
|
| | 63 | | public MediaStream VideoStream { get; set; } |
| | 64 | |
|
| | 65 | | public VideoType VideoType { get; set; } |
| | 66 | |
|
| | 67 | | public Dictionary<string, string> RemoteHttpHeaders { get; set; } |
| | 68 | |
|
| | 69 | | public string OutputVideoCodec { get; set; } |
| | 70 | |
|
| | 71 | | public MediaProtocol InputProtocol { get; set; } |
| | 72 | |
|
| | 73 | | public string MediaPath { get; set; } |
| | 74 | |
|
| | 75 | | public bool IsInputVideo { get; set; } |
| | 76 | |
|
| | 77 | | public string OutputAudioCodec { get; set; } |
| | 78 | |
|
| | 79 | | public int? OutputVideoBitrate { get; set; } |
| | 80 | |
|
| | 81 | | public MediaStream SubtitleStream { get; set; } |
| | 82 | |
|
| | 83 | | public SubtitleDeliveryMethod SubtitleDeliveryMethod { get; set; } |
| | 84 | |
|
| | 85 | | public string[] SupportedSubtitleCodecs { get; set; } |
| | 86 | |
|
| | 87 | | public int InternalSubtitleStreamOffset { get; set; } |
| | 88 | |
|
| | 89 | | public MediaSourceInfo MediaSource { get; set; } |
| | 90 | |
|
| | 91 | | public User User { get; set; } |
| | 92 | |
|
| | 93 | | public long? RunTimeTicks { get; set; } |
| | 94 | |
|
| | 95 | | public bool ReadInputAtNativeFramerate { get; set; } |
| | 96 | |
|
| | 97 | | public string OutputFilePath { get; set; } |
| | 98 | |
|
| | 99 | | public string MimeType { get; set; } |
| | 100 | |
|
| 0 | 101 | | public bool IgnoreInputDts => MediaSource.IgnoreDts; |
| | 102 | |
|
| 0 | 103 | | public bool IgnoreInputIndex => MediaSource.IgnoreIndex; |
| | 104 | |
|
| 0 | 105 | | public bool GenPtsInput => MediaSource.GenPtsInput; |
| | 106 | |
|
| 0 | 107 | | public bool DiscardCorruptFramesInput => false; |
| | 108 | |
|
| 0 | 109 | | public bool EnableFastSeekInput => false; |
| | 110 | |
|
| 0 | 111 | | public bool GenPtsOutput => false; |
| | 112 | |
|
| | 113 | | public string OutputContainer { get; set; } |
| | 114 | |
|
| | 115 | | public string OutputVideoSync { get; set; } |
| | 116 | |
|
| | 117 | | public string AlbumCoverPath { get; set; } |
| | 118 | |
|
| | 119 | | public string InputAudioSync { get; set; } |
| | 120 | |
|
| | 121 | | public string InputVideoSync { get; set; } |
| | 122 | |
|
| | 123 | | public TransportStreamTimestamp InputTimestamp { get; set; } |
| | 124 | |
|
| | 125 | | public MediaStream AudioStream { get; set; } |
| | 126 | |
|
| | 127 | | public string[] SupportedAudioCodecs { get; set; } |
| | 128 | |
|
| | 129 | | public string[] SupportedVideoCodecs { get; set; } |
| | 130 | |
|
| | 131 | | public string InputContainer { get; set; } |
| | 132 | |
|
| | 133 | | public IsoType? IsoType { get; set; } |
| | 134 | |
|
| | 135 | | public BaseEncodingJobOptions BaseRequest { get; set; } |
| | 136 | |
|
| | 137 | | public bool IsVideoRequest { get; set; } |
| | 138 | |
|
| | 139 | | public TranscodingJobType TranscodingType { get; set; } |
| | 140 | |
|
| 0 | 141 | | public long? StartTimeTicks => BaseRequest.StartTimeTicks; |
| | 142 | |
|
| 0 | 143 | | public bool CopyTimestamps => BaseRequest.CopyTimestamps; |
| | 144 | |
|
| | 145 | | public bool IsSegmentedLiveStream |
| 0 | 146 | | => TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue; |
| | 147 | |
|
| 0 | 148 | | public int? TotalOutputBitrate => (OutputAudioBitrate ?? 0) + (OutputVideoBitrate ?? 0); |
| | 149 | |
|
| | 150 | | public int? OutputWidth |
| | 151 | | { |
| | 152 | | get |
| | 153 | | { |
| 0 | 154 | | if (VideoStream is not null && VideoStream.Width.HasValue && VideoStream.Height.HasValue) |
| | 155 | | { |
| 0 | 156 | | var size = new ImageDimensions(VideoStream.Width.Value, VideoStream.Height.Value); |
| | 157 | |
|
| 0 | 158 | | var newSize = DrawingUtils.Resize( |
| 0 | 159 | | size, |
| 0 | 160 | | BaseRequest.Width ?? 0, |
| 0 | 161 | | BaseRequest.Height ?? 0, |
| 0 | 162 | | BaseRequest.MaxWidth ?? 0, |
| 0 | 163 | | BaseRequest.MaxHeight ?? 0); |
| | 164 | |
|
| 0 | 165 | | return newSize.Width; |
| | 166 | | } |
| | 167 | |
|
| 0 | 168 | | if (!IsVideoRequest) |
| | 169 | | { |
| 0 | 170 | | return null; |
| | 171 | | } |
| | 172 | |
|
| 0 | 173 | | return BaseRequest.MaxWidth ?? BaseRequest.Width; |
| | 174 | | } |
| | 175 | | } |
| | 176 | |
|
| | 177 | | public int? OutputHeight |
| | 178 | | { |
| | 179 | | get |
| | 180 | | { |
| 0 | 181 | | if (VideoStream is not null && VideoStream.Width.HasValue && VideoStream.Height.HasValue) |
| | 182 | | { |
| 0 | 183 | | var size = new ImageDimensions(VideoStream.Width.Value, VideoStream.Height.Value); |
| | 184 | |
|
| 0 | 185 | | var newSize = DrawingUtils.Resize( |
| 0 | 186 | | size, |
| 0 | 187 | | BaseRequest.Width ?? 0, |
| 0 | 188 | | BaseRequest.Height ?? 0, |
| 0 | 189 | | BaseRequest.MaxWidth ?? 0, |
| 0 | 190 | | BaseRequest.MaxHeight ?? 0); |
| | 191 | |
|
| 0 | 192 | | return newSize.Height; |
| | 193 | | } |
| | 194 | |
|
| 0 | 195 | | if (!IsVideoRequest) |
| | 196 | | { |
| 0 | 197 | | return null; |
| | 198 | | } |
| | 199 | |
|
| 0 | 200 | | return BaseRequest.MaxHeight ?? BaseRequest.Height; |
| | 201 | | } |
| | 202 | | } |
| | 203 | |
|
| | 204 | | public int? OutputAudioSampleRate |
| | 205 | | { |
| | 206 | | get |
| | 207 | | { |
| 0 | 208 | | if (BaseRequest.Static |
| 0 | 209 | | || EncodingHelper.IsCopyCodec(OutputAudioCodec)) |
| | 210 | | { |
| 0 | 211 | | if (AudioStream is not null) |
| | 212 | | { |
| 0 | 213 | | return AudioStream.SampleRate; |
| | 214 | | } |
| | 215 | | } |
| 0 | 216 | | else if (BaseRequest.AudioSampleRate.HasValue) |
| | 217 | | { |
| | 218 | | // Don't exceed what the encoder supports |
| | 219 | | // Seeing issues of attempting to encode to 88200 |
| 0 | 220 | | return BaseRequest.AudioSampleRate.Value; |
| | 221 | | } |
| | 222 | |
|
| 0 | 223 | | return null; |
| | 224 | | } |
| | 225 | | } |
| | 226 | |
|
| | 227 | | public int? OutputAudioBitDepth |
| | 228 | | { |
| | 229 | | get |
| | 230 | | { |
| 0 | 231 | | if (BaseRequest.Static |
| 0 | 232 | | || EncodingHelper.IsCopyCodec(OutputAudioCodec)) |
| | 233 | | { |
| 0 | 234 | | if (AudioStream is not null) |
| | 235 | | { |
| 0 | 236 | | return AudioStream.BitDepth; |
| | 237 | | } |
| | 238 | | } |
| | 239 | |
|
| 0 | 240 | | return null; |
| | 241 | | } |
| | 242 | | } |
| | 243 | |
|
| | 244 | | /// <summary> |
| | 245 | | /// Gets the target video level. |
| | 246 | | /// </summary> |
| | 247 | | public double? TargetVideoLevel |
| | 248 | | { |
| | 249 | | get |
| | 250 | | { |
| 0 | 251 | | if (BaseRequest.Static || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 252 | | { |
| 0 | 253 | | return VideoStream?.Level; |
| | 254 | | } |
| | 255 | |
|
| 0 | 256 | | var level = GetRequestedLevel(ActualOutputVideoCodec); |
| 0 | 257 | | if (double.TryParse(level, CultureInfo.InvariantCulture, out var result)) |
| | 258 | | { |
| 0 | 259 | | return result; |
| | 260 | | } |
| | 261 | |
|
| 0 | 262 | | return null; |
| | 263 | | } |
| | 264 | | } |
| | 265 | |
|
| | 266 | | /// <summary> |
| | 267 | | /// Gets the target video bit depth. |
| | 268 | | /// </summary> |
| | 269 | | public int? TargetVideoBitDepth |
| | 270 | | { |
| | 271 | | get |
| | 272 | | { |
| 0 | 273 | | if (BaseRequest.Static |
| 0 | 274 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 275 | | { |
| 0 | 276 | | return VideoStream?.BitDepth; |
| | 277 | | } |
| | 278 | |
|
| 0 | 279 | | return null; |
| | 280 | | } |
| | 281 | | } |
| | 282 | |
|
| | 283 | | /// <summary> |
| | 284 | | /// Gets the target reference frames. |
| | 285 | | /// </summary> |
| | 286 | | /// <value>The target reference frames.</value> |
| | 287 | | public int? TargetRefFrames |
| | 288 | | { |
| | 289 | | get |
| | 290 | | { |
| 0 | 291 | | if (BaseRequest.Static |
| 0 | 292 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 293 | | { |
| 0 | 294 | | return VideoStream?.RefFrames; |
| | 295 | | } |
| | 296 | |
|
| 0 | 297 | | return null; |
| | 298 | | } |
| | 299 | | } |
| | 300 | |
|
| | 301 | | /// <summary> |
| | 302 | | /// Gets the target framerate. |
| | 303 | | /// </summary> |
| | 304 | | public float? TargetFramerate |
| | 305 | | { |
| | 306 | | get |
| | 307 | | { |
| 0 | 308 | | if (BaseRequest.Static |
| 0 | 309 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 310 | | { |
| 0 | 311 | | return VideoStream?.ReferenceFrameRate; |
| | 312 | | } |
| | 313 | |
|
| 0 | 314 | | return BaseRequest.MaxFramerate ?? BaseRequest.Framerate; |
| | 315 | | } |
| | 316 | | } |
| | 317 | |
|
| | 318 | | public TransportStreamTimestamp TargetTimestamp |
| | 319 | | { |
| | 320 | | get |
| | 321 | | { |
| 0 | 322 | | if (BaseRequest.Static) |
| | 323 | | { |
| 0 | 324 | | return InputTimestamp; |
| | 325 | | } |
| | 326 | |
|
| 0 | 327 | | return string.Equals(OutputContainer, "m2ts", StringComparison.OrdinalIgnoreCase) ? |
| 0 | 328 | | TransportStreamTimestamp.Valid : |
| 0 | 329 | | TransportStreamTimestamp.None; |
| | 330 | | } |
| | 331 | | } |
| | 332 | |
|
| | 333 | | /// <summary> |
| | 334 | | /// Gets the target packet length. |
| | 335 | | /// </summary> |
| | 336 | | public int? TargetPacketLength |
| | 337 | | { |
| | 338 | | get |
| | 339 | | { |
| 0 | 340 | | if (BaseRequest.Static || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 341 | | { |
| 0 | 342 | | return VideoStream?.PacketLength; |
| | 343 | | } |
| | 344 | |
|
| 0 | 345 | | return null; |
| | 346 | | } |
| | 347 | | } |
| | 348 | |
|
| | 349 | | /// <summary> |
| | 350 | | /// Gets the target video profile. |
| | 351 | | /// </summary> |
| | 352 | | public string TargetVideoProfile |
| | 353 | | { |
| | 354 | | get |
| | 355 | | { |
| 0 | 356 | | if (BaseRequest.Static || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 357 | | { |
| 0 | 358 | | return VideoStream?.Profile; |
| | 359 | | } |
| | 360 | |
|
| 0 | 361 | | var requestedProfile = GetRequestedProfiles(ActualOutputVideoCodec).FirstOrDefault(); |
| 0 | 362 | | if (!string.IsNullOrEmpty(requestedProfile)) |
| | 363 | | { |
| 0 | 364 | | return requestedProfile; |
| | 365 | | } |
| | 366 | |
|
| 0 | 367 | | return null; |
| | 368 | | } |
| | 369 | | } |
| | 370 | |
|
| | 371 | | /// <summary> |
| | 372 | | /// Gets the target video range type. |
| | 373 | | /// </summary> |
| | 374 | | public VideoRangeType TargetVideoRangeType |
| | 375 | | { |
| | 376 | | get |
| | 377 | | { |
| 0 | 378 | | if (BaseRequest.Static || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 379 | | { |
| 0 | 380 | | return VideoStream?.VideoRangeType ?? VideoRangeType.Unknown; |
| | 381 | | } |
| | 382 | |
|
| 0 | 383 | | if (Enum.TryParse(GetRequestedRangeTypes(ActualOutputVideoCodec).FirstOrDefault() ?? "Unknown", true, ou |
| | 384 | | { |
| 0 | 385 | | return requestedRangeType; |
| | 386 | | } |
| | 387 | |
|
| 0 | 388 | | return VideoRangeType.Unknown; |
| | 389 | | } |
| | 390 | | } |
| | 391 | |
|
| | 392 | | public string TargetVideoCodecTag |
| | 393 | | { |
| | 394 | | get |
| | 395 | | { |
| 0 | 396 | | if (BaseRequest.Static |
| 0 | 397 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 398 | | { |
| 0 | 399 | | return VideoStream?.CodecTag; |
| | 400 | | } |
| | 401 | |
|
| 0 | 402 | | return null; |
| | 403 | | } |
| | 404 | | } |
| | 405 | |
|
| | 406 | | public bool? IsTargetAnamorphic |
| | 407 | | { |
| | 408 | | get |
| | 409 | | { |
| 0 | 410 | | if (BaseRequest.Static |
| 0 | 411 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 412 | | { |
| 0 | 413 | | return VideoStream?.IsAnamorphic; |
| | 414 | | } |
| | 415 | |
|
| 0 | 416 | | return false; |
| | 417 | | } |
| | 418 | | } |
| | 419 | |
|
| | 420 | | public string ActualOutputVideoCodec |
| | 421 | | { |
| | 422 | | get |
| | 423 | | { |
| 0 | 424 | | if (VideoStream is null) |
| | 425 | | { |
| 0 | 426 | | return null; |
| | 427 | | } |
| | 428 | |
|
| 0 | 429 | | if (EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 430 | | { |
| 0 | 431 | | return VideoStream.Codec; |
| | 432 | | } |
| | 433 | |
|
| 0 | 434 | | return OutputVideoCodec; |
| | 435 | | } |
| | 436 | | } |
| | 437 | |
|
| | 438 | | public string ActualOutputAudioCodec |
| | 439 | | { |
| | 440 | | get |
| | 441 | | { |
| 0 | 442 | | if (AudioStream is null) |
| | 443 | | { |
| 0 | 444 | | return null; |
| | 445 | | } |
| | 446 | |
|
| 0 | 447 | | if (EncodingHelper.IsCopyCodec(OutputAudioCodec)) |
| | 448 | | { |
| 0 | 449 | | return AudioStream.Codec; |
| | 450 | | } |
| | 451 | |
|
| 0 | 452 | | return OutputAudioCodec; |
| | 453 | | } |
| | 454 | | } |
| | 455 | |
|
| | 456 | | public bool? IsTargetInterlaced |
| | 457 | | { |
| | 458 | | get |
| | 459 | | { |
| 0 | 460 | | if (BaseRequest.Static |
| 0 | 461 | | || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 462 | | { |
| 0 | 463 | | return VideoStream?.IsInterlaced; |
| | 464 | | } |
| | 465 | |
|
| 0 | 466 | | if (DeInterlace(ActualOutputVideoCodec, true)) |
| | 467 | | { |
| 0 | 468 | | return false; |
| | 469 | | } |
| | 470 | |
|
| 0 | 471 | | return VideoStream?.IsInterlaced; |
| | 472 | | } |
| | 473 | | } |
| | 474 | |
|
| | 475 | | public bool? IsTargetAVC |
| | 476 | | { |
| | 477 | | get |
| | 478 | | { |
| 0 | 479 | | if (BaseRequest.Static || EncodingHelper.IsCopyCodec(OutputVideoCodec)) |
| | 480 | | { |
| 0 | 481 | | return VideoStream?.IsAVC; |
| | 482 | | } |
| | 483 | |
|
| 0 | 484 | | return false; |
| | 485 | | } |
| | 486 | | } |
| | 487 | |
|
| | 488 | | public int? TargetVideoStreamCount |
| | 489 | | { |
| | 490 | | get |
| | 491 | | { |
| 0 | 492 | | if (BaseRequest.Static) |
| | 493 | | { |
| 0 | 494 | | return GetMediaStreamCount(MediaStreamType.Video, int.MaxValue); |
| | 495 | | } |
| | 496 | |
|
| 0 | 497 | | return GetMediaStreamCount(MediaStreamType.Video, 1); |
| | 498 | | } |
| | 499 | | } |
| | 500 | |
|
| | 501 | | public int? TargetAudioStreamCount |
| | 502 | | { |
| | 503 | | get |
| | 504 | | { |
| 0 | 505 | | if (BaseRequest.Static) |
| | 506 | | { |
| 0 | 507 | | return GetMediaStreamCount(MediaStreamType.Audio, int.MaxValue); |
| | 508 | | } |
| | 509 | |
|
| 0 | 510 | | return GetMediaStreamCount(MediaStreamType.Audio, 1); |
| | 511 | | } |
| | 512 | | } |
| | 513 | |
|
| 0 | 514 | | public bool EnableAudioVbrEncoding => BaseRequest.EnableAudioVbrEncoding; |
| | 515 | |
|
| 0 | 516 | | public int HlsListSize => 0; |
| | 517 | |
|
| | 518 | | public bool EnableBreakOnNonKeyFrames(string videoCodec) |
| | 519 | | { |
| 0 | 520 | | if (TranscodingType != TranscodingJobType.Progressive) |
| | 521 | | { |
| 0 | 522 | | if (IsSegmentedLiveStream) |
| | 523 | | { |
| 0 | 524 | | return false; |
| | 525 | | } |
| | 526 | |
|
| 0 | 527 | | return BaseRequest.BreakOnNonKeyFrames && EncodingHelper.IsCopyCodec(videoCodec); |
| | 528 | | } |
| | 529 | |
|
| 0 | 530 | | return false; |
| | 531 | | } |
| | 532 | |
|
| | 533 | | private int? GetMediaStreamCount(MediaStreamType type, int limit) |
| | 534 | | { |
| 0 | 535 | | var count = MediaSource.GetStreamCount(type); |
| | 536 | |
|
| 0 | 537 | | if (count.HasValue) |
| | 538 | | { |
| 0 | 539 | | count = Math.Min(count.Value, limit); |
| | 540 | | } |
| | 541 | |
|
| 0 | 542 | | return count; |
| | 543 | | } |
| | 544 | |
|
| | 545 | | public string GetMimeType(string outputPath, bool enableStreamDefault = true) |
| | 546 | | { |
| 0 | 547 | | if (!string.IsNullOrEmpty(MimeType)) |
| | 548 | | { |
| 0 | 549 | | return MimeType; |
| | 550 | | } |
| | 551 | |
|
| 0 | 552 | | if (enableStreamDefault) |
| | 553 | | { |
| 0 | 554 | | return MimeTypes.GetMimeType(outputPath); |
| | 555 | | } |
| | 556 | |
|
| 0 | 557 | | return MimeTypes.GetMimeType(outputPath, null); |
| | 558 | | } |
| | 559 | |
|
| | 560 | | public bool DeInterlace(string videoCodec, bool forceDeinterlaceIfSourceIsInterlaced) |
| | 561 | | { |
| 0 | 562 | | var videoStream = VideoStream; |
| 0 | 563 | | var isInputInterlaced = videoStream is not null && videoStream.IsInterlaced; |
| | 564 | |
|
| 0 | 565 | | if (!isInputInterlaced) |
| | 566 | | { |
| 0 | 567 | | return false; |
| | 568 | | } |
| | 569 | |
|
| | 570 | | // Support general param |
| 0 | 571 | | if (BaseRequest.DeInterlace) |
| | 572 | | { |
| 0 | 573 | | return true; |
| | 574 | | } |
| | 575 | |
|
| 0 | 576 | | if (!string.IsNullOrEmpty(videoCodec)) |
| | 577 | | { |
| 0 | 578 | | if (string.Equals(BaseRequest.GetOption(videoCodec, "deinterlace"), "true", StringComparison.OrdinalIgno |
| | 579 | | { |
| 0 | 580 | | return true; |
| | 581 | | } |
| | 582 | | } |
| | 583 | |
|
| 0 | 584 | | return forceDeinterlaceIfSourceIsInterlaced; |
| | 585 | | } |
| | 586 | |
|
| | 587 | | public string[] GetRequestedProfiles(string codec) |
| | 588 | | { |
| 0 | 589 | | if (!string.IsNullOrEmpty(BaseRequest.Profile)) |
| | 590 | | { |
| 0 | 591 | | return BaseRequest.Profile.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 592 | | } |
| | 593 | |
|
| 0 | 594 | | if (!string.IsNullOrEmpty(codec)) |
| | 595 | | { |
| 0 | 596 | | var profile = BaseRequest.GetOption(codec, "profile"); |
| | 597 | |
|
| 0 | 598 | | if (!string.IsNullOrEmpty(profile)) |
| | 599 | | { |
| 0 | 600 | | return profile.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 601 | | } |
| | 602 | | } |
| | 603 | |
|
| 0 | 604 | | return Array.Empty<string>(); |
| | 605 | | } |
| | 606 | |
|
| | 607 | | public string[] GetRequestedRangeTypes(string codec) |
| | 608 | | { |
| 0 | 609 | | if (!string.IsNullOrEmpty(BaseRequest.VideoRangeType)) |
| | 610 | | { |
| 0 | 611 | | return BaseRequest.VideoRangeType.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 612 | | } |
| | 613 | |
|
| 0 | 614 | | if (!string.IsNullOrEmpty(codec)) |
| | 615 | | { |
| 0 | 616 | | var rangetype = BaseRequest.GetOption(codec, "rangetype"); |
| | 617 | |
|
| 0 | 618 | | if (!string.IsNullOrEmpty(rangetype)) |
| | 619 | | { |
| 0 | 620 | | return rangetype.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 621 | | } |
| | 622 | | } |
| | 623 | |
|
| 0 | 624 | | return Array.Empty<string>(); |
| | 625 | | } |
| | 626 | |
|
| | 627 | | public string[] GetRequestedCodecTags(string codec) |
| | 628 | | { |
| 0 | 629 | | if (!string.IsNullOrEmpty(BaseRequest.CodecTag)) |
| | 630 | | { |
| 0 | 631 | | return BaseRequest.CodecTag.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 632 | | } |
| | 633 | |
|
| 0 | 634 | | if (!string.IsNullOrEmpty(codec)) |
| | 635 | | { |
| 0 | 636 | | var codectag = BaseRequest.GetOption(codec, "codectag"); |
| | 637 | |
|
| 0 | 638 | | if (!string.IsNullOrEmpty(codectag)) |
| | 639 | | { |
| 0 | 640 | | return codectag.Split(_separators, StringSplitOptions.RemoveEmptyEntries); |
| | 641 | | } |
| | 642 | | } |
| | 643 | |
|
| 0 | 644 | | return Array.Empty<string>(); |
| | 645 | | } |
| | 646 | |
|
| | 647 | | public string GetRequestedLevel(string codec) |
| | 648 | | { |
| 0 | 649 | | if (!string.IsNullOrEmpty(BaseRequest.Level)) |
| | 650 | | { |
| 0 | 651 | | return BaseRequest.Level; |
| | 652 | | } |
| | 653 | |
|
| 0 | 654 | | if (!string.IsNullOrEmpty(codec)) |
| | 655 | | { |
| 0 | 656 | | return BaseRequest.GetOption(codec, "level"); |
| | 657 | | } |
| | 658 | |
|
| 0 | 659 | | return null; |
| | 660 | | } |
| | 661 | |
|
| | 662 | | public int? GetRequestedMaxRefFrames(string codec) |
| | 663 | | { |
| 0 | 664 | | if (BaseRequest.MaxRefFrames.HasValue) |
| | 665 | | { |
| 0 | 666 | | return BaseRequest.MaxRefFrames; |
| | 667 | | } |
| | 668 | |
|
| 0 | 669 | | if (!string.IsNullOrEmpty(codec)) |
| | 670 | | { |
| 0 | 671 | | var value = BaseRequest.GetOption(codec, "maxrefframes"); |
| 0 | 672 | | if (int.TryParse(value, CultureInfo.InvariantCulture, out var result)) |
| | 673 | | { |
| 0 | 674 | | return result; |
| | 675 | | } |
| | 676 | | } |
| | 677 | |
|
| 0 | 678 | | return null; |
| | 679 | | } |
| | 680 | |
|
| | 681 | | public int? GetRequestedVideoBitDepth(string codec) |
| | 682 | | { |
| 0 | 683 | | if (BaseRequest.MaxVideoBitDepth.HasValue) |
| | 684 | | { |
| 0 | 685 | | return BaseRequest.MaxVideoBitDepth; |
| | 686 | | } |
| | 687 | |
|
| 0 | 688 | | if (!string.IsNullOrEmpty(codec)) |
| | 689 | | { |
| 0 | 690 | | var value = BaseRequest.GetOption(codec, "videobitdepth"); |
| 0 | 691 | | if (int.TryParse(value, CultureInfo.InvariantCulture, out var result)) |
| | 692 | | { |
| 0 | 693 | | return result; |
| | 694 | | } |
| | 695 | | } |
| | 696 | |
|
| 0 | 697 | | return null; |
| | 698 | | } |
| | 699 | |
|
| | 700 | | public int? GetRequestedAudioBitDepth(string codec) |
| | 701 | | { |
| 0 | 702 | | if (BaseRequest.MaxAudioBitDepth.HasValue) |
| | 703 | | { |
| 0 | 704 | | return BaseRequest.MaxAudioBitDepth; |
| | 705 | | } |
| | 706 | |
|
| 0 | 707 | | if (!string.IsNullOrEmpty(codec)) |
| | 708 | | { |
| 0 | 709 | | var value = BaseRequest.GetOption(codec, "audiobitdepth"); |
| 0 | 710 | | if (int.TryParse(value, CultureInfo.InvariantCulture, out var result)) |
| | 711 | | { |
| 0 | 712 | | return result; |
| | 713 | | } |
| | 714 | | } |
| | 715 | |
|
| 0 | 716 | | return null; |
| | 717 | | } |
| | 718 | |
|
| | 719 | | public int? GetRequestedAudioChannels(string codec) |
| | 720 | | { |
| 0 | 721 | | if (!string.IsNullOrEmpty(codec)) |
| | 722 | | { |
| 0 | 723 | | var value = BaseRequest.GetOption(codec, "audiochannels"); |
| 0 | 724 | | if (int.TryParse(value, CultureInfo.InvariantCulture, out var result)) |
| | 725 | | { |
| 0 | 726 | | return result; |
| | 727 | | } |
| | 728 | | } |
| | 729 | |
|
| 0 | 730 | | if (BaseRequest.MaxAudioChannels.HasValue) |
| | 731 | | { |
| 0 | 732 | | return BaseRequest.MaxAudioChannels; |
| | 733 | | } |
| | 734 | |
|
| 0 | 735 | | if (BaseRequest.AudioChannels.HasValue) |
| | 736 | | { |
| 0 | 737 | | return BaseRequest.AudioChannels; |
| | 738 | | } |
| | 739 | |
|
| 0 | 740 | | if (BaseRequest.TranscodingMaxAudioChannels.HasValue) |
| | 741 | | { |
| 0 | 742 | | return BaseRequest.TranscodingMaxAudioChannels; |
| | 743 | | } |
| | 744 | |
|
| 0 | 745 | | return null; |
| | 746 | | } |
| | 747 | |
|
| | 748 | | public virtual void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentCo |
| | 749 | | { |
| 0 | 750 | | Progress.Report(percentComplete.Value); |
| 0 | 751 | | } |
| | 752 | | } |
| | 753 | | } |