/// <summary> /// Converts decoded, raw frame data in the frame source into a a usable frame. <br /> /// The process includes performing picture, samples or text conversions /// so that the decoded source frame data is easily usable in multimedia applications /// </summary> /// <param name="input">The source frame to use as an input.</param> /// <param name="output">The target frame that will be updated with the source frame. If null is passed the frame will be instantiated.</param> /// <param name="siblings">The sibling blocks that may help guess some additional parameters for the input frame.</param> /// <returns> /// Return the updated output frame /// </returns> /// <exception cref="ArgumentNullException">input cannot be null</exception> public override MediaBlock MaterializeFrame(MediaFrame input, ref MediaBlock output, List <MediaBlock> siblings) { if (output == null) { output = new SubtitleBlock(); } var source = input as SubtitleFrame; var target = output as SubtitleBlock; if (source == null || target == null) { throw new ArgumentNullException($"{nameof(input)} and {nameof(output)} are either null or not of a compatible media type '{MediaType}'"); } // Set the target data target.EndTime = source.EndTime; target.StartTime = source.StartTime; target.Duration = source.Duration; target.StreamIndex = input.StreamIndex; target.OriginalText.Clear(); if (source.Text.Count > 0) { target.OriginalText.AddRange(source.Text); } target.OriginalTextType = source.TextType; target.Text.Clear(); foreach (var text in source.Text) { if (string.IsNullOrWhiteSpace(text)) { continue; } if (source.TextType == AVSubtitleType.SUBTITLE_ASS) { var strippedText = StripAssFormat(text); if (string.IsNullOrWhiteSpace(strippedText) == false) { target.Text.Add(strippedText); } } else { var strippedText = StripSrtFormat(text); if (string.IsNullOrWhiteSpace(strippedText) == false) { target.Text.Add(strippedText); } } } return(target); }
/// <summary> /// Converts decoded, raw frame data in the frame source into a a usable frame. <br /> /// The process includes performing picture, samples or text conversions /// so that the decoded source frame data is easily usable in multimedia applications /// </summary> /// <param name="input">The source frame to use as an input.</param> /// <param name="output">The target frame that will be updated with the source frame. If null is passed the frame will be instantiated.</param> /// <returns> /// Return the updated output frame /// </returns> /// <exception cref="System.ArgumentNullException">input</exception> internal override MediaBlock MaterializeFrame(MediaFrame input, ref MediaBlock output) { if (output == null) { output = new SubtitleBlock(); } var source = input as SubtitleFrame; var target = output as SubtitleBlock; if (source == null || target == null) { throw new ArgumentNullException($"{nameof(input)} and {nameof(output)} are either null or not of a compatible media type '{MediaType}'"); } // Set the target data target.EndTime = source.EndTime; target.StartTime = source.StartTime; target.Duration = source.Duration; target.Text.Clear(); target.Text.AddRange(source.Text); return(target); }
/// <summary> /// Converts decoded, raw frame data in the frame source into a a usable frame. <br /> /// The process includes performing picture, samples or text conversions /// so that the decoded source frame data is easily usable in multimedia applications /// </summary> /// <param name="input">The source frame to use as an input.</param> /// <param name="output">The target frame that will be updated with the source frame. If null is passed the frame will be instantiated.</param> /// <param name="siblings">The sibling blocks that may help guess some additional parameters for the input frame.</param> /// <returns> /// Returns true if successful. False otherwise /// </returns> /// <exception cref="ArgumentNullException">input cannot be null</exception> public override bool MaterializeFrame(MediaFrame input, ref MediaBlock output, List <MediaBlock> siblings) { if (output == null) { output = new SubtitleBlock(); } var source = input as SubtitleFrame; var target = output as SubtitleBlock; if (source == null || target == null) { throw new ArgumentNullException($"{nameof(input)} and {nameof(output)} are either null or not of a compatible media type '{MediaType}'"); } // Set the target data target.EndTime = source.EndTime; target.StartTime = source.StartTime; target.Duration = source.Duration; target.StreamIndex = input.StreamIndex; // Process time offsets if (Delay != TimeSpan.Zero) { target.StartTime = TimeSpan.FromTicks(target.StartTime.Ticks + Delay.Ticks); target.EndTime = TimeSpan.FromTicks(target.EndTime.Ticks + Delay.Ticks); target.Duration = TimeSpan.FromTicks(target.EndTime.Ticks - target.StartTime.Ticks); } target.OriginalText.Clear(); if (source.Text.Count > 0) { target.OriginalText.AddRange(source.Text); } target.OriginalTextType = source.TextType; target.Text.Clear(); foreach (var text in source.Text) { if (string.IsNullOrWhiteSpace(text)) { continue; } if (source.TextType == AVSubtitleType.SUBTITLE_ASS) { var strippedText = StripAssFormat(text); if (string.IsNullOrWhiteSpace(strippedText) == false) { target.Text.Add(strippedText); } } else { var strippedText = StripSrtFormat(text); if (string.IsNullOrWhiteSpace(strippedText) == false) { target.Text.Add(strippedText); } } } // TODO: CompressedSize is just an estimate. // It would be better if we counted chars in all text lines. target.CompressedSize = source.CompressedSize; return(true); }