Skip to content

Commit

Permalink
vtt clean content (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
melindawangmsft authored Aug 15, 2023
1 parent 03e6e0d commit 2a52b87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
19 changes: 1 addition & 18 deletions pipes/MultiFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ private void GenerateVttContent(IList<Box> inputBoxes, MP4Writer mp4Writer)

if (vttText != null)
{
byte[] contentBytes = Encoding.UTF8.GetBytes(RemoveXmlControlCharacters(vttText));
mp4Writer.Write(contentBytes);
mp4Writer.Write(vttText);
}
else
{
Expand All @@ -197,22 +196,6 @@ private void GenerateVttContent(IList<Box> inputBoxes, MP4Writer mp4Writer)
}
}

private string RemoveXmlControlCharacters(string input)
{
StringBuilder output = new StringBuilder();

foreach (char c in input)
{
// Exclude XML control characters (0x00 to 0x1F, except for whitespace characters)
if (c >= 0x20 || char.IsWhiteSpace(c))
{
output.Append(c);
}
}

return output.ToString();
}

private async Task DownloadClearBlobContent(BlockBlobClient sourceBlob, Stream outputStream, CancellationToken cancellationToken)
{
using var tmpStream = new MemoryStream();
Expand Down
9 changes: 7 additions & 2 deletions transform/CTtml2WebVttConv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public static class TtmlToVttConverter
{
public static string? Convert(byte[]? ttmlText)
public static byte[]? Convert(byte[]? ttmlText)
{
if (ttmlText == null)
{
Expand Down Expand Up @@ -127,7 +127,12 @@ public static class TtmlToVttConverter

webVttContentRes= webVttContent.ToString();
}
return !string.IsNullOrEmpty(webVttContentRes) ? webVttContentRes: null; //webVttContentRes;Regex.Replace(webVttContentRes, @"[\x00-\x1F\x7F]", "\n")
byte[]? contentBytes = null;
if (!string.IsNullOrEmpty(webVttContentRes))
{
contentBytes = Encoding.UTF8.GetBytes(webVttContentRes);
}
return contentBytes;
}

private static void ParseRegionAttributes(XmlReader pReader, out string strStartCue, out string strCueSize, out string strAlign)
Expand Down

0 comments on commit 2a52b87

Please sign in to comment.