diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index 7aad74f..0f516e8 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -20,13 +20,14 @@ public static class FFMpeg /// Output video file path /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. + /// Number of video stream in input file. Default it is 0. /// Bitmap with the requested snapshot. - public static bool Snapshot(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) + public static bool Snapshot(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null, int videoStreamNumber = 0) { if (Path.GetExtension(output) != FileExtension.Png) output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png; - var arguments = BuildSnapshotArguments(source, size, captureTime); + var arguments = BuildSnapshotArguments(source, size, captureTime, videoStreamNumber); return arguments .OutputToFile(output) @@ -39,13 +40,14 @@ public static bool Snapshot(IMediaAnalysis source, string output, Size? size = n /// Output video file path /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. + /// Number of video stream in input file. Default it is 0. /// Bitmap with the requested snapshot. - public static Task SnapshotAsync(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null) + public static Task SnapshotAsync(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null, int videoStreamNumber = 0) { if (Path.GetExtension(output) != FileExtension.Png) output = Path.GetFileNameWithoutExtension(output) + FileExtension.Png; - var arguments = BuildSnapshotArguments(source, size, captureTime); + var arguments = BuildSnapshotArguments(source, size, captureTime, videoStreamNumber); return arguments .OutputToFile(output) @@ -57,10 +59,11 @@ public static Task SnapshotAsync(IMediaAnalysis source, string output, Siz /// Source video file. /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. + /// Number of video stream in input file. Default it is 0. /// Bitmap with the requested snapshot. - public static Bitmap Snapshot(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + public static Bitmap Snapshot(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int videoStreamNumber = 0) { - var arguments = BuildSnapshotArguments(source, size, captureTime); + var arguments = BuildSnapshotArguments(source, size, captureTime, videoStreamNumber); using var ms = new MemoryStream(); arguments @@ -77,10 +80,11 @@ public static Bitmap Snapshot(IMediaAnalysis source, Size? size = null, TimeSpan /// Source video file. /// Seek position where the thumbnail should be taken. /// Thumbnail size. If width or height equal 0, the other will be computed automatically. + /// Number of video stream in input file. Default it is 0. /// Bitmap with the requested snapshot. - public static async Task SnapshotAsync(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + public static async Task SnapshotAsync(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int videoStreamNumber = 0) { - var arguments = BuildSnapshotArguments(source, size, captureTime); + var arguments = BuildSnapshotArguments(source, size, captureTime, videoStreamNumber); using var ms = new MemoryStream(); await arguments @@ -92,13 +96,14 @@ await arguments return new Bitmap(ms); } - private static FFMpegArguments BuildSnapshotArguments(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null) + private static FFMpegArguments BuildSnapshotArguments(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int videoStreamNumber = 0) { captureTime ??= TimeSpan.FromSeconds(source.Duration.TotalSeconds / 3); size = PrepareSnapshotSize(source, size); return FFMpegArguments .FromSeekedFiles((source.Path, captureTime ?? TimeSpan.Zero)) + .WithVideoStream(videoStreamNumber) .WithVideoCodec(VideoCodec.Png) .WithFrameOutputCount(1) .Resize(size);