Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtt clean content #132

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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