< 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: 838
Line coverage: 73.8%
Branch coverage
68%
Covered branches: 202
Total branches: 296
Branch coverage: 68.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 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: 8394/12/2026 - 12:13:54 AM Line coverage: 73.8% (164/222) Branch coverage: 68.2% (202/296) Total lines: 838 1/23/2026 - 12:11:06 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: 8394/12/2026 - 12:13:54 AM Line coverage: 73.8% (164/222) Branch coverage: 68.2% (202/296) Total lines: 838

Coverage delta

Coverage delta 2 -2

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(...)83.33%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.Text;
 9using System.Text.Json.Serialization;
 10using Jellyfin.Data.Enums;
 11using Jellyfin.Extensions;
 12using MediaBrowser.Model.Dlna;
 13using MediaBrowser.Model.Extensions;
 14using MediaBrowser.Model.MediaInfo;
 15
 16namespace MediaBrowser.Model.Entities
 17{
 18    /// <summary>
 19    /// Class MediaStream.
 20    /// </summary>
 21    public class MediaStream
 22    {
 223        private static readonly string[] _specialCodes =
 224        {
 225            // Uncoded languages.
 226            "mis",
 227            // Multiple languages.
 228            "mul",
 229            // Undetermined.
 230            "und",
 231            // No linguistic content; not applicable.
 232            "zxx"
 233        };
 34
 35        /// <summary>
 36        /// Gets or sets the codec.
 37        /// </summary>
 38        /// <value>The codec.</value>
 39        public string Codec { get; set; }
 40
 41        /// <summary>
 42        /// Gets or sets the codec tag.
 43        /// </summary>
 44        /// <value>The codec tag.</value>
 45        public string CodecTag { get; set; }
 46
 47        /// <summary>
 48        /// Gets or sets the language.
 49        /// </summary>
 50        /// <value>The language.</value>
 51        public string Language { get; set; }
 52
 53        /// <summary>
 54        /// Gets or sets the color range.
 55        /// </summary>
 56        /// <value>The color range.</value>
 57        public string ColorRange { get; set; }
 58
 59        /// <summary>
 60        /// Gets or sets the color space.
 61        /// </summary>
 62        /// <value>The color space.</value>
 63        public string ColorSpace { get; set; }
 64
 65        /// <summary>
 66        /// Gets or sets the color transfer.
 67        /// </summary>
 68        /// <value>The color transfer.</value>
 69        public string ColorTransfer { get; set; }
 70
 71        /// <summary>
 72        /// Gets or sets the color primaries.
 73        /// </summary>
 74        /// <value>The color primaries.</value>
 75        public string ColorPrimaries { get; set; }
 76
 77        /// <summary>
 78        /// Gets or sets the Dolby Vision version major.
 79        /// </summary>
 80        /// <value>The Dolby Vision version major.</value>
 81        public int? DvVersionMajor { get; set; }
 82
 83        /// <summary>
 84        /// Gets or sets the Dolby Vision version minor.
 85        /// </summary>
 86        /// <value>The Dolby Vision version minor.</value>
 87        public int? DvVersionMinor { get; set; }
 88
 89        /// <summary>
 90        /// Gets or sets the Dolby Vision profile.
 91        /// </summary>
 92        /// <value>The Dolby Vision profile.</value>
 93        public int? DvProfile { get; set; }
 94
 95        /// <summary>
 96        /// Gets or sets the Dolby Vision level.
 97        /// </summary>
 98        /// <value>The Dolby Vision level.</value>
 99        public int? DvLevel { get; set; }
 100
 101        /// <summary>
 102        /// Gets or sets the Dolby Vision rpu present flag.
 103        /// </summary>
 104        /// <value>The Dolby Vision rpu present flag.</value>
 105        public int? RpuPresentFlag { get; set; }
 106
 107        /// <summary>
 108        /// Gets or sets the Dolby Vision el present flag.
 109        /// </summary>
 110        /// <value>The Dolby Vision el present flag.</value>
 111        public int? ElPresentFlag { get; set; }
 112
 113        /// <summary>
 114        /// Gets or sets the Dolby Vision bl present flag.
 115        /// </summary>
 116        /// <value>The Dolby Vision bl present flag.</value>
 117        public int? BlPresentFlag { get; set; }
 118
 119        /// <summary>
 120        /// Gets or sets the Dolby Vision bl signal compatibility id.
 121        /// </summary>
 122        /// <value>The Dolby Vision bl signal compatibility id.</value>
 123        public int? DvBlSignalCompatibilityId { get; set; }
 124
 125        /// <summary>
 126        /// Gets or sets the Rotation in degrees.
 127        /// </summary>
 128        /// <value>The video rotation.</value>
 129        public int? Rotation { get; set; }
 130
 131        /// <summary>
 132        /// Gets or sets the comment.
 133        /// </summary>
 134        /// <value>The comment.</value>
 135        public string Comment { get; set; }
 136
 137        /// <summary>
 138        /// Gets or sets the time base.
 139        /// </summary>
 140        /// <value>The time base.</value>
 141        public string TimeBase { get; set; }
 142
 143        /// <summary>
 144        /// Gets or sets the codec time base.
 145        /// </summary>
 146        /// <value>The codec time base.</value>
 147        public string CodecTimeBase { get; set; }
 148
 149        /// <summary>
 150        /// Gets or sets the title.
 151        /// </summary>
 152        /// <value>The title.</value>
 153        public string Title { get; set; }
 154
 155        public bool? Hdr10PlusPresentFlag { get; set; }
 156
 157        /// <summary>
 158        /// Gets the video range.
 159        /// </summary>
 160        /// <value>The video range.</value>
 161        [DefaultValue(VideoRange.Unknown)]
 162        public VideoRange VideoRange
 163        {
 164            get
 165            {
 35166                var (videoRange, _) = GetVideoColorRange();
 167
 35168                return videoRange;
 169            }
 170        }
 171
 172        /// <summary>
 173        /// Gets the video range type.
 174        /// </summary>
 175        /// <value>The video range type.</value>
 176        [DefaultValue(VideoRangeType.Unknown)]
 177        public VideoRangeType VideoRangeType
 178        {
 179            get
 180            {
 909181                var (_, videoRangeType) = GetVideoColorRange();
 182
 909183                return videoRangeType;
 184            }
 185        }
 186
 187        /// <summary>
 188        /// Gets the video dovi title.
 189        /// </summary>
 190        /// <value>The video dovi title.</value>
 191        public string VideoDoViTitle
 192        {
 193            get
 194            {
 35195                var dvProfile = DvProfile;
 35196                var rpuPresentFlag = RpuPresentFlag == 1;
 35197                var blPresentFlag = BlPresentFlag == 1;
 35198                var dvBlCompatId = DvBlSignalCompatibilityId;
 199
 35200                if (rpuPresentFlag
 35201                    && blPresentFlag
 35202                    && (dvProfile == 4
 35203                        || dvProfile == 5
 35204                        || dvProfile == 7
 35205                        || dvProfile == 8
 35206                        || dvProfile == 9
 35207                        || dvProfile == 10))
 208                {
 0209                    var title = "Dolby Vision Profile " + dvProfile;
 210
 0211                    if (dvBlCompatId > 0)
 212                    {
 0213                        title += "." + dvBlCompatId;
 214                    }
 215
 0216                    return dvBlCompatId switch
 0217                    {
 0218                        1 => title + " (HDR10)",
 0219                        2 => title + " (SDR)",
 0220                        4 => title + " (HLG)",
 0221                        6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10
 0222                        _ => title
 0223                    };
 224                }
 225
 35226                return null;
 227            }
 228        }
 229
 230        /// <summary>
 231        /// Gets the audio spatial format.
 232        /// </summary>
 233        /// <value>The audio spatial format.</value>
 234        [DefaultValue(AudioSpatialFormat.None)]
 235        public AudioSpatialFormat AudioSpatialFormat
 236        {
 237            get
 238            {
 37239                if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
 240                {
 35241                    return AudioSpatialFormat.None;
 242                }
 243
 2244                return
 2245                    Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos 
 2246                    Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
 2247                    AudioSpatialFormat.None;
 248            }
 249        }
 250
 251        public string LocalizedUndefined { get; set; }
 252
 253        public string LocalizedDefault { get; set; }
 254
 255        public string LocalizedForced { get; set; }
 256
 257        public string LocalizedExternal { get; set; }
 258
 259        public string LocalizedHearingImpaired { get; set; }
 260
 261        public string LocalizedLanguage { get; set; }
 262
 263        public string DisplayTitle
 264        {
 265            get
 266            {
 46267                switch (Type)
 268                {
 269                    case MediaStreamType.Audio:
 270                    {
 16271                        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
 16274                        if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.Ordina
 275                        {
 276                            // Use pre-resolved localized language name, falling back to raw language code.
 5277                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 278                        }
 279
 16280                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 281                        {
 0282                            attributes.Add(Profile);
 283                        }
 16284                        else if (!string.IsNullOrEmpty(Codec))
 285                        {
 4286                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 287                        }
 288
 16289                        if (!string.IsNullOrEmpty(ChannelLayout))
 290                        {
 2291                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 292                        }
 14293                        else if (Channels.HasValue)
 294                        {
 0295                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 296                        }
 297
 16298                        if (IsDefault)
 299                        {
 4300                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 301                        }
 302
 16303                        if (IsExternal)
 304                        {
 8305                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 306                        }
 307
 16308                        if (!string.IsNullOrEmpty(Title))
 309                        {
 2310                            var result = new StringBuilder(Title);
 16311                            foreach (var tag in attributes)
 312                            {
 313                                // Keep Tags that are not already in Title.
 6314                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 315                                {
 6316                                    result.Append(" - ").Append(tag);
 317                                }
 318                            }
 319
 2320                            return result.ToString();
 321                        }
 322
 14323                        return string.Join(" - ", attributes);
 324                    }
 325
 326                    case MediaStreamType.Video:
 327                    {
 0328                        var attributes = new List<string>();
 329
 0330                        var resolutionText = GetResolutionText();
 331
 0332                        if (!string.IsNullOrEmpty(resolutionText))
 333                        {
 0334                            attributes.Add(resolutionText);
 335                        }
 336
 0337                        if (!string.IsNullOrEmpty(Codec))
 338                        {
 0339                            attributes.Add(Codec.ToUpperInvariant());
 340                        }
 341
 0342                        if (VideoDoViTitle is not null)
 343                        {
 0344                            attributes.Add(VideoDoViTitle);
 345                        }
 0346                        else if (VideoRange != VideoRange.Unknown)
 347                        {
 0348                            attributes.Add(VideoRange.ToString());
 349                        }
 350
 0351                        if (!string.IsNullOrEmpty(Title))
 352                        {
 0353                            var result = new StringBuilder(Title);
 0354                            foreach (var tag in attributes)
 355                            {
 356                                // Keep Tags that are not already in Title.
 0357                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 358                                {
 0359                                    result.Append(" - ").Append(tag);
 360                                }
 361                            }
 362
 0363                            return result.ToString();
 364                        }
 365
 0366                        return string.Join(' ', attributes);
 367                    }
 368
 369                    case MediaStreamType.Subtitle:
 370                    {
 30371                        var attributes = new List<string>();
 372
 30373                        if (!string.IsNullOrEmpty(Language))
 374                        {
 375                            // Use pre-resolved localized language name, falling back to raw language code.
 20376                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 377                        }
 378                        else
 379                        {
 10380                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 381                        }
 382
 30383                        if (IsHearingImpaired == true)
 384                        {
 6385                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 386                        }
 387
 30388                        if (IsDefault)
 389                        {
 11390                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 391                        }
 392
 30393                        if (IsForced)
 394                        {
 12395                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 396                        }
 397
 30398                        if (!string.IsNullOrEmpty(Codec))
 399                        {
 12400                            attributes.Add(Codec.ToUpperInvariant());
 401                        }
 402
 30403                        if (IsExternal)
 404                        {
 2405                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 406                        }
 407
 30408                        if (!string.IsNullOrEmpty(Title))
 409                        {
 20410                            var result = new StringBuilder(Title);
 154411                            foreach (var tag in attributes)
 412                            {
 413                                // Keep Tags that are not already in Title.
 57414                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 415                                {
 53416                                    result.Append(" - ").Append(tag);
 417                                }
 418                            }
 419
 20420                            return result.ToString();
 421                        }
 422
 10423                        return string.Join(" - ", attributes);
 424                    }
 425
 426                    default:
 0427                        return null;
 428                }
 429            }
 430        }
 431
 432        public string NalLengthSize { get; set; }
 433
 434        /// <summary>
 435        /// Gets or sets a value indicating whether this instance is interlaced.
 436        /// </summary>
 437        /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
 438        public bool IsInterlaced { get; set; }
 439
 440        public bool? IsAVC { get; set; }
 441
 442        /// <summary>
 443        /// Gets or sets the channel layout.
 444        /// </summary>
 445        /// <value>The channel layout.</value>
 446        public string ChannelLayout { get; set; }
 447
 448        /// <summary>
 449        /// Gets or sets the bit rate.
 450        /// </summary>
 451        /// <value>The bit rate.</value>
 452        public int? BitRate { get; set; }
 453
 454        /// <summary>
 455        /// Gets or sets the bit depth.
 456        /// </summary>
 457        /// <value>The bit depth.</value>
 458        public int? BitDepth { get; set; }
 459
 460        /// <summary>
 461        /// Gets or sets the reference frames.
 462        /// </summary>
 463        /// <value>The reference frames.</value>
 464        public int? RefFrames { get; set; }
 465
 466        /// <summary>
 467        /// Gets or sets the length of the packet.
 468        /// </summary>
 469        /// <value>The length of the packet.</value>
 470        public int? PacketLength { get; set; }
 471
 472        /// <summary>
 473        /// Gets or sets the channels.
 474        /// </summary>
 475        /// <value>The channels.</value>
 476        public int? Channels { get; set; }
 477
 478        /// <summary>
 479        /// Gets or sets the sample rate.
 480        /// </summary>
 481        /// <value>The sample rate.</value>
 482        public int? SampleRate { get; set; }
 483
 484        /// <summary>
 485        /// Gets or sets a value indicating whether this instance is default.
 486        /// </summary>
 487        /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
 488        public bool IsDefault { get; set; }
 489
 490        /// <summary>
 491        /// Gets or sets a value indicating whether this instance is forced.
 492        /// </summary>
 493        /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
 494        public bool IsForced { get; set; }
 495
 496        /// <summary>
 497        /// Gets or sets a value indicating whether this instance is for the hearing impaired.
 498        /// </summary>
 499        /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
 500        public bool IsHearingImpaired { get; set; }
 501
 502        /// <summary>
 503        /// Gets or sets the height.
 504        /// </summary>
 505        /// <value>The height.</value>
 506        public int? Height { get; set; }
 507
 508        /// <summary>
 509        /// Gets or sets the width.
 510        /// </summary>
 511        /// <value>The width.</value>
 512        public int? Width { get; set; }
 513
 514        /// <summary>
 515        /// Gets or sets the average frame rate.
 516        /// </summary>
 517        /// <value>The average frame rate.</value>
 518        public float? AverageFrameRate { get; set; }
 519
 520        /// <summary>
 521        /// Gets or sets the real frame rate.
 522        /// </summary>
 523        /// <value>The real frame rate.</value>
 524        public float? RealFrameRate { get; set; }
 525
 526        /// <summary>
 527        /// Gets the framerate used as reference.
 528        /// Prefer AverageFrameRate, if that is null or an unrealistic value
 529        /// then fallback to RealFrameRate.
 530        /// </summary>
 531        /// <value>The reference frame rate.</value>
 532        public float? ReferenceFrameRate
 533        {
 534            get
 535            {
 536                // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not.
 537                // This is probably due to a library compatibility issue.
 538                // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info.
 1054539                return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate;
 540            }
 541        }
 542
 543        /// <summary>
 544        /// Gets or sets the profile.
 545        /// </summary>
 546        /// <value>The profile.</value>
 547        public string Profile { get; set; }
 548
 549        /// <summary>
 550        /// Gets or sets the type.
 551        /// </summary>
 552        /// <value>The type.</value>
 553        public MediaStreamType Type { get; set; }
 554
 555        /// <summary>
 556        /// Gets or sets the aspect ratio.
 557        /// </summary>
 558        /// <value>The aspect ratio.</value>
 559        public string AspectRatio { get; set; }
 560
 561        /// <summary>
 562        /// Gets or sets the index.
 563        /// </summary>
 564        /// <value>The index.</value>
 565        public int Index { get; set; }
 566
 567        /// <summary>
 568        /// Gets or sets the score.
 569        /// </summary>
 570        /// <value>The score.</value>
 571        public int? Score { get; set; }
 572
 573        /// <summary>
 574        /// Gets or sets a value indicating whether this instance is external.
 575        /// </summary>
 576        /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
 577        public bool IsExternal { get; set; }
 578
 579        /// <summary>
 580        /// Gets or sets the method.
 581        /// </summary>
 582        /// <value>The method.</value>
 583        public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
 584
 585        /// <summary>
 586        /// Gets or sets the delivery URL.
 587        /// </summary>
 588        /// <value>The delivery URL.</value>
 589        public string DeliveryUrl { get; set; }
 590
 591        /// <summary>
 592        /// Gets or sets a value indicating whether this instance is external URL.
 593        /// </summary>
 594        /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f
 595        public bool? IsExternalUrl { get; set; }
 596
 597        public bool IsTextSubtitleStream
 598        {
 599            get
 600            {
 2056601                if (Type != MediaStreamType.Subtitle)
 602                {
 51603                    return false;
 604                }
 605
 2005606                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 607                {
 30608                    return false;
 609                }
 610
 1975611                return IsTextFormat(Codec);
 612            }
 613        }
 614
 615        [JsonIgnore]
 616        public bool IsPgsSubtitleStream
 617        {
 618            get
 619            {
 64620                if (Type != MediaStreamType.Subtitle)
 621                {
 28622                    return false;
 623                }
 624
 36625                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 626                {
 30627                    return false;
 628                }
 629
 6630                return IsPgsFormat(Codec);
 631            }
 632        }
 633
 634        /// <summary>
 635        /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg.
 636        /// All text-based and pgs subtitles can be extracted.
 637        /// </summary>
 638        /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value>
 639        [JsonIgnore]
 35640        public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream;
 641
 642        /// <summary>
 643        /// Gets or sets a value indicating whether [supports external stream].
 644        /// </summary>
 645        /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
 646        public bool SupportsExternalStream { get; set; }
 647
 648        /// <summary>
 649        /// Gets or sets the filename.
 650        /// </summary>
 651        /// <value>The filename.</value>
 652        public string Path { get; set; }
 653
 654        /// <summary>
 655        /// Gets or sets the pixel format.
 656        /// </summary>
 657        /// <value>The pixel format.</value>
 658        public string PixelFormat { get; set; }
 659
 660        /// <summary>
 661        /// Gets or sets the level.
 662        /// </summary>
 663        /// <value>The level.</value>
 664        public double? Level { get; set; }
 665
 666        /// <summary>
 667        /// Gets or sets whether this instance is anamorphic.
 668        /// </summary>
 669        /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
 670        public bool? IsAnamorphic { get; set; }
 671
 672        internal string GetResolutionText()
 673        {
 73674            if (!Width.HasValue || !Height.HasValue)
 675            {
 3676                return null;
 677            }
 678
 70679            return Width switch
 70680            {
 70681                // 256x144 (16:9 square pixel format)
 4682                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70683                // 426x240 (16:9 square pixel format)
 4684                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70685                // 640x360 (16:9 square pixel format)
 14686                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70687                // 682x384 (16:9 square pixel format)
 3688                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70689                // 720x404 (16:9 square pixel format)
 7690                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70691                // 854x480 (16:9 square pixel format)
 10692                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70693                // 960x544 (16:9 square pixel format)
 11694                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70695                // 1024x576 (16:9 square pixel format)
 9696                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70697                // 1280x720
 26698                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70699                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46700                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70701                // 4K
 12702                <= 4096 when Height <= 3072 => "4K",
 70703                // 8K
 6704                <= 8192 when Height <= 6144 => "8K",
 0705                _ => null
 70706            };
 707        }
 708
 709        public static bool IsTextFormat(string format)
 710        {
 3377711            string codec = format ?? string.Empty;
 712
 713            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 714
 3377715            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3377716                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3377717                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3377718                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3377719                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3377720                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 721        }
 722
 723        public static bool IsPgsFormat(string format)
 724        {
 10725            string codec = format ?? string.Empty;
 726
 10727            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 10728                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 729        }
 730
 731        public bool SupportsSubtitleConversionTo(string toCodec)
 732        {
 286733            if (!IsTextSubtitleStream)
 734            {
 0735                return false;
 736            }
 737
 286738            var fromCodec = Codec;
 739
 740            // Can't convert from this
 286741            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 742            {
 0743                return false;
 744            }
 745
 286746            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 747            {
 0748                return false;
 749            }
 750
 751            // Can't convert to this
 286752            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 753            {
 0754                return false;
 755            }
 756
 286757            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 758            {
 0759                return false;
 760            }
 761
 286762            return true;
 763        }
 764
 765        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 766        {
 944767            if (Type != MediaStreamType.Video)
 768            {
 70769                return (VideoRange.Unknown, VideoRangeType.Unknown);
 770            }
 771
 874772            var codecTag = CodecTag;
 874773            var dvProfile = DvProfile;
 874774            var rpuPresentFlag = RpuPresentFlag == 1;
 874775            var blPresentFlag = BlPresentFlag == 1;
 874776            var dvBlCompatId = DvBlSignalCompatibilityId;
 777
 874778            var isDoViProfile = dvProfile is 5 or 7 or 8 or 10;
 874779            var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6;
 780
 874781            if ((isDoViProfile && isDoViFlag)
 874782                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 874783                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 874784                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 874785                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 786            {
 115787                var dvRangeSet = dvProfile switch
 115788                {
 64789                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 51790                    8 => dvBlCompatId switch
 51791                    {
 51792                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0793                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0794                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 51795                        // Out of Dolby Spec files should be marked as invalid
 0796                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 51797                    },
 0798                    7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL),
 0799                    10 => dvBlCompatId switch
 0800                    {
 0801                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0802                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0803                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0804                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0805                        // Out of Dolby Spec files should be marked as invalid
 0806                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 0807                    },
 0808                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 115809                };
 810
 115811                if (Hdr10PlusPresentFlag == true)
 812                {
 0813                    return dvRangeSet.Item2 switch
 0814                    {
 0815                        VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus),
 0816                        VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus),
 0817                        _ => dvRangeSet
 0818                    };
 819                }
 820
 115821                return dvRangeSet;
 822            }
 823
 759824            var colorTransfer = ColorTransfer;
 825
 759826            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 827            {
 198828                return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide
 829            }
 561830            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 831            {
 0832                return (VideoRange.HDR, VideoRangeType.HLG);
 833            }
 834
 561835            return (VideoRange.SDR, VideoRangeType.SDR);
 836        }
 837    }
 838}