Merge pull request #3085 from MrTimscampi/vtt-position
Add positionning cues to WebVTT writer
This commit is contained in:
commit
18953d95e6
|
@ -7,14 +7,25 @@ using MediaBrowser.Model.MediaInfo;
|
|||
|
||||
namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
/// <summary>
|
||||
/// Subtitle writer for the WebVTT format.
|
||||
/// </summary>
|
||||
public class VttWriter : ISubtitleWriter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
{
|
||||
writer.WriteLine("WEBVTT");
|
||||
writer.WriteLine(string.Empty);
|
||||
writer.WriteLine("REGION");
|
||||
writer.WriteLine("id:subtitle");
|
||||
writer.WriteLine("width:80%");
|
||||
writer.WriteLine("lines:3");
|
||||
writer.WriteLine("regionanchor:50%,100%");
|
||||
writer.WriteLine("viewportanchor:50%,90%");
|
||||
writer.WriteLine(string.Empty);
|
||||
foreach (var trackEvent in info.TrackEvents)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -22,13 +33,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||
var startTime = TimeSpan.FromTicks(trackEvent.StartPositionTicks);
|
||||
var endTime = TimeSpan.FromTicks(trackEvent.EndPositionTicks);
|
||||
|
||||
// make sure the start and end times are different and seqential
|
||||
// make sure the start and end times are different and sequential
|
||||
if (endTime.TotalMilliseconds <= startTime.TotalMilliseconds)
|
||||
{
|
||||
endTime = startTime.Add(TimeSpan.FromMilliseconds(1));
|
||||
}
|
||||
|
||||
writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff}", startTime, endTime);
|
||||
writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff} region:subtitle", startTime, endTime);
|
||||
|
||||
var text = trackEvent.Text;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user