< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Entities.MediaStream
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs
Line coverage
75%
Covered lines: 170
Uncovered lines: 56
Coverable lines: 226
Total lines: 833
Line coverage: 75.2%
Branch coverage
66%
Covered branches: 193
Total branches: 291
Branch coverage: 66.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_VideoRange()100%11100%
get_VideoRangeType()100%11100%
get_VideoDoViTitle()8%85.22554.16%
get_AudioSpatialFormat()87.5%88100%
get_DisplayTitle()57.31%468.118261.42%
get_ReferenceFrameRate()100%22100%
get_IsTextSubtitleStream()100%66100%
get_IsPgsSubtitleStream()100%66100%
get_IsExtractableSubtitleStream()100%22100%
GetResolutionText()93.24%74.27496.66%
IsTextFormat(...)50%1212100%
IsPgsFormat(...)50%44100%
SupportsSubtitleConversionTo(...)50%17.241058.33%
GetVideoColorRange()55%262.256061.7%

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    {
 124        private static readonly string[] _specialCodes =
 125        {
 126            // Uncoded languages.
 127            "mis",
 128            // Multiple languages.
 129            "mul",
 130            // Undetermined.
 131            "und",
 132            // No linguistic content; not applicable.
 133            "zxx"
 134        };
 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            {
 32164                var (videoRange, _) = GetVideoColorRange();
 165
 32166                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            {
 840178                var (_, videoRangeType) = GetVideoColorRange();
 179
 840180                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            {
 32192                var dvProfile = DvProfile;
 32193                var rpuPresentFlag = RpuPresentFlag == 1;
 32194                var blPresentFlag = BlPresentFlag == 1;
 32195                var dvBlCompatId = DvBlSignalCompatibilityId;
 196
 32197                if (rpuPresentFlag
 32198                    && blPresentFlag
 32199                    && (dvProfile == 4
 32200                        || dvProfile == 5
 32201                        || dvProfile == 7
 32202                        || dvProfile == 8
 32203                        || dvProfile == 9
 32204                        || dvProfile == 10))
 205                {
 0206                    var title = "Dolby Vision Profile " + dvProfile;
 207
 0208                    if (dvBlCompatId > 0)
 209                    {
 0210                        title += "." + dvBlCompatId;
 211                    }
 212
 0213                    return dvBlCompatId switch
 0214                    {
 0215                        1 => title + " (HDR10)",
 0216                        2 => title + " (SDR)",
 0217                        4 => title + " (HLG)",
 0218                        6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10
 0219                        _ => title
 0220                    };
 221                }
 222
 32223                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            {
 34236                if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
 237                {
 32238                    return AudioSpatialFormat.None;
 239                }
 240
 2241                return
 2242                    Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos 
 2243                    Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
 2244                    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            {
 40262                switch (Type)
 263                {
 264                    case MediaStreamType.Audio:
 265                    {
 14266                        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
 14269                        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 
 3272                            string fullLanguage = CultureInfo
 3273                                .GetCultures(CultureTypes.NeutralCultures)
 3274                                .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi
 3275                                ?.DisplayName;
 3276                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 277                        }
 278
 14279                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 280                        {
 0281                            attributes.Add(Profile);
 282                        }
 14283                        else if (!string.IsNullOrEmpty(Codec))
 284                        {
 2285                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 286                        }
 287
 14288                        if (!string.IsNullOrEmpty(ChannelLayout))
 289                        {
 0290                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 291                        }
 14292                        else if (Channels.HasValue)
 293                        {
 0294                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 295                        }
 296
 14297                        if (IsDefault)
 298                        {
 4299                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 300                        }
 301
 14302                        if (IsExternal)
 303                        {
 8304                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 305                        }
 306
 14307                        if (!string.IsNullOrEmpty(Title))
 308                        {
 2309                            var result = new StringBuilder(Title);
 16310                            foreach (var tag in attributes)
 311                            {
 312                                // Keep Tags that are not already in Title.
 6313                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 314                                {
 6315                                    result.Append(" - ").Append(tag);
 316                                }
 317                            }
 318
 2319                            return result.ToString();
 320                        }
 321
 12322                        return string.Join(" - ", attributes);
 323                    }
 324
 325                    case MediaStreamType.Video:
 326                    {
 0327                        var attributes = new List<string>();
 328
 0329                        var resolutionText = GetResolutionText();
 330
 0331                        if (!string.IsNullOrEmpty(resolutionText))
 332                        {
 0333                            attributes.Add(resolutionText);
 334                        }
 335
 0336                        if (!string.IsNullOrEmpty(Codec))
 337                        {
 0338                            attributes.Add(Codec.ToUpperInvariant());
 339                        }
 340
 0341                        if (VideoDoViTitle is not null)
 342                        {
 0343                            attributes.Add(VideoDoViTitle);
 344                        }
 0345                        else if (VideoRange != VideoRange.Unknown)
 346                        {
 0347                            attributes.Add(VideoRange.ToString());
 348                        }
 349
 0350                        if (!string.IsNullOrEmpty(Title))
 351                        {
 0352                            var result = new StringBuilder(Title);
 0353                            foreach (var tag in attributes)
 354                            {
 355                                // Keep Tags that are not already in Title.
 0356                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 357                                {
 0358                                    result.Append(" - ").Append(tag);
 359                                }
 360                            }
 361
 0362                            return result.ToString();
 363                        }
 364
 0365                        return string.Join(' ', attributes);
 366                    }
 367
 368                    case MediaStreamType.Subtitle:
 369                    {
 26370                        var attributes = new List<string>();
 371
 26372                        if (!string.IsNullOrEmpty(Language))
 373                        {
 374                            // Get full language string i.e. eng -> English. Will not work for some languages which use 
 16375                            string fullLanguage = CultureInfo
 16376                                .GetCultures(CultureTypes.NeutralCultures)
 16377                                .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi
 16378                                ?.DisplayName;
 16379                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 380                        }
 381                        else
 382                        {
 10383                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 384                        }
 385
 26386                        if (IsHearingImpaired)
 387                        {
 6388                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 389                        }
 390
 26391                        if (IsDefault)
 392                        {
 12393                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 394                        }
 395
 26396                        if (IsForced)
 397                        {
 12398                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 399                        }
 400
 26401                        if (!string.IsNullOrEmpty(Codec))
 402                        {
 8403                            attributes.Add(Codec.ToUpperInvariant());
 404                        }
 405
 26406                        if (IsExternal)
 407                        {
 2408                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 409                        }
 410
 26411                        if (!string.IsNullOrEmpty(Title))
 412                        {
 20413                            var result = new StringBuilder(Title);
 156414                            foreach (var tag in attributes)
 415                            {
 416                                // Keep Tags that are not already in Title.
 58417                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 418                                {
 54419                                    result.Append(" - ").Append(tag);
 420                                }
 421                            }
 422
 20423                            return result.ToString();
 424                        }
 425
 6426                        return string.Join(" - ", attributes);
 427                    }
 428
 429                    default:
 0430                        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.
 696542                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            {
 1969604                if (Type != MediaStreamType.Subtitle)
 605                {
 49606                    return false;
 607                }
 608
 1920609                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 610                {
 30611                    return false;
 612                }
 613
 1890614                return IsTextFormat(Codec);
 615            }
 616        }
 617
 618        [JsonIgnore]
 619        public bool IsPgsSubtitleStream
 620        {
 621            get
 622            {
 60623                if (Type != MediaStreamType.Subtitle)
 624                {
 26625                    return false;
 626                }
 627
 34628                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 629                {
 30630                    return false;
 631                }
 632
 4633                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]
 32643        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        {
 73677            if (!Width.HasValue || !Height.HasValue)
 678            {
 3679                return null;
 680            }
 681
 70682            return Width switch
 70683            {
 70684                // 256x144 (16:9 square pixel format)
 4685                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70686                // 426x240 (16:9 square pixel format)
 4687                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70688                // 640x360 (16:9 square pixel format)
 14689                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70690                // 682x384 (16:9 square pixel format)
 3691                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70692                // 720x404 (16:9 square pixel format)
 7693                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70694                // 854x480 (16:9 square pixel format)
 10695                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70696                // 960x544 (16:9 square pixel format)
 11697                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70698                // 1024x576 (16:9 square pixel format)
 9699                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70700                // 1280x720
 26701                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70702                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46703                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70704                // 4K
 12705                <= 4096 when Height <= 3072 => "4K",
 70706                // 8K
 6707                <= 8192 when Height <= 6144 => "8K",
 0708                _ => null
 70709            };
 710        }
 711
 712        public static bool IsTextFormat(string format)
 713        {
 3224714            string codec = format ?? string.Empty;
 715
 716            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 717
 3224718            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3224719                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3224720                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3224721                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3224722                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3224723                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 724        }
 725
 726        public static bool IsPgsFormat(string format)
 727        {
 8728            string codec = format ?? string.Empty;
 729
 8730            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 8731                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 732        }
 733
 734        public bool SupportsSubtitleConversionTo(string toCodec)
 735        {
 274736            if (!IsTextSubtitleStream)
 737            {
 0738                return false;
 739            }
 740
 274741            var fromCodec = Codec;
 742
 743            // Can't convert from this
 274744            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 745            {
 0746                return false;
 747            }
 748
 274749            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 750            {
 0751                return false;
 752            }
 753
 754            // Can't convert to this
 274755            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 756            {
 0757                return false;
 758            }
 759
 274760            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 761            {
 0762                return false;
 763            }
 764
 274765            return true;
 766        }
 767
 768        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 769        {
 872770            if (Type != MediaStreamType.Video)
 771            {
 64772                return (VideoRange.Unknown, VideoRangeType.Unknown);
 773            }
 774
 808775            var codecTag = CodecTag;
 808776            var dvProfile = DvProfile;
 808777            var rpuPresentFlag = RpuPresentFlag == 1;
 808778            var blPresentFlag = BlPresentFlag == 1;
 808779            var dvBlCompatId = DvBlSignalCompatibilityId;
 780
 808781            var isDoViProfile = dvProfile == 5 || dvProfile == 7 || dvProfile == 8 || dvProfile == 10;
 808782            var isDoViFlag = rpuPresentFlag && blPresentFlag && (dvBlCompatId == 0 || dvBlCompatId == 1 || dvBlCompatId 
 783
 808784            if ((isDoViProfile && isDoViFlag)
 808785                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 808786                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 808787                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 808788                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 789            {
 67790                return dvProfile switch
 67791                {
 30792                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 37793                    8 => dvBlCompatId switch
 37794                    {
 37795                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0796                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0797                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 37798                        // While not in Dolby Spec, Profile 8 CCid 6 media are possible to create, and since CCid 6 stem
 0799                        6 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 37800                        // There is no other case to handle here as per Dolby Spec. Default case included for completene
 0801                        _ => (VideoRange.SDR, VideoRangeType.SDR)
 37802                    },
 0803                    7 => (VideoRange.HDR, VideoRangeType.HDR10),
 0804                    10 => dvBlCompatId switch
 0805                    {
 0806                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0807                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0808                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0809                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0810                        // While not in Dolby Spec, Profile 8 CCid 6 media are possible to create, and since CCid 6 stem
 0811                        6 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0812                        // There is no other case to handle here as per Dolby Spec. Default case included for completene
 0813                        _ => (VideoRange.SDR, VideoRangeType.SDR)
 0814                    },
 0815                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 67816                };
 817            }
 818
 741819            var colorTransfer = ColorTransfer;
 820
 741821            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 822            {
 185823                return (VideoRange.HDR, VideoRangeType.HDR10);
 824            }
 556825            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 826            {
 0827                return (VideoRange.HDR, VideoRangeType.HLG);
 828            }
 829
 556830            return (VideoRange.SDR, VideoRangeType.SDR);
 831        }
 832    }
 833}