Basic ffprobe subtitle support

This commit is contained in:
alex6dj 2021-07-31 15:34:47 -04:00
parent 587c453a7e
commit f80d1fa3a6
3 changed files with 27 additions and 3 deletions

View file

@ -9,7 +9,9 @@ public interface IMediaAnalysis
MediaFormat Format { get; } MediaFormat Format { get; }
AudioStream? PrimaryAudioStream { get; } AudioStream? PrimaryAudioStream { get; }
VideoStream? PrimaryVideoStream { get; } VideoStream? PrimaryVideoStream { get; }
SubtitleStream? PrimarySubtitleStream { get; }
List<VideoStream> VideoStreams { get; } List<VideoStream> VideoStreams { get; }
List<AudioStream> AudioStreams { get; } List<AudioStream> AudioStreams { get; }
List<SubtitleStream> SubtitleStreams { get; }
} }
} }

View file

@ -12,6 +12,7 @@ internal MediaAnalysis(FFProbeAnalysis analysis)
Format = ParseFormat(analysis.Format); Format = ParseFormat(analysis.Format);
VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList(); VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList();
AudioStreams = analysis.Streams.Where(stream => stream.CodecType == "audio").Select(ParseAudioStream).ToList(); AudioStreams = analysis.Streams.Where(stream => stream.CodecType == "audio").Select(ParseAudioStream).ToList();
SubtitleStreams = analysis.Streams.Where(stream => stream.CodecType == "subtitle").Select(ParseSubtitleStream).ToList();
} }
private MediaFormat ParseFormat(Format analysisFormat) private MediaFormat ParseFormat(Format analysisFormat)
@ -36,12 +37,14 @@ private MediaFormat ParseFormat(Format analysisFormat)
}.Max(); }.Max();
public MediaFormat Format { get; } public MediaFormat Format { get; }
public AudioStream? PrimaryAudioStream => AudioStreams.OrderBy(stream => stream.Index).FirstOrDefault();
public AudioStream? PrimaryAudioStream => AudioStreams.OrderBy(stream => stream.Index).FirstOrDefault();
public VideoStream? PrimaryVideoStream => VideoStreams.OrderBy(stream => stream.Index).FirstOrDefault(); public VideoStream? PrimaryVideoStream => VideoStreams.OrderBy(stream => stream.Index).FirstOrDefault();
public SubtitleStream? PrimarySubtitleStream => SubtitleStreams.OrderBy(stream => stream.Index).FirstOrDefault();
public List<VideoStream> VideoStreams { get; } public List<VideoStream> VideoStreams { get; }
public List<AudioStream> AudioStreams { get; } public List<AudioStream> AudioStreams { get; }
public List<SubtitleStream> SubtitleStreams { get; }
private VideoStream ParseVideoStream(FFProbeStream stream) private VideoStream ParseVideoStream(FFProbeStream stream)
{ {
@ -84,7 +87,19 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
}; };
} }
private SubtitleStream ParseSubtitleStream(FFProbeStream stream)
{
return new SubtitleStream
{
Index = stream.Index,
BitRate = !string.IsNullOrEmpty(stream.BitRate) ? MediaAnalysisUtils.ParseIntInvariant(stream.BitRate) : default,
CodecName = stream.CodecName,
CodecLongName = stream.CodecLongName,
Duration = MediaAnalysisUtils.ParseDuration(stream),
Language = stream.GetLanguage(),
Tags = stream.Tags,
};
}
} }
public static class MediaAnalysisUtils public static class MediaAnalysisUtils

View file

@ -0,0 +1,7 @@
namespace FFMpegCore
{
public class SubtitleStream : MediaStream
{
}
}