jellyfin/MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs
Bond_009 cc5acf37f7 Make probesize and analyzeduration configurable and simplify circular
dependencies

Makes the probesize and analyzeduration configurable with env args.
(`JELLYFIN_FFmpeg_probesize` and `FFmpeg_analyzeduration`)
2019-11-25 12:07:59 +01:00

41 lines
1.2 KiB
C#

using System.IO;
using System.Text.Json;
using System.Threading;
using MediaBrowser.Model.MediaInfo;
namespace MediaBrowser.MediaEncoding.Subtitles
{
/// <summary>
/// JSON subtitle writer.
/// </summary>
public class JsonWriter : ISubtitleWriter
{
/// <inheritdoc />
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
{
using (var writer = new Utf8JsonWriter(stream))
{
var trackevents = info.TrackEvents;
writer.WriteStartArray("TrackEvents");
for (int i = 0; i < trackevents.Count; i++)
{
cancellationToken.ThrowIfCancellationRequested();
var current = trackevents[i];
writer.WriteStartObject();
writer.WriteString("Id", current.Id);
writer.WriteString("Text", current.Text);
writer.WriteNumber("StartPositionTicks", current.StartPositionTicks);
writer.WriteNumber("EndPositionTicks", current.EndPositionTicks);
writer.WriteEndObject();
}
writer.WriteEndObject();
}
}
}
}