< 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: 840
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 10/25/2025 - 12:09:58 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: 840 10/25/2025 - 12:09:58 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: 840

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.Frozen;
 6using System.Collections.Generic;
 7using System.ComponentModel;
 8using System.Globalization;
 9using System.Linq;
 10using System.Text;
 11using System.Text.Json.Serialization;
 12using Jellyfin.Data.Enums;
 13using Jellyfin.Extensions;
 14using MediaBrowser.Model.Dlna;
 15using MediaBrowser.Model.Extensions;
 16using MediaBrowser.Model.MediaInfo;
 17
 18namespace MediaBrowser.Model.Entities
 19{
 20    /// <summary>
 21    /// Class MediaStream.
 22    /// </summary>
 23    public class MediaStream
 24    {
 225        private static readonly string[] _specialCodes =
 226        {
 227            // Uncoded languages.
 228            "mis",
 229            // Multiple languages.
 230            "mul",
 231            // Undetermined.
 232            "und",
 233            // No linguistic content; not applicable.
 234            "zxx"
 235        };
 36
 37        /// <summary>
 38        /// Gets or sets the codec.
 39        /// </summary>
 40        /// <value>The codec.</value>
 41        public string Codec { get; set; }
 42
 43        /// <summary>
 44        /// Gets or sets the codec tag.
 45        /// </summary>
 46        /// <value>The codec tag.</value>
 47        public string CodecTag { get; set; }
 48
 49        /// <summary>
 50        /// Gets or sets the language.
 51        /// </summary>
 52        /// <value>The language.</value>
 53        public string Language { get; set; }
 54
 55        /// <summary>
 56        /// Gets or sets the color range.
 57        /// </summary>
 58        /// <value>The color range.</value>
 59        public string ColorRange { get; set; }
 60
 61        /// <summary>
 62        /// Gets or sets the color space.
 63        /// </summary>
 64        /// <value>The color space.</value>
 65        public string ColorSpace { get; set; }
 66
 67        /// <summary>
 68        /// Gets or sets the color transfer.
 69        /// </summary>
 70        /// <value>The color transfer.</value>
 71        public string ColorTransfer { get; set; }
 72
 73        /// <summary>
 74        /// Gets or sets the color primaries.
 75        /// </summary>
 76        /// <value>The color primaries.</value>
 77        public string ColorPrimaries { get; set; }
 78
 79        /// <summary>
 80        /// Gets or sets the Dolby Vision version major.
 81        /// </summary>
 82        /// <value>The Dolby Vision version major.</value>
 83        public int? DvVersionMajor { get; set; }
 84
 85        /// <summary>
 86        /// Gets or sets the Dolby Vision version minor.
 87        /// </summary>
 88        /// <value>The Dolby Vision version minor.</value>
 89        public int? DvVersionMinor { get; set; }
 90
 91        /// <summary>
 92        /// Gets or sets the Dolby Vision profile.
 93        /// </summary>
 94        /// <value>The Dolby Vision profile.</value>
 95        public int? DvProfile { get; set; }
 96
 97        /// <summary>
 98        /// Gets or sets the Dolby Vision level.
 99        /// </summary>
 100        /// <value>The Dolby Vision level.</value>
 101        public int? DvLevel { get; set; }
 102
 103        /// <summary>
 104        /// Gets or sets the Dolby Vision rpu present flag.
 105        /// </summary>
 106        /// <value>The Dolby Vision rpu present flag.</value>
 107        public int? RpuPresentFlag { get; set; }
 108
 109        /// <summary>
 110        /// Gets or sets the Dolby Vision el present flag.
 111        /// </summary>
 112        /// <value>The Dolby Vision el present flag.</value>
 113        public int? ElPresentFlag { get; set; }
 114
 115        /// <summary>
 116        /// Gets or sets the Dolby Vision bl present flag.
 117        /// </summary>
 118        /// <value>The Dolby Vision bl present flag.</value>
 119        public int? BlPresentFlag { get; set; }
 120
 121        /// <summary>
 122        /// Gets or sets the Dolby Vision bl signal compatibility id.
 123        /// </summary>
 124        /// <value>The Dolby Vision bl signal compatibility id.</value>
 125        public int? DvBlSignalCompatibilityId { get; set; }
 126
 127        /// <summary>
 128        /// Gets or sets the Rotation in degrees.
 129        /// </summary>
 130        /// <value>The video rotation.</value>
 131        public int? Rotation { get; set; }
 132
 133        /// <summary>
 134        /// Gets or sets the comment.
 135        /// </summary>
 136        /// <value>The comment.</value>
 137        public string Comment { get; set; }
 138
 139        /// <summary>
 140        /// Gets or sets the time base.
 141        /// </summary>
 142        /// <value>The time base.</value>
 143        public string TimeBase { get; set; }
 144
 145        /// <summary>
 146        /// Gets or sets the codec time base.
 147        /// </summary>
 148        /// <value>The codec time base.</value>
 149        public string CodecTimeBase { get; set; }
 150
 151        /// <summary>
 152        /// Gets or sets the title.
 153        /// </summary>
 154        /// <value>The title.</value>
 155        public string Title { get; set; }
 156
 157        public bool? Hdr10PlusPresentFlag { get; set; }
 158
 159        /// <summary>
 160        /// Gets the video range.
 161        /// </summary>
 162        /// <value>The video range.</value>
 163        [DefaultValue(VideoRange.Unknown)]
 164        public VideoRange VideoRange
 165        {
 166            get
 167            {
 35168                var (videoRange, _) = GetVideoColorRange();
 169
 35170                return videoRange;
 171            }
 172        }
 173
 174        /// <summary>
 175        /// Gets the video range type.
 176        /// </summary>
 177        /// <value>The video range type.</value>
 178        [DefaultValue(VideoRangeType.Unknown)]
 179        public VideoRangeType VideoRangeType
 180        {
 181            get
 182            {
 909183                var (_, videoRangeType) = GetVideoColorRange();
 184
 909185                return videoRangeType;
 186            }
 187        }
 188
 189        /// <summary>
 190        /// Gets the video dovi title.
 191        /// </summary>
 192        /// <value>The video dovi title.</value>
 193        public string VideoDoViTitle
 194        {
 195            get
 196            {
 35197                var dvProfile = DvProfile;
 35198                var rpuPresentFlag = RpuPresentFlag == 1;
 35199                var blPresentFlag = BlPresentFlag == 1;
 35200                var dvBlCompatId = DvBlSignalCompatibilityId;
 201
 35202                if (rpuPresentFlag
 35203                    && blPresentFlag
 35204                    && (dvProfile == 4
 35205                        || dvProfile == 5
 35206                        || dvProfile == 7
 35207                        || dvProfile == 8
 35208                        || dvProfile == 9
 35209                        || dvProfile == 10))
 210                {
 0211                    var title = "Dolby Vision Profile " + dvProfile;
 212
 0213                    if (dvBlCompatId > 0)
 214                    {
 0215                        title += "." + dvBlCompatId;
 216                    }
 217
 0218                    return dvBlCompatId switch
 0219                    {
 0220                        1 => title + " (HDR10)",
 0221                        2 => title + " (SDR)",
 0222                        4 => title + " (HLG)",
 0223                        6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10
 0224                        _ => title
 0225                    };
 226                }
 227
 35228                return null;
 229            }
 230        }
 231
 232        /// <summary>
 233        /// Gets the audio spatial format.
 234        /// </summary>
 235        /// <value>The audio spatial format.</value>
 236        [DefaultValue(AudioSpatialFormat.None)]
 237        public AudioSpatialFormat AudioSpatialFormat
 238        {
 239            get
 240            {
 37241                if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
 242                {
 35243                    return AudioSpatialFormat.None;
 244                }
 245
 2246                return
 2247                    Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos 
 2248                    Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
 2249                    AudioSpatialFormat.None;
 250            }
 251        }
 252
 253        public string LocalizedUndefined { get; set; }
 254
 255        public string LocalizedDefault { get; set; }
 256
 257        public string LocalizedForced { get; set; }
 258
 259        public string LocalizedExternal { get; set; }
 260
 261        public string LocalizedHearingImpaired { get; set; }
 262
 263        public string LocalizedLanguage { get; set; }
 264
 265        public string DisplayTitle
 266        {
 267            get
 268            {
 46269                switch (Type)
 270                {
 271                    case MediaStreamType.Audio:
 272                    {
 16273                        var attributes = new List<string>();
 274
 275                        // Do not display the language code in display titles if unset or set to a special code. Show it
 16276                        if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.Ordina
 277                        {
 278                            // Use pre-resolved localized language name, falling back to raw language code.
 5279                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 280                        }
 281
 16282                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 283                        {
 0284                            attributes.Add(Profile);
 285                        }
 16286                        else if (!string.IsNullOrEmpty(Codec))
 287                        {
 4288                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 289                        }
 290
 16291                        if (!string.IsNullOrEmpty(ChannelLayout))
 292                        {
 2293                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 294                        }
 14295                        else if (Channels.HasValue)
 296                        {
 0297                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 298                        }
 299
 16300                        if (IsDefault)
 301                        {
 4302                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 303                        }
 304
 16305                        if (IsExternal)
 306                        {
 8307                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 308                        }
 309
 16310                        if (!string.IsNullOrEmpty(Title))
 311                        {
 2312                            var result = new StringBuilder(Title);
 16313                            foreach (var tag in attributes)
 314                            {
 315                                // Keep Tags that are not already in Title.
 6316                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 317                                {
 6318                                    result.Append(" - ").Append(tag);
 319                                }
 320                            }
 321
 2322                            return result.ToString();
 323                        }
 324
 14325                        return string.Join(" - ", attributes);
 326                    }
 327
 328                    case MediaStreamType.Video:
 329                    {
 0330                        var attributes = new List<string>();
 331
 0332                        var resolutionText = GetResolutionText();
 333
 0334                        if (!string.IsNullOrEmpty(resolutionText))
 335                        {
 0336                            attributes.Add(resolutionText);
 337                        }
 338
 0339                        if (!string.IsNullOrEmpty(Codec))
 340                        {
 0341                            attributes.Add(Codec.ToUpperInvariant());
 342                        }
 343
 0344                        if (VideoDoViTitle is not null)
 345                        {
 0346                            attributes.Add(VideoDoViTitle);
 347                        }
 0348                        else if (VideoRange != VideoRange.Unknown)
 349                        {
 0350                            attributes.Add(VideoRange.ToString());
 351                        }
 352
 0353                        if (!string.IsNullOrEmpty(Title))
 354                        {
 0355                            var result = new StringBuilder(Title);
 0356                            foreach (var tag in attributes)
 357                            {
 358                                // Keep Tags that are not already in Title.
 0359                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 360                                {
 0361                                    result.Append(" - ").Append(tag);
 362                                }
 363                            }
 364
 0365                            return result.ToString();
 366                        }
 367
 0368                        return string.Join(' ', attributes);
 369                    }
 370
 371                    case MediaStreamType.Subtitle:
 372                    {
 30373                        var attributes = new List<string>();
 374
 30375                        if (!string.IsNullOrEmpty(Language))
 376                        {
 377                            // Use pre-resolved localized language name, falling back to raw language code.
 20378                            attributes.Add(StringHelper.FirstToUpper(LocalizedLanguage ?? Language));
 379                        }
 380                        else
 381                        {
 10382                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 383                        }
 384
 30385                        if (IsHearingImpaired == true)
 386                        {
 6387                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 388                        }
 389
 30390                        if (IsDefault)
 391                        {
 11392                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 393                        }
 394
 30395                        if (IsForced)
 396                        {
 12397                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 398                        }
 399
 30400                        if (!string.IsNullOrEmpty(Codec))
 401                        {
 12402                            attributes.Add(Codec.ToUpperInvariant());
 403                        }
 404
 30405                        if (IsExternal)
 406                        {
 2407                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 408                        }
 409
 30410                        if (!string.IsNullOrEmpty(Title))
 411                        {
 20412                            var result = new StringBuilder(Title);
 154413                            foreach (var tag in attributes)
 414                            {
 415                                // Keep Tags that are not already in Title.
 57416                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 417                                {
 53418                                    result.Append(" - ").Append(tag);
 419                                }
 420                            }
 421
 20422                            return result.ToString();
 423                        }
 424
 10425                        return string.Join(" - ", attributes);
 426                    }
 427
 428                    default:
 0429                        return null;
 430                }
 431            }
 432        }
 433
 434        public string NalLengthSize { get; set; }
 435
 436        /// <summary>
 437        /// Gets or sets a value indicating whether this instance is interlaced.
 438        /// </summary>
 439        /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
 440        public bool IsInterlaced { get; set; }
 441
 442        public bool? IsAVC { get; set; }
 443
 444        /// <summary>
 445        /// Gets or sets the channel layout.
 446        /// </summary>
 447        /// <value>The channel layout.</value>
 448        public string ChannelLayout { get; set; }
 449
 450        /// <summary>
 451        /// Gets or sets the bit rate.
 452        /// </summary>
 453        /// <value>The bit rate.</value>
 454        public int? BitRate { get; set; }
 455
 456        /// <summary>
 457        /// Gets or sets the bit depth.
 458        /// </summary>
 459        /// <value>The bit depth.</value>
 460        public int? BitDepth { get; set; }
 461
 462        /// <summary>
 463        /// Gets or sets the reference frames.
 464        /// </summary>
 465        /// <value>The reference frames.</value>
 466        public int? RefFrames { get; set; }
 467
 468        /// <summary>
 469        /// Gets or sets the length of the packet.
 470        /// </summary>
 471        /// <value>The length of the packet.</value>
 472        public int? PacketLength { get; set; }
 473
 474        /// <summary>
 475        /// Gets or sets the channels.
 476        /// </summary>
 477        /// <value>The channels.</value>
 478        public int? Channels { get; set; }
 479
 480        /// <summary>
 481        /// Gets or sets the sample rate.
 482        /// </summary>
 483        /// <value>The sample rate.</value>
 484        public int? SampleRate { get; set; }
 485
 486        /// <summary>
 487        /// Gets or sets a value indicating whether this instance is default.
 488        /// </summary>
 489        /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
 490        public bool IsDefault { get; set; }
 491
 492        /// <summary>
 493        /// Gets or sets a value indicating whether this instance is forced.
 494        /// </summary>
 495        /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
 496        public bool IsForced { get; set; }
 497
 498        /// <summary>
 499        /// Gets or sets a value indicating whether this instance is for the hearing impaired.
 500        /// </summary>
 501        /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
 502        public bool IsHearingImpaired { get; set; }
 503
 504        /// <summary>
 505        /// Gets or sets the height.
 506        /// </summary>
 507        /// <value>The height.</value>
 508        public int? Height { get; set; }
 509
 510        /// <summary>
 511        /// Gets or sets the width.
 512        /// </summary>
 513        /// <value>The width.</value>
 514        public int? Width { get; set; }
 515
 516        /// <summary>
 517        /// Gets or sets the average frame rate.
 518        /// </summary>
 519        /// <value>The average frame rate.</value>
 520        public float? AverageFrameRate { get; set; }
 521
 522        /// <summary>
 523        /// Gets or sets the real frame rate.
 524        /// </summary>
 525        /// <value>The real frame rate.</value>
 526        public float? RealFrameRate { get; set; }
 527
 528        /// <summary>
 529        /// Gets the framerate used as reference.
 530        /// Prefer AverageFrameRate, if that is null or an unrealistic value
 531        /// then fallback to RealFrameRate.
 532        /// </summary>
 533        /// <value>The reference frame rate.</value>
 534        public float? ReferenceFrameRate
 535        {
 536            get
 537            {
 538                // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not.
 539                // This is probably due to a library compatibility issue.
 540                // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info.
 1054541                return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate;
 542            }
 543        }
 544
 545        /// <summary>
 546        /// Gets or sets the profile.
 547        /// </summary>
 548        /// <value>The profile.</value>
 549        public string Profile { get; set; }
 550
 551        /// <summary>
 552        /// Gets or sets the type.
 553        /// </summary>
 554        /// <value>The type.</value>
 555        public MediaStreamType Type { get; set; }
 556
 557        /// <summary>
 558        /// Gets or sets the aspect ratio.
 559        /// </summary>
 560        /// <value>The aspect ratio.</value>
 561        public string AspectRatio { get; set; }
 562
 563        /// <summary>
 564        /// Gets or sets the index.
 565        /// </summary>
 566        /// <value>The index.</value>
 567        public int Index { get; set; }
 568
 569        /// <summary>
 570        /// Gets or sets the score.
 571        /// </summary>
 572        /// <value>The score.</value>
 573        public int? Score { get; set; }
 574
 575        /// <summary>
 576        /// Gets or sets a value indicating whether this instance is external.
 577        /// </summary>
 578        /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
 579        public bool IsExternal { get; set; }
 580
 581        /// <summary>
 582        /// Gets or sets the method.
 583        /// </summary>
 584        /// <value>The method.</value>
 585        public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
 586
 587        /// <summary>
 588        /// Gets or sets the delivery URL.
 589        /// </summary>
 590        /// <value>The delivery URL.</value>
 591        public string DeliveryUrl { get; set; }
 592
 593        /// <summary>
 594        /// Gets or sets a value indicating whether this instance is external URL.
 595        /// </summary>
 596        /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f
 597        public bool? IsExternalUrl { get; set; }
 598
 599        public bool IsTextSubtitleStream
 600        {
 601            get
 602            {
 2047603                if (Type != MediaStreamType.Subtitle)
 604                {
 51605                    return false;
 606                }
 607
 1996608                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 609                {
 30610                    return false;
 611                }
 612
 1966613                return IsTextFormat(Codec);
 614            }
 615        }
 616
 617        [JsonIgnore]
 618        public bool IsPgsSubtitleStream
 619        {
 620            get
 621            {
 64622                if (Type != MediaStreamType.Subtitle)
 623                {
 28624                    return false;
 625                }
 626
 36627                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 628                {
 30629                    return false;
 630                }
 631
 6632                return IsPgsFormat(Codec);
 633            }
 634        }
 635
 636        /// <summary>
 637        /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg.
 638        /// All text-based and pgs subtitles can be extracted.
 639        /// </summary>
 640        /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value>
 641        [JsonIgnore]
 35642        public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream;
 643
 644        /// <summary>
 645        /// Gets or sets a value indicating whether [supports external stream].
 646        /// </summary>
 647        /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
 648        public bool SupportsExternalStream { get; set; }
 649
 650        /// <summary>
 651        /// Gets or sets the filename.
 652        /// </summary>
 653        /// <value>The filename.</value>
 654        public string Path { get; set; }
 655
 656        /// <summary>
 657        /// Gets or sets the pixel format.
 658        /// </summary>
 659        /// <value>The pixel format.</value>
 660        public string PixelFormat { get; set; }
 661
 662        /// <summary>
 663        /// Gets or sets the level.
 664        /// </summary>
 665        /// <value>The level.</value>
 666        public double? Level { get; set; }
 667
 668        /// <summary>
 669        /// Gets or sets whether this instance is anamorphic.
 670        /// </summary>
 671        /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
 672        public bool? IsAnamorphic { get; set; }
 673
 674        internal string GetResolutionText()
 675        {
 73676            if (!Width.HasValue || !Height.HasValue)
 677            {
 3678                return null;
 679            }
 680
 70681            return Width switch
 70682            {
 70683                // 256x144 (16:9 square pixel format)
 4684                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70685                // 426x240 (16:9 square pixel format)
 4686                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70687                // 640x360 (16:9 square pixel format)
 14688                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70689                // 682x384 (16:9 square pixel format)
 3690                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70691                // 720x404 (16:9 square pixel format)
 7692                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70693                // 854x480 (16:9 square pixel format)
 10694                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70695                // 960x544 (16:9 square pixel format)
 11696                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70697                // 1024x576 (16:9 square pixel format)
 9698                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70699                // 1280x720
 26700                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70701                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46702                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70703                // 4K
 12704                <= 4096 when Height <= 3072 => "4K",
 70705                // 8K
 6706                <= 8192 when Height <= 6144 => "8K",
 0707                _ => null
 70708            };
 709        }
 710
 711        public static bool IsTextFormat(string format)
 712        {
 3348713            string codec = format ?? string.Empty;
 714
 715            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 716
 3348717            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3348718                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3348719                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3348720                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3348721                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3348722                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 723        }
 724
 725        public static bool IsPgsFormat(string format)
 726        {
 10727            string codec = format ?? string.Empty;
 728
 10729            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 10730                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 731        }
 732
 733        public bool SupportsSubtitleConversionTo(string toCodec)
 734        {
 286735            if (!IsTextSubtitleStream)
 736            {
 0737                return false;
 738            }
 739
 286740            var fromCodec = Codec;
 741
 742            // Can't convert from this
 286743            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 744            {
 0745                return false;
 746            }
 747
 286748            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 749            {
 0750                return false;
 751            }
 752
 753            // Can't convert to this
 286754            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 755            {
 0756                return false;
 757            }
 758
 286759            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 760            {
 0761                return false;
 762            }
 763
 286764            return true;
 765        }
 766
 767        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 768        {
 944769            if (Type != MediaStreamType.Video)
 770            {
 70771                return (VideoRange.Unknown, VideoRangeType.Unknown);
 772            }
 773
 874774            var codecTag = CodecTag;
 874775            var dvProfile = DvProfile;
 874776            var rpuPresentFlag = RpuPresentFlag == 1;
 874777            var blPresentFlag = BlPresentFlag == 1;
 874778            var dvBlCompatId = DvBlSignalCompatibilityId;
 779
 874780            var isDoViProfile = dvProfile is 5 or 7 or 8 or 10;
 874781            var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6;
 782
 874783            if ((isDoViProfile && isDoViFlag)
 874784                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 874785                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 874786                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 874787                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 788            {
 115789                var dvRangeSet = dvProfile switch
 115790                {
 64791                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 51792                    8 => dvBlCompatId switch
 51793                    {
 51794                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0795                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0796                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 51797                        // Out of Dolby Spec files should be marked as invalid
 0798                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 51799                    },
 0800                    7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL),
 0801                    10 => dvBlCompatId switch
 0802                    {
 0803                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0804                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0805                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0806                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0807                        // Out of Dolby Spec files should be marked as invalid
 0808                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 0809                    },
 0810                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 115811                };
 812
 115813                if (Hdr10PlusPresentFlag == true)
 814                {
 0815                    return dvRangeSet.Item2 switch
 0816                    {
 0817                        VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus),
 0818                        VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus),
 0819                        _ => dvRangeSet
 0820                    };
 821                }
 822
 115823                return dvRangeSet;
 824            }
 825
 759826            var colorTransfer = ColorTransfer;
 827
 759828            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 829            {
 198830                return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide
 831            }
 561832            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 833            {
 0834                return (VideoRange.HDR, VideoRangeType.HLG);
 835            }
 836
 561837            return (VideoRange.SDR, VideoRangeType.SDR);
 838        }
 839    }
 840}