< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Entities.MediaStream
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs
Line coverage
73%
Covered lines: 164
Uncovered lines: 58
Coverable lines: 222
Total lines: 839
Line coverage: 73.8%
Branch coverage
66%
Covered branches: 198
Total branches: 296
Branch coverage: 66.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/28/2025 - 12:10:13 AM Line coverage: 71.1% (175/246) Branch coverage: 65.9% (203/308) Total lines: 8801/19/2026 - 12:13:54 AM Line coverage: 73.8% (164/222) Branch coverage: 66.8% (198/296) Total lines: 8403/31/2026 - 12:14:24 AM Line coverage: 73.8% (164/222) Branch coverage: 66.8% (198/296) Total lines: 839 12/28/2025 - 12:10:13 AM Line coverage: 71.1% (175/246) Branch coverage: 65.9% (203/308) Total lines: 8801/19/2026 - 12:13:54 AM Line coverage: 73.8% (164/222) Branch coverage: 66.8% (198/296) Total lines: 8403/31/2026 - 12:14:24 AM Line coverage: 73.8% (164/222) Branch coverage: 66.8% (198/296) Total lines: 839

Coverage delta

Coverage delta 3 -3

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_VideoRange()100%11100%
get_VideoRangeType()100%11100%
get_VideoDoViTitle()8%852554.16%
get_AudioSpatialFormat()87.5%88100%
get_DisplayTitle()65.38%2827867.74%
get_ReferenceFrameRate()100%22100%
get_IsTextSubtitleStream()100%66100%
get_IsPgsSubtitleStream()100%66100%
get_IsExtractableSubtitleStream()100%22100%
GetResolutionText()93.24%747496.66%
IsTextFormat(...)50%1212100%
IsPgsFormat(...)50%44100%
SupportsSubtitleConversionTo(...)50%171058.33%
GetVideoColorRange()56.52%4016958.82%

File(s)

/srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System;
 5using System.Collections.Generic;
 6using System.ComponentModel;
 7using System.Globalization;
 8using System.Linq;
 9using System.Text;
 10using System.Text.Json.Serialization;
 11using Jellyfin.Data.Enums;
 12using Jellyfin.Extensions;
 13using MediaBrowser.Model.Dlna;
 14using MediaBrowser.Model.Extensions;
 15using MediaBrowser.Model.MediaInfo;
 16
 17namespace MediaBrowser.Model.Entities
 18{
 19    /// <summary>
 20    /// Class MediaStream.
 21    /// </summary>
 22    public class MediaStream
 23    {
 224        private static readonly string[] _specialCodes =
 225        {
 226            // Uncoded languages.
 227            "mis",
 228            // Multiple languages.
 229            "mul",
 230            // Undetermined.
 231            "und",
 232            // No linguistic content; not applicable.
 233            "zxx"
 234        };
 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        public bool? Hdr10PlusPresentFlag { get; set; }
 157
 158        /// <summary>
 159        /// Gets the video range.
 160        /// </summary>
 161        /// <value>The video range.</value>
 162        [DefaultValue(VideoRange.Unknown)]
 163        public VideoRange VideoRange
 164        {
 165            get
 166            {
 35167                var (videoRange, _) = GetVideoColorRange();
 168
 35169                return videoRange;
 170            }
 171        }
 172
 173        /// <summary>
 174        /// Gets the video range type.
 175        /// </summary>
 176        /// <value>The video range type.</value>
 177        [DefaultValue(VideoRangeType.Unknown)]
 178        public VideoRangeType VideoRangeType
 179        {
 180            get
 181            {
 909182                var (_, videoRangeType) = GetVideoColorRange();
 183
 909184                return videoRangeType;
 185            }
 186        }
 187
 188        /// <summary>
 189        /// Gets the video dovi title.
 190        /// </summary>
 191        /// <value>The video dovi title.</value>
 192        public string VideoDoViTitle
 193        {
 194            get
 195            {
 35196                var dvProfile = DvProfile;
 35197                var rpuPresentFlag = RpuPresentFlag == 1;
 35198                var blPresentFlag = BlPresentFlag == 1;
 35199                var dvBlCompatId = DvBlSignalCompatibilityId;
 200
 35201                if (rpuPresentFlag
 35202                    && blPresentFlag
 35203                    && (dvProfile == 4
 35204                        || dvProfile == 5
 35205                        || dvProfile == 7
 35206                        || dvProfile == 8
 35207                        || dvProfile == 9
 35208                        || dvProfile == 10))
 209                {
 0210                    var title = "Dolby Vision Profile " + dvProfile;
 211
 0212                    if (dvBlCompatId > 0)
 213                    {
 0214                        title += "." + dvBlCompatId;
 215                    }
 216
 0217                    return dvBlCompatId switch
 0218                    {
 0219                        1 => title + " (HDR10)",
 0220                        2 => title + " (SDR)",
 0221                        4 => title + " (HLG)",
 0222                        6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10
 0223                        _ => title
 0224                    };
 225                }
 226
 35227                return null;
 228            }
 229        }
 230
 231        /// <summary>
 232        /// Gets the audio spatial format.
 233        /// </summary>
 234        /// <value>The audio spatial format.</value>
 235        [DefaultValue(AudioSpatialFormat.None)]
 236        public AudioSpatialFormat AudioSpatialFormat
 237        {
 238            get
 239            {
 37240                if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
 241                {
 35242                    return AudioSpatialFormat.None;
 243                }
 244
 2245                return
 2246                    Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos 
 2247                    Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
 2248                    AudioSpatialFormat.None;
 249            }
 250        }
 251
 252        public string LocalizedUndefined { get; set; }
 253
 254        public string LocalizedDefault { get; set; }
 255
 256        public string LocalizedForced { get; set; }
 257
 258        public string LocalizedExternal { get; set; }
 259
 260        public string LocalizedHearingImpaired { get; set; }
 261
 262        public string LocalizedLanguage { get; set; }
 263
 264        public string DisplayTitle
 265        {
 266            get
 267            {
 46268                switch (Type)
 269                {
 270                    case MediaStreamType.Audio:
 271                    {
 16272                        var attributes = new List<string>();
 273
 274                        // Do not display the language code in display titles if unset or set to a special code. Show it
 16275                        if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.Ordina
 276                        {
 277                            // Use pre-resolved localized language name, falling back to raw language code.
 5278                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 279                        }
 280
 16281                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 282                        {
 0283                            attributes.Add(Profile);
 284                        }
 16285                        else if (!string.IsNullOrEmpty(Codec))
 286                        {
 4287                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 288                        }
 289
 16290                        if (!string.IsNullOrEmpty(ChannelLayout))
 291                        {
 2292                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 293                        }
 14294                        else if (Channels.HasValue)
 295                        {
 0296                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 297                        }
 298
 16299                        if (IsDefault)
 300                        {
 4301                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 302                        }
 303
 16304                        if (IsExternal)
 305                        {
 8306                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 307                        }
 308
 16309                        if (!string.IsNullOrEmpty(Title))
 310                        {
 2311                            var result = new StringBuilder(Title);
 16312                            foreach (var tag in attributes)
 313                            {
 314                                // Keep Tags that are not already in Title.
 6315                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 316                                {
 6317                                    result.Append(" - ").Append(tag);
 318                                }
 319                            }
 320
 2321                            return result.ToString();
 322                        }
 323
 14324                        return string.Join(" - ", attributes);
 325                    }
 326
 327                    case MediaStreamType.Video:
 328                    {
 0329                        var attributes = new List<string>();
 330
 0331                        var resolutionText = GetResolutionText();
 332
 0333                        if (!string.IsNullOrEmpty(resolutionText))
 334                        {
 0335                            attributes.Add(resolutionText);
 336                        }
 337
 0338                        if (!string.IsNullOrEmpty(Codec))
 339                        {
 0340                            attributes.Add(Codec.ToUpperInvariant());
 341                        }
 342
 0343                        if (VideoDoViTitle is not null)
 344                        {
 0345                            attributes.Add(VideoDoViTitle);
 346                        }
 0347                        else if (VideoRange != VideoRange.Unknown)
 348                        {
 0349                            attributes.Add(VideoRange.ToString());
 350                        }
 351
 0352                        if (!string.IsNullOrEmpty(Title))
 353                        {
 0354                            var result = new StringBuilder(Title);
 0355                            foreach (var tag in attributes)
 356                            {
 357                                // Keep Tags that are not already in Title.
 0358                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 359                                {
 0360                                    result.Append(" - ").Append(tag);
 361                                }
 362                            }
 363
 0364                            return result.ToString();
 365                        }
 366
 0367                        return string.Join(' ', attributes);
 368                    }
 369
 370                    case MediaStreamType.Subtitle:
 371                    {
 30372                        var attributes = new List<string>();
 373
 30374                        if (!string.IsNullOrEmpty(Language))
 375                        {
 376                            // Use pre-resolved localized language name, falling back to raw language code.
 20377                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 378                        }
 379                        else
 380                        {
 10381                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 382                        }
 383
 30384                        if (IsHearingImpaired == true)
 385                        {
 6386                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 387                        }
 388
 30389                        if (IsDefault)
 390                        {
 11391                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 392                        }
 393
 30394                        if (IsForced)
 395                        {
 12396                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 397                        }
 398
 30399                        if (!string.IsNullOrEmpty(Codec))
 400                        {
 12401                            attributes.Add(Codec.ToUpperInvariant());
 402                        }
 403
 30404                        if (IsExternal)
 405                        {
 2406                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 407                        }
 408
 30409                        if (!string.IsNullOrEmpty(Title))
 410                        {
 20411                            var result = new StringBuilder(Title);
 154412                            foreach (var tag in attributes)
 413                            {
 414                                // Keep Tags that are not already in Title.
 57415                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 416                                {
 53417                                    result.Append(" - ").Append(tag);
 418                                }
 419                            }
 420
 20421                            return result.ToString();
 422                        }
 423
 10424                        return string.Join(" - ", attributes);
 425                    }
 426
 427                    default:
 0428                        return null;
 429                }
 430            }
 431        }
 432
 433        public string NalLengthSize { get; set; }
 434
 435        /// <summary>
 436        /// Gets or sets a value indicating whether this instance is interlaced.
 437        /// </summary>
 438        /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
 439        public bool IsInterlaced { get; set; }
 440
 441        public bool? IsAVC { get; set; }
 442
 443        /// <summary>
 444        /// Gets or sets the channel layout.
 445        /// </summary>
 446        /// <value>The channel layout.</value>
 447        public string ChannelLayout { get; set; }
 448
 449        /// <summary>
 450        /// Gets or sets the bit rate.
 451        /// </summary>
 452        /// <value>The bit rate.</value>
 453        public int? BitRate { get; set; }
 454
 455        /// <summary>
 456        /// Gets or sets the bit depth.
 457        /// </summary>
 458        /// <value>The bit depth.</value>
 459        public int? BitDepth { get; set; }
 460
 461        /// <summary>
 462        /// Gets or sets the reference frames.
 463        /// </summary>
 464        /// <value>The reference frames.</value>
 465        public int? RefFrames { get; set; }
 466
 467        /// <summary>
 468        /// Gets or sets the length of the packet.
 469        /// </summary>
 470        /// <value>The length of the packet.</value>
 471        public int? PacketLength { get; set; }
 472
 473        /// <summary>
 474        /// Gets or sets the channels.
 475        /// </summary>
 476        /// <value>The channels.</value>
 477        public int? Channels { get; set; }
 478
 479        /// <summary>
 480        /// Gets or sets the sample rate.
 481        /// </summary>
 482        /// <value>The sample rate.</value>
 483        public int? SampleRate { get; set; }
 484
 485        /// <summary>
 486        /// Gets or sets a value indicating whether this instance is default.
 487        /// </summary>
 488        /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
 489        public bool IsDefault { get; set; }
 490
 491        /// <summary>
 492        /// Gets or sets a value indicating whether this instance is forced.
 493        /// </summary>
 494        /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
 495        public bool IsForced { get; set; }
 496
 497        /// <summary>
 498        /// Gets or sets a value indicating whether this instance is for the hearing impaired.
 499        /// </summary>
 500        /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
 501        public bool IsHearingImpaired { get; set; }
 502
 503        /// <summary>
 504        /// Gets or sets the height.
 505        /// </summary>
 506        /// <value>The height.</value>
 507        public int? Height { get; set; }
 508
 509        /// <summary>
 510        /// Gets or sets the width.
 511        /// </summary>
 512        /// <value>The width.</value>
 513        public int? Width { get; set; }
 514
 515        /// <summary>
 516        /// Gets or sets the average frame rate.
 517        /// </summary>
 518        /// <value>The average frame rate.</value>
 519        public float? AverageFrameRate { get; set; }
 520
 521        /// <summary>
 522        /// Gets or sets the real frame rate.
 523        /// </summary>
 524        /// <value>The real frame rate.</value>
 525        public float? RealFrameRate { get; set; }
 526
 527        /// <summary>
 528        /// Gets the framerate used as reference.
 529        /// Prefer AverageFrameRate, if that is null or an unrealistic value
 530        /// then fallback to RealFrameRate.
 531        /// </summary>
 532        /// <value>The reference frame rate.</value>
 533        public float? ReferenceFrameRate
 534        {
 535            get
 536            {
 537                // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not.
 538                // This is probably due to a library compatibility issue.
 539                // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info.
 1054540                return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate;
 541            }
 542        }
 543
 544        /// <summary>
 545        /// Gets or sets the profile.
 546        /// </summary>
 547        /// <value>The profile.</value>
 548        public string Profile { get; set; }
 549
 550        /// <summary>
 551        /// Gets or sets the type.
 552        /// </summary>
 553        /// <value>The type.</value>
 554        public MediaStreamType Type { get; set; }
 555
 556        /// <summary>
 557        /// Gets or sets the aspect ratio.
 558        /// </summary>
 559        /// <value>The aspect ratio.</value>
 560        public string AspectRatio { get; set; }
 561
 562        /// <summary>
 563        /// Gets or sets the index.
 564        /// </summary>
 565        /// <value>The index.</value>
 566        public int Index { get; set; }
 567
 568        /// <summary>
 569        /// Gets or sets the score.
 570        /// </summary>
 571        /// <value>The score.</value>
 572        public int? Score { get; set; }
 573
 574        /// <summary>
 575        /// Gets or sets a value indicating whether this instance is external.
 576        /// </summary>
 577        /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
 578        public bool IsExternal { get; set; }
 579
 580        /// <summary>
 581        /// Gets or sets the method.
 582        /// </summary>
 583        /// <value>The method.</value>
 584        public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
 585
 586        /// <summary>
 587        /// Gets or sets the delivery URL.
 588        /// </summary>
 589        /// <value>The delivery URL.</value>
 590        public string DeliveryUrl { get; set; }
 591
 592        /// <summary>
 593        /// Gets or sets a value indicating whether this instance is external URL.
 594        /// </summary>
 595        /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f
 596        public bool? IsExternalUrl { get; set; }
 597
 598        public bool IsTextSubtitleStream
 599        {
 600            get
 601            {
 2047602                if (Type != MediaStreamType.Subtitle)
 603                {
 51604                    return false;
 605                }
 606
 1996607                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 608                {
 30609                    return false;
 610                }
 611
 1966612                return IsTextFormat(Codec);
 613            }
 614        }
 615
 616        [JsonIgnore]
 617        public bool IsPgsSubtitleStream
 618        {
 619            get
 620            {
 64621                if (Type != MediaStreamType.Subtitle)
 622                {
 28623                    return false;
 624                }
 625
 36626                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 627                {
 30628                    return false;
 629                }
 630
 6631                return IsPgsFormat(Codec);
 632            }
 633        }
 634
 635        /// <summary>
 636        /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg.
 637        /// All text-based and pgs subtitles can be extracted.
 638        /// </summary>
 639        /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value>
 640        [JsonIgnore]
 35641        public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream;
 642
 643        /// <summary>
 644        /// Gets or sets a value indicating whether [supports external stream].
 645        /// </summary>
 646        /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
 647        public bool SupportsExternalStream { get; set; }
 648
 649        /// <summary>
 650        /// Gets or sets the filename.
 651        /// </summary>
 652        /// <value>The filename.</value>
 653        public string Path { get; set; }
 654
 655        /// <summary>
 656        /// Gets or sets the pixel format.
 657        /// </summary>
 658        /// <value>The pixel format.</value>
 659        public string PixelFormat { get; set; }
 660
 661        /// <summary>
 662        /// Gets or sets the level.
 663        /// </summary>
 664        /// <value>The level.</value>
 665        public double? Level { get; set; }
 666
 667        /// <summary>
 668        /// Gets or sets whether this instance is anamorphic.
 669        /// </summary>
 670        /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
 671        public bool? IsAnamorphic { get; set; }
 672
 673        internal string GetResolutionText()
 674        {
 73675            if (!Width.HasValue || !Height.HasValue)
 676            {
 3677                return null;
 678            }
 679
 70680            return Width switch
 70681            {
 70682                // 256x144 (16:9 square pixel format)
 4683                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70684                // 426x240 (16:9 square pixel format)
 4685                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70686                // 640x360 (16:9 square pixel format)
 14687                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70688                // 682x384 (16:9 square pixel format)
 3689                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70690                // 720x404 (16:9 square pixel format)
 7691                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70692                // 854x480 (16:9 square pixel format)
 10693                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70694                // 960x544 (16:9 square pixel format)
 11695                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70696                // 1024x576 (16:9 square pixel format)
 9697                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70698                // 1280x720
 26699                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70700                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46701                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70702                // 4K
 12703                <= 4096 when Height <= 3072 => "4K",
 70704                // 8K
 6705                <= 8192 when Height <= 6144 => "8K",
 0706                _ => null
 70707            };
 708        }
 709
 710        public static bool IsTextFormat(string format)
 711        {
 3348712            string codec = format ?? string.Empty;
 713
 714            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 715
 3348716            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3348717                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3348718                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3348719                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3348720                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3348721                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 722        }
 723
 724        public static bool IsPgsFormat(string format)
 725        {
 10726            string codec = format ?? string.Empty;
 727
 10728            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 10729                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 730        }
 731
 732        public bool SupportsSubtitleConversionTo(string toCodec)
 733        {
 286734            if (!IsTextSubtitleStream)
 735            {
 0736                return false;
 737            }
 738
 286739            var fromCodec = Codec;
 740
 741            // Can't convert from this
 286742            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 743            {
 0744                return false;
 745            }
 746
 286747            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 748            {
 0749                return false;
 750            }
 751
 752            // Can't convert to this
 286753            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 754            {
 0755                return false;
 756            }
 757
 286758            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 759            {
 0760                return false;
 761            }
 762
 286763            return true;
 764        }
 765
 766        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 767        {
 944768            if (Type != MediaStreamType.Video)
 769            {
 70770                return (VideoRange.Unknown, VideoRangeType.Unknown);
 771            }
 772
 874773            var codecTag = CodecTag;
 874774            var dvProfile = DvProfile;
 874775            var rpuPresentFlag = RpuPresentFlag == 1;
 874776            var blPresentFlag = BlPresentFlag == 1;
 874777            var dvBlCompatId = DvBlSignalCompatibilityId;
 778
 874779            var isDoViProfile = dvProfile is 5 or 7 or 8 or 10;
 874780            var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6;
 781
 874782            if ((isDoViProfile && isDoViFlag)
 874783                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 874784                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 874785                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 874786                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 787            {
 115788                var dvRangeSet = dvProfile switch
 115789                {
 64790                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 51791                    8 => dvBlCompatId switch
 51792                    {
 51793                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0794                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0795                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 51796                        // Out of Dolby Spec files should be marked as invalid
 0797                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 51798                    },
 0799                    7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL),
 0800                    10 => dvBlCompatId switch
 0801                    {
 0802                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0803                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0804                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0805                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0806                        // Out of Dolby Spec files should be marked as invalid
 0807                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 0808                    },
 0809                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 115810                };
 811
 115812                if (Hdr10PlusPresentFlag == true)
 813                {
 0814                    return dvRangeSet.Item2 switch
 0815                    {
 0816                        VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus),
 0817                        VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus),
 0818                        _ => dvRangeSet
 0819                    };
 820                }
 821
 115822                return dvRangeSet;
 823            }
 824
 759825            var colorTransfer = ColorTransfer;
 826
 759827            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 828            {
 198829                return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide
 830            }
 561831            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 832            {
 0833                return (VideoRange.HDR, VideoRangeType.HLG);
 834            }
 835
 561836            return (VideoRange.SDR, VideoRangeType.SDR);
 837        }
 838    }
 839}