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