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