| | 1 | | #nullable disable |
| | 2 | | #pragma warning disable CS1591 |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Frozen; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.ComponentModel; |
| | 8 | | using System.Globalization; |
| | 9 | | using System.Linq; |
| | 10 | | using System.Text; |
| | 11 | | using System.Text.Json.Serialization; |
| | 12 | | using Jellyfin.Data.Enums; |
| | 13 | | using Jellyfin.Extensions; |
| | 14 | | using MediaBrowser.Model.Dlna; |
| | 15 | | using MediaBrowser.Model.Extensions; |
| | 16 | | using MediaBrowser.Model.MediaInfo; |
| | 17 | |
|
| | 18 | | namespace MediaBrowser.Model.Entities |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Class MediaStream. |
| | 22 | | /// </summary> |
| | 23 | | public class MediaStream |
| | 24 | | { |
| 1 | 25 | | private static readonly string[] _specialCodes = |
| 1 | 26 | | { |
| 1 | 27 | | // Uncoded languages. |
| 1 | 28 | | "mis", |
| 1 | 29 | | // Multiple languages. |
| 1 | 30 | | "mul", |
| 1 | 31 | | // Undetermined. |
| 1 | 32 | | "und", |
| 1 | 33 | | // No linguistic content; not applicable. |
| 1 | 34 | | "zxx" |
| 1 | 35 | | }; |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Gets or sets the codec. |
| | 39 | | /// </summary> |
| | 40 | | /// <value>The codec.</value> |
| | 41 | | public string Codec { get; set; } |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Gets or sets the codec tag. |
| | 45 | | /// </summary> |
| | 46 | | /// <value>The codec tag.</value> |
| | 47 | | public string CodecTag { get; set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets or sets the language. |
| | 51 | | /// </summary> |
| | 52 | | /// <value>The language.</value> |
| | 53 | | public string Language { get; set; } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets or sets the color range. |
| | 57 | | /// </summary> |
| | 58 | | /// <value>The color range.</value> |
| | 59 | | public string ColorRange { get; set; } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Gets or sets the color space. |
| | 63 | | /// </summary> |
| | 64 | | /// <value>The color space.</value> |
| | 65 | | public string ColorSpace { get; set; } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Gets or sets the color transfer. |
| | 69 | | /// </summary> |
| | 70 | | /// <value>The color transfer.</value> |
| | 71 | | public string ColorTransfer { get; set; } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Gets or sets the color primaries. |
| | 75 | | /// </summary> |
| | 76 | | /// <value>The color primaries.</value> |
| | 77 | | public string ColorPrimaries { get; set; } |
| | 78 | |
|
| | 79 | | /// <summary> |
| | 80 | | /// Gets or sets the Dolby Vision version major. |
| | 81 | | /// </summary> |
| | 82 | | /// <value>The Dolby Vision version major.</value> |
| | 83 | | public int? DvVersionMajor { get; set; } |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// Gets or sets the Dolby Vision version minor. |
| | 87 | | /// </summary> |
| | 88 | | /// <value>The Dolby Vision version minor.</value> |
| | 89 | | public int? DvVersionMinor { get; set; } |
| | 90 | |
|
| | 91 | | /// <summary> |
| | 92 | | /// Gets or sets the Dolby Vision profile. |
| | 93 | | /// </summary> |
| | 94 | | /// <value>The Dolby Vision profile.</value> |
| | 95 | | public int? DvProfile { get; set; } |
| | 96 | |
|
| | 97 | | /// <summary> |
| | 98 | | /// Gets or sets the Dolby Vision level. |
| | 99 | | /// </summary> |
| | 100 | | /// <value>The Dolby Vision level.</value> |
| | 101 | | public int? DvLevel { get; set; } |
| | 102 | |
|
| | 103 | | /// <summary> |
| | 104 | | /// Gets or sets the Dolby Vision rpu present flag. |
| | 105 | | /// </summary> |
| | 106 | | /// <value>The Dolby Vision rpu present flag.</value> |
| | 107 | | public int? RpuPresentFlag { get; set; } |
| | 108 | |
|
| | 109 | | /// <summary> |
| | 110 | | /// Gets or sets the Dolby Vision el present flag. |
| | 111 | | /// </summary> |
| | 112 | | /// <value>The Dolby Vision el present flag.</value> |
| | 113 | | public int? ElPresentFlag { get; set; } |
| | 114 | |
|
| | 115 | | /// <summary> |
| | 116 | | /// Gets or sets the Dolby Vision bl present flag. |
| | 117 | | /// </summary> |
| | 118 | | /// <value>The Dolby Vision bl present flag.</value> |
| | 119 | | public int? BlPresentFlag { get; set; } |
| | 120 | |
|
| | 121 | | /// <summary> |
| | 122 | | /// Gets or sets the Dolby Vision bl signal compatibility id. |
| | 123 | | /// </summary> |
| | 124 | | /// <value>The Dolby Vision bl signal compatibility id.</value> |
| | 125 | | public int? DvBlSignalCompatibilityId { get; set; } |
| | 126 | |
|
| | 127 | | /// <summary> |
| | 128 | | /// Gets or sets the Rotation in degrees. |
| | 129 | | /// </summary> |
| | 130 | | /// <value>The video rotation.</value> |
| | 131 | | public int? Rotation { get; set; } |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// Gets or sets the comment. |
| | 135 | | /// </summary> |
| | 136 | | /// <value>The comment.</value> |
| | 137 | | public string Comment { get; set; } |
| | 138 | |
|
| | 139 | | /// <summary> |
| | 140 | | /// Gets or sets the time base. |
| | 141 | | /// </summary> |
| | 142 | | /// <value>The time base.</value> |
| | 143 | | public string TimeBase { get; set; } |
| | 144 | |
|
| | 145 | | /// <summary> |
| | 146 | | /// Gets or sets the codec time base. |
| | 147 | | /// </summary> |
| | 148 | | /// <value>The codec time base.</value> |
| | 149 | | public string CodecTimeBase { get; set; } |
| | 150 | |
|
| | 151 | | /// <summary> |
| | 152 | | /// Gets or sets the title. |
| | 153 | | /// </summary> |
| | 154 | | /// <value>The title.</value> |
| | 155 | | public string Title { get; set; } |
| | 156 | |
|
| | 157 | | public bool? Hdr10PlusPresentFlag { get; set; } |
| | 158 | |
|
| | 159 | | /// <summary> |
| | 160 | | /// Gets the video range. |
| | 161 | | /// </summary> |
| | 162 | | /// <value>The video range.</value> |
| | 163 | | [DefaultValue(VideoRange.Unknown)] |
| | 164 | | public VideoRange VideoRange |
| | 165 | | { |
| | 166 | | get |
| | 167 | | { |
| 32 | 168 | | var (videoRange, _) = GetVideoColorRange(); |
| | 169 | |
|
| 32 | 170 | | return videoRange; |
| | 171 | | } |
| | 172 | | } |
| | 173 | |
|
| | 174 | | /// <summary> |
| | 175 | | /// Gets the video range type. |
| | 176 | | /// </summary> |
| | 177 | | /// <value>The video range type.</value> |
| | 178 | | [DefaultValue(VideoRangeType.Unknown)] |
| | 179 | | public VideoRangeType VideoRangeType |
| | 180 | | { |
| | 181 | | get |
| | 182 | | { |
| 906 | 183 | | var (_, videoRangeType) = GetVideoColorRange(); |
| | 184 | |
|
| 906 | 185 | | return videoRangeType; |
| | 186 | | } |
| | 187 | | } |
| | 188 | |
|
| | 189 | | /// <summary> |
| | 190 | | /// Gets the video dovi title. |
| | 191 | | /// </summary> |
| | 192 | | /// <value>The video dovi title.</value> |
| | 193 | | public string VideoDoViTitle |
| | 194 | | { |
| | 195 | | get |
| | 196 | | { |
| 32 | 197 | | var dvProfile = DvProfile; |
| 32 | 198 | | var rpuPresentFlag = RpuPresentFlag == 1; |
| 32 | 199 | | var blPresentFlag = BlPresentFlag == 1; |
| 32 | 200 | | var dvBlCompatId = DvBlSignalCompatibilityId; |
| | 201 | |
|
| 32 | 202 | | if (rpuPresentFlag |
| 32 | 203 | | && blPresentFlag |
| 32 | 204 | | && (dvProfile == 4 |
| 32 | 205 | | || dvProfile == 5 |
| 32 | 206 | | || dvProfile == 7 |
| 32 | 207 | | || dvProfile == 8 |
| 32 | 208 | | || dvProfile == 9 |
| 32 | 209 | | || dvProfile == 10)) |
| | 210 | | { |
| 0 | 211 | | var title = "Dolby Vision Profile " + dvProfile; |
| | 212 | |
|
| 0 | 213 | | if (dvBlCompatId > 0) |
| | 214 | | { |
| 0 | 215 | | title += "." + dvBlCompatId; |
| | 216 | | } |
| | 217 | |
|
| 0 | 218 | | return dvBlCompatId switch |
| 0 | 219 | | { |
| 0 | 220 | | 1 => title + " (HDR10)", |
| 0 | 221 | | 2 => title + " (SDR)", |
| 0 | 222 | | 4 => title + " (HLG)", |
| 0 | 223 | | 6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10 |
| 0 | 224 | | _ => title |
| 0 | 225 | | }; |
| | 226 | | } |
| | 227 | |
|
| 32 | 228 | | return null; |
| | 229 | | } |
| | 230 | | } |
| | 231 | |
|
| | 232 | | /// <summary> |
| | 233 | | /// Gets the audio spatial format. |
| | 234 | | /// </summary> |
| | 235 | | /// <value>The audio spatial format.</value> |
| | 236 | | [DefaultValue(AudioSpatialFormat.None)] |
| | 237 | | public AudioSpatialFormat AudioSpatialFormat |
| | 238 | | { |
| | 239 | | get |
| | 240 | | { |
| 34 | 241 | | if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile)) |
| | 242 | | { |
| 32 | 243 | | return AudioSpatialFormat.None; |
| | 244 | | } |
| | 245 | |
|
| 2 | 246 | | return |
| 2 | 247 | | Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos |
| 2 | 248 | | Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX : |
| 2 | 249 | | AudioSpatialFormat.None; |
| | 250 | | } |
| | 251 | | } |
| | 252 | |
|
| | 253 | | public string LocalizedUndefined { get; set; } |
| | 254 | |
|
| | 255 | | public string LocalizedDefault { get; set; } |
| | 256 | |
|
| | 257 | | public string LocalizedForced { get; set; } |
| | 258 | |
|
| | 259 | | public string LocalizedExternal { get; set; } |
| | 260 | |
|
| | 261 | | public string LocalizedHearingImpaired { get; set; } |
| | 262 | |
|
| | 263 | | public string DisplayTitle |
| | 264 | | { |
| | 265 | | get |
| | 266 | | { |
| 40 | 267 | | switch (Type) |
| | 268 | | { |
| | 269 | | case MediaStreamType.Audio: |
| | 270 | | { |
| 14 | 271 | | var attributes = new List<string>(); |
| | 272 | |
|
| | 273 | | // Do not display the language code in display titles if unset or set to a special code. Show it |
| 14 | 274 | | if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.Ordina |
| | 275 | | { |
| | 276 | | // Get full language string i.e. eng -> English. |
| 3 | 277 | | string fullLanguage = CultureInfo |
| 3 | 278 | | .GetCultures(CultureTypes.NeutralCultures) |
| 3 | 279 | | .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi |
| 3 | 280 | | ?.DisplayName; |
| 3 | 281 | | attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language)); |
| | 282 | | } |
| | 283 | |
|
| 14 | 284 | | if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno |
| | 285 | | { |
| 0 | 286 | | attributes.Add(Profile); |
| | 287 | | } |
| 14 | 288 | | else if (!string.IsNullOrEmpty(Codec)) |
| | 289 | | { |
| 2 | 290 | | attributes.Add(AudioCodec.GetFriendlyName(Codec)); |
| | 291 | | } |
| | 292 | |
|
| 14 | 293 | | if (!string.IsNullOrEmpty(ChannelLayout)) |
| | 294 | | { |
| 0 | 295 | | attributes.Add(StringHelper.FirstToUpper(ChannelLayout)); |
| | 296 | | } |
| 14 | 297 | | else if (Channels.HasValue) |
| | 298 | | { |
| 0 | 299 | | attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch"); |
| | 300 | | } |
| | 301 | |
|
| 14 | 302 | | if (IsDefault) |
| | 303 | | { |
| 4 | 304 | | attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault); |
| | 305 | | } |
| | 306 | |
|
| 14 | 307 | | if (IsExternal) |
| | 308 | | { |
| 8 | 309 | | attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal); |
| | 310 | | } |
| | 311 | |
|
| 14 | 312 | | if (!string.IsNullOrEmpty(Title)) |
| | 313 | | { |
| 2 | 314 | | var result = new StringBuilder(Title); |
| 16 | 315 | | foreach (var tag in attributes) |
| | 316 | | { |
| | 317 | | // Keep Tags that are not already in Title. |
| 6 | 318 | | if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase)) |
| | 319 | | { |
| 6 | 320 | | result.Append(" - ").Append(tag); |
| | 321 | | } |
| | 322 | | } |
| | 323 | |
|
| 2 | 324 | | return result.ToString(); |
| | 325 | | } |
| | 326 | |
|
| 12 | 327 | | return string.Join(" - ", attributes); |
| | 328 | | } |
| | 329 | |
|
| | 330 | | case MediaStreamType.Video: |
| | 331 | | { |
| 0 | 332 | | var attributes = new List<string>(); |
| | 333 | |
|
| 0 | 334 | | var resolutionText = GetResolutionText(); |
| | 335 | |
|
| 0 | 336 | | if (!string.IsNullOrEmpty(resolutionText)) |
| | 337 | | { |
| 0 | 338 | | attributes.Add(resolutionText); |
| | 339 | | } |
| | 340 | |
|
| 0 | 341 | | if (!string.IsNullOrEmpty(Codec)) |
| | 342 | | { |
| 0 | 343 | | attributes.Add(Codec.ToUpperInvariant()); |
| | 344 | | } |
| | 345 | |
|
| 0 | 346 | | if (VideoDoViTitle is not null) |
| | 347 | | { |
| 0 | 348 | | attributes.Add(VideoDoViTitle); |
| | 349 | | } |
| 0 | 350 | | else if (VideoRange != VideoRange.Unknown) |
| | 351 | | { |
| 0 | 352 | | attributes.Add(VideoRange.ToString()); |
| | 353 | | } |
| | 354 | |
|
| 0 | 355 | | if (!string.IsNullOrEmpty(Title)) |
| | 356 | | { |
| 0 | 357 | | var result = new StringBuilder(Title); |
| 0 | 358 | | foreach (var tag in attributes) |
| | 359 | | { |
| | 360 | | // Keep Tags that are not already in Title. |
| 0 | 361 | | if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase)) |
| | 362 | | { |
| 0 | 363 | | result.Append(" - ").Append(tag); |
| | 364 | | } |
| | 365 | | } |
| | 366 | |
|
| 0 | 367 | | return result.ToString(); |
| | 368 | | } |
| | 369 | |
|
| 0 | 370 | | return string.Join(' ', attributes); |
| | 371 | | } |
| | 372 | |
|
| | 373 | | case MediaStreamType.Subtitle: |
| | 374 | | { |
| 26 | 375 | | var attributes = new List<string>(); |
| | 376 | |
|
| 26 | 377 | | if (!string.IsNullOrEmpty(Language)) |
| | 378 | | { |
| | 379 | | // Get full language string i.e. eng -> English. |
| 16 | 380 | | string fullLanguage = CultureInfo |
| 16 | 381 | | .GetCultures(CultureTypes.NeutralCultures) |
| 16 | 382 | | .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi |
| 16 | 383 | | ?.DisplayName; |
| 16 | 384 | | attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language)); |
| | 385 | | } |
| | 386 | | else |
| | 387 | | { |
| 10 | 388 | | attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined); |
| | 389 | | } |
| | 390 | |
|
| 26 | 391 | | if (IsHearingImpaired == true) |
| | 392 | | { |
| 6 | 393 | | attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz |
| | 394 | | } |
| | 395 | |
|
| 26 | 396 | | if (IsDefault) |
| | 397 | | { |
| 11 | 398 | | attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault); |
| | 399 | | } |
| | 400 | |
|
| 26 | 401 | | if (IsForced) |
| | 402 | | { |
| 12 | 403 | | attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced); |
| | 404 | | } |
| | 405 | |
|
| 26 | 406 | | if (!string.IsNullOrEmpty(Codec)) |
| | 407 | | { |
| 8 | 408 | | attributes.Add(Codec.ToUpperInvariant()); |
| | 409 | | } |
| | 410 | |
|
| 26 | 411 | | if (IsExternal) |
| | 412 | | { |
| 2 | 413 | | attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal); |
| | 414 | | } |
| | 415 | |
|
| 26 | 416 | | if (!string.IsNullOrEmpty(Title)) |
| | 417 | | { |
| 20 | 418 | | var result = new StringBuilder(Title); |
| 154 | 419 | | foreach (var tag in attributes) |
| | 420 | | { |
| | 421 | | // Keep Tags that are not already in Title. |
| 57 | 422 | | if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase)) |
| | 423 | | { |
| 53 | 424 | | result.Append(" - ").Append(tag); |
| | 425 | | } |
| | 426 | | } |
| | 427 | |
|
| 20 | 428 | | return result.ToString(); |
| | 429 | | } |
| | 430 | |
|
| 6 | 431 | | return string.Join(" - ", attributes); |
| | 432 | | } |
| | 433 | |
|
| | 434 | | default: |
| 0 | 435 | | return null; |
| | 436 | | } |
| | 437 | | } |
| | 438 | | } |
| | 439 | |
|
| | 440 | | public string NalLengthSize { get; set; } |
| | 441 | |
|
| | 442 | | /// <summary> |
| | 443 | | /// Gets or sets a value indicating whether this instance is interlaced. |
| | 444 | | /// </summary> |
| | 445 | | /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value> |
| | 446 | | public bool IsInterlaced { get; set; } |
| | 447 | |
|
| | 448 | | public bool? IsAVC { get; set; } |
| | 449 | |
|
| | 450 | | /// <summary> |
| | 451 | | /// Gets or sets the channel layout. |
| | 452 | | /// </summary> |
| | 453 | | /// <value>The channel layout.</value> |
| | 454 | | public string ChannelLayout { get; set; } |
| | 455 | |
|
| | 456 | | /// <summary> |
| | 457 | | /// Gets or sets the bit rate. |
| | 458 | | /// </summary> |
| | 459 | | /// <value>The bit rate.</value> |
| | 460 | | public int? BitRate { get; set; } |
| | 461 | |
|
| | 462 | | /// <summary> |
| | 463 | | /// Gets or sets the bit depth. |
| | 464 | | /// </summary> |
| | 465 | | /// <value>The bit depth.</value> |
| | 466 | | public int? BitDepth { get; set; } |
| | 467 | |
|
| | 468 | | /// <summary> |
| | 469 | | /// Gets or sets the reference frames. |
| | 470 | | /// </summary> |
| | 471 | | /// <value>The reference frames.</value> |
| | 472 | | public int? RefFrames { get; set; } |
| | 473 | |
|
| | 474 | | /// <summary> |
| | 475 | | /// Gets or sets the length of the packet. |
| | 476 | | /// </summary> |
| | 477 | | /// <value>The length of the packet.</value> |
| | 478 | | public int? PacketLength { get; set; } |
| | 479 | |
|
| | 480 | | /// <summary> |
| | 481 | | /// Gets or sets the channels. |
| | 482 | | /// </summary> |
| | 483 | | /// <value>The channels.</value> |
| | 484 | | public int? Channels { get; set; } |
| | 485 | |
|
| | 486 | | /// <summary> |
| | 487 | | /// Gets or sets the sample rate. |
| | 488 | | /// </summary> |
| | 489 | | /// <value>The sample rate.</value> |
| | 490 | | public int? SampleRate { get; set; } |
| | 491 | |
|
| | 492 | | /// <summary> |
| | 493 | | /// Gets or sets a value indicating whether this instance is default. |
| | 494 | | /// </summary> |
| | 495 | | /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value> |
| | 496 | | public bool IsDefault { get; set; } |
| | 497 | |
|
| | 498 | | /// <summary> |
| | 499 | | /// Gets or sets a value indicating whether this instance is forced. |
| | 500 | | /// </summary> |
| | 501 | | /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value> |
| | 502 | | public bool IsForced { get; set; } |
| | 503 | |
|
| | 504 | | /// <summary> |
| | 505 | | /// Gets or sets a value indicating whether this instance is for the hearing impaired. |
| | 506 | | /// </summary> |
| | 507 | | /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value> |
| | 508 | | public bool IsHearingImpaired { get; set; } |
| | 509 | |
|
| | 510 | | /// <summary> |
| | 511 | | /// Gets or sets the height. |
| | 512 | | /// </summary> |
| | 513 | | /// <value>The height.</value> |
| | 514 | | public int? Height { get; set; } |
| | 515 | |
|
| | 516 | | /// <summary> |
| | 517 | | /// Gets or sets the width. |
| | 518 | | /// </summary> |
| | 519 | | /// <value>The width.</value> |
| | 520 | | public int? Width { get; set; } |
| | 521 | |
|
| | 522 | | /// <summary> |
| | 523 | | /// Gets or sets the average frame rate. |
| | 524 | | /// </summary> |
| | 525 | | /// <value>The average frame rate.</value> |
| | 526 | | public float? AverageFrameRate { get; set; } |
| | 527 | |
|
| | 528 | | /// <summary> |
| | 529 | | /// Gets or sets the real frame rate. |
| | 530 | | /// </summary> |
| | 531 | | /// <value>The real frame rate.</value> |
| | 532 | | public float? RealFrameRate { get; set; } |
| | 533 | |
|
| | 534 | | /// <summary> |
| | 535 | | /// Gets the framerate used as reference. |
| | 536 | | /// Prefer AverageFrameRate, if that is null or an unrealistic value |
| | 537 | | /// then fallback to RealFrameRate. |
| | 538 | | /// </summary> |
| | 539 | | /// <value>The reference frame rate.</value> |
| | 540 | | public float? ReferenceFrameRate |
| | 541 | | { |
| | 542 | | get |
| | 543 | | { |
| | 544 | | // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not. |
| | 545 | | // This is probably due to a library compatibility issue. |
| | 546 | | // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info. |
| 1051 | 547 | | return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate; |
| | 548 | | } |
| | 549 | | } |
| | 550 | |
|
| | 551 | | /// <summary> |
| | 552 | | /// Gets or sets the profile. |
| | 553 | | /// </summary> |
| | 554 | | /// <value>The profile.</value> |
| | 555 | | public string Profile { get; set; } |
| | 556 | |
|
| | 557 | | /// <summary> |
| | 558 | | /// Gets or sets the type. |
| | 559 | | /// </summary> |
| | 560 | | /// <value>The type.</value> |
| | 561 | | public MediaStreamType Type { get; set; } |
| | 562 | |
|
| | 563 | | /// <summary> |
| | 564 | | /// Gets or sets the aspect ratio. |
| | 565 | | /// </summary> |
| | 566 | | /// <value>The aspect ratio.</value> |
| | 567 | | public string AspectRatio { get; set; } |
| | 568 | |
|
| | 569 | | /// <summary> |
| | 570 | | /// Gets or sets the index. |
| | 571 | | /// </summary> |
| | 572 | | /// <value>The index.</value> |
| | 573 | | public int Index { get; set; } |
| | 574 | |
|
| | 575 | | /// <summary> |
| | 576 | | /// Gets or sets the score. |
| | 577 | | /// </summary> |
| | 578 | | /// <value>The score.</value> |
| | 579 | | public int? Score { get; set; } |
| | 580 | |
|
| | 581 | | /// <summary> |
| | 582 | | /// Gets or sets a value indicating whether this instance is external. |
| | 583 | | /// </summary> |
| | 584 | | /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value> |
| | 585 | | public bool IsExternal { get; set; } |
| | 586 | |
|
| | 587 | | /// <summary> |
| | 588 | | /// Gets or sets the method. |
| | 589 | | /// </summary> |
| | 590 | | /// <value>The method.</value> |
| | 591 | | public SubtitleDeliveryMethod? DeliveryMethod { get; set; } |
| | 592 | |
|
| | 593 | | /// <summary> |
| | 594 | | /// Gets or sets the delivery URL. |
| | 595 | | /// </summary> |
| | 596 | | /// <value>The delivery URL.</value> |
| | 597 | | public string DeliveryUrl { get; set; } |
| | 598 | |
|
| | 599 | | /// <summary> |
| | 600 | | /// Gets or sets a value indicating whether this instance is external URL. |
| | 601 | | /// </summary> |
| | 602 | | /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f |
| | 603 | | public bool? IsExternalUrl { get; set; } |
| | 604 | |
|
| | 605 | | public bool IsTextSubtitleStream |
| | 606 | | { |
| | 607 | | get |
| | 608 | | { |
| 2041 | 609 | | if (Type != MediaStreamType.Subtitle) |
| | 610 | | { |
| 49 | 611 | | return false; |
| | 612 | | } |
| | 613 | |
|
| 1992 | 614 | | if (string.IsNullOrEmpty(Codec) && !IsExternal) |
| | 615 | | { |
| 30 | 616 | | return false; |
| | 617 | | } |
| | 618 | |
|
| 1962 | 619 | | return IsTextFormat(Codec); |
| | 620 | | } |
| | 621 | | } |
| | 622 | |
|
| | 623 | | [JsonIgnore] |
| | 624 | | public bool IsPgsSubtitleStream |
| | 625 | | { |
| | 626 | | get |
| | 627 | | { |
| 60 | 628 | | if (Type != MediaStreamType.Subtitle) |
| | 629 | | { |
| 26 | 630 | | return false; |
| | 631 | | } |
| | 632 | |
|
| 34 | 633 | | if (string.IsNullOrEmpty(Codec) && !IsExternal) |
| | 634 | | { |
| 30 | 635 | | return false; |
| | 636 | | } |
| | 637 | |
|
| 4 | 638 | | return IsPgsFormat(Codec); |
| | 639 | | } |
| | 640 | | } |
| | 641 | |
|
| | 642 | | /// <summary> |
| | 643 | | /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg. |
| | 644 | | /// All text-based and pgs subtitles can be extracted. |
| | 645 | | /// </summary> |
| | 646 | | /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value> |
| | 647 | | [JsonIgnore] |
| 32 | 648 | | public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream; |
| | 649 | |
|
| | 650 | | /// <summary> |
| | 651 | | /// Gets or sets a value indicating whether [supports external stream]. |
| | 652 | | /// </summary> |
| | 653 | | /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value> |
| | 654 | | public bool SupportsExternalStream { get; set; } |
| | 655 | |
|
| | 656 | | /// <summary> |
| | 657 | | /// Gets or sets the filename. |
| | 658 | | /// </summary> |
| | 659 | | /// <value>The filename.</value> |
| | 660 | | public string Path { get; set; } |
| | 661 | |
|
| | 662 | | /// <summary> |
| | 663 | | /// Gets or sets the pixel format. |
| | 664 | | /// </summary> |
| | 665 | | /// <value>The pixel format.</value> |
| | 666 | | public string PixelFormat { get; set; } |
| | 667 | |
|
| | 668 | | /// <summary> |
| | 669 | | /// Gets or sets the level. |
| | 670 | | /// </summary> |
| | 671 | | /// <value>The level.</value> |
| | 672 | | public double? Level { get; set; } |
| | 673 | |
|
| | 674 | | /// <summary> |
| | 675 | | /// Gets or sets whether this instance is anamorphic. |
| | 676 | | /// </summary> |
| | 677 | | /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value> |
| | 678 | | public bool? IsAnamorphic { get; set; } |
| | 679 | |
|
| | 680 | | internal string GetResolutionText() |
| | 681 | | { |
| 73 | 682 | | if (!Width.HasValue || !Height.HasValue) |
| | 683 | | { |
| 3 | 684 | | return null; |
| | 685 | | } |
| | 686 | |
|
| 70 | 687 | | return Width switch |
| 70 | 688 | | { |
| 70 | 689 | | // 256x144 (16:9 square pixel format) |
| 4 | 690 | | <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p", |
| 70 | 691 | | // 426x240 (16:9 square pixel format) |
| 4 | 692 | | <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p", |
| 70 | 693 | | // 640x360 (16:9 square pixel format) |
| 14 | 694 | | <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p", |
| 70 | 695 | | // 682x384 (16:9 square pixel format) |
| 3 | 696 | | <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p", |
| 70 | 697 | | // 720x404 (16:9 square pixel format) |
| 7 | 698 | | <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p", |
| 70 | 699 | | // 854x480 (16:9 square pixel format) |
| 10 | 700 | | <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p", |
| 70 | 701 | | // 960x544 (16:9 square pixel format) |
| 11 | 702 | | <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p", |
| 70 | 703 | | // 1024x576 (16:9 square pixel format) |
| 9 | 704 | | <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p", |
| 70 | 705 | | // 1280x720 |
| 26 | 706 | | <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p", |
| 70 | 707 | | // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD |
| 46 | 708 | | <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p", |
| 70 | 709 | | // 4K |
| 12 | 710 | | <= 4096 when Height <= 3072 => "4K", |
| 70 | 711 | | // 8K |
| 6 | 712 | | <= 8192 when Height <= 6144 => "8K", |
| 0 | 713 | | _ => null |
| 70 | 714 | | }; |
| | 715 | | } |
| | 716 | |
|
| | 717 | | public static bool IsTextFormat(string format) |
| | 718 | | { |
| 3344 | 719 | | string codec = format ?? string.Empty; |
| | 720 | |
|
| | 721 | | // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based. |
| | 722 | |
|
| 3344 | 723 | | return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase) |
| 3344 | 724 | | || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase) |
| 3344 | 725 | | && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase) |
| 3344 | 726 | | && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase) |
| 3344 | 727 | | && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase) |
| 3344 | 728 | | && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase)); |
| | 729 | | } |
| | 730 | |
|
| | 731 | | public static bool IsPgsFormat(string format) |
| | 732 | | { |
| 8 | 733 | | string codec = format ?? string.Empty; |
| | 734 | |
|
| 8 | 735 | | return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase) |
| 8 | 736 | | || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase); |
| | 737 | | } |
| | 738 | |
|
| | 739 | | public bool SupportsSubtitleConversionTo(string toCodec) |
| | 740 | | { |
| 286 | 741 | | if (!IsTextSubtitleStream) |
| | 742 | | { |
| 0 | 743 | | return false; |
| | 744 | | } |
| | 745 | |
|
| 286 | 746 | | var fromCodec = Codec; |
| | 747 | |
|
| | 748 | | // Can't convert from this |
| 286 | 749 | | if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase)) |
| | 750 | | { |
| 0 | 751 | | return false; |
| | 752 | | } |
| | 753 | |
|
| 286 | 754 | | if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase)) |
| | 755 | | { |
| 0 | 756 | | return false; |
| | 757 | | } |
| | 758 | |
|
| | 759 | | // Can't convert to this |
| 286 | 760 | | if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase)) |
| | 761 | | { |
| 0 | 762 | | return false; |
| | 763 | | } |
| | 764 | |
|
| 286 | 765 | | if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase)) |
| | 766 | | { |
| 0 | 767 | | return false; |
| | 768 | | } |
| | 769 | |
|
| 286 | 770 | | return true; |
| | 771 | | } |
| | 772 | |
|
| | 773 | | public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange() |
| | 774 | | { |
| 938 | 775 | | if (Type != MediaStreamType.Video) |
| | 776 | | { |
| 64 | 777 | | return (VideoRange.Unknown, VideoRangeType.Unknown); |
| | 778 | | } |
| | 779 | |
|
| 874 | 780 | | var codecTag = CodecTag; |
| 874 | 781 | | var dvProfile = DvProfile; |
| 874 | 782 | | var rpuPresentFlag = RpuPresentFlag == 1; |
| 874 | 783 | | var blPresentFlag = BlPresentFlag == 1; |
| 874 | 784 | | var dvBlCompatId = DvBlSignalCompatibilityId; |
| | 785 | |
|
| 874 | 786 | | var isDoViProfile = dvProfile is 5 or 7 or 8 or 10; |
| 874 | 787 | | var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6; |
| | 788 | |
|
| 874 | 789 | | if ((isDoViProfile && isDoViFlag) |
| 874 | 790 | | || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase) |
| 874 | 791 | | || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase) |
| 874 | 792 | | || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase) |
| 874 | 793 | | || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase)) |
| | 794 | | { |
| 115 | 795 | | var dvRangeSet = dvProfile switch |
| 115 | 796 | | { |
| 64 | 797 | | 5 => (VideoRange.HDR, VideoRangeType.DOVI), |
| 51 | 798 | | 8 => dvBlCompatId switch |
| 51 | 799 | | { |
| 51 | 800 | | 1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10), |
| 0 | 801 | | 4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG), |
| 0 | 802 | | 2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR), |
| 51 | 803 | | // Out of Dolby Spec files should be marked as invalid |
| 0 | 804 | | _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid) |
| 51 | 805 | | }, |
| 0 | 806 | | 7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL), |
| 0 | 807 | | 10 => dvBlCompatId switch |
| 0 | 808 | | { |
| 0 | 809 | | 0 => (VideoRange.HDR, VideoRangeType.DOVI), |
| 0 | 810 | | 1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10), |
| 0 | 811 | | 2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR), |
| 0 | 812 | | 4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG), |
| 0 | 813 | | // Out of Dolby Spec files should be marked as invalid |
| 0 | 814 | | _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid) |
| 0 | 815 | | }, |
| 0 | 816 | | _ => (VideoRange.SDR, VideoRangeType.SDR) |
| 115 | 817 | | }; |
| | 818 | |
|
| 115 | 819 | | if (Hdr10PlusPresentFlag == true) |
| | 820 | | { |
| 0 | 821 | | return dvRangeSet.Item2 switch |
| 0 | 822 | | { |
| 0 | 823 | | VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus), |
| 0 | 824 | | VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus), |
| 0 | 825 | | _ => dvRangeSet |
| 0 | 826 | | }; |
| | 827 | | } |
| | 828 | |
|
| 115 | 829 | | return dvRangeSet; |
| | 830 | | } |
| | 831 | |
|
| 759 | 832 | | var colorTransfer = ColorTransfer; |
| | 833 | |
|
| 759 | 834 | | if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase)) |
| | 835 | | { |
| 198 | 836 | | return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide |
| | 837 | | } |
| 561 | 838 | | else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase)) |
| | 839 | | { |
| 0 | 840 | | return (VideoRange.HDR, VideoRangeType.HLG); |
| | 841 | | } |
| | 842 | |
|
| 561 | 843 | | return (VideoRange.SDR, VideoRangeType.SDR); |
| | 844 | | } |
| | 845 | | } |
| | 846 | | } |