mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Use map filtering
Use map filtering doing snapshot
Former-commit-id: 981b3294c5
This commit is contained in:
parent
f6132e2eba
commit
e977511b17
1 changed files with 14 additions and 9 deletions
|
@ -20,13 +20,14 @@ public static class FFMpeg
|
|||
/// <param name="output">Output video file path</param>
|
||||
/// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
|
||||
/// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
|
||||
/// <param name="videoStreamNumber">Number of video stream in input file. Default it is 0.</param>
|
||||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
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
|
|||
/// <param name="output">Output video file path</param>
|
||||
/// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
|
||||
/// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
|
||||
/// <param name="videoStreamNumber">Number of video stream in input file. Default it is 0.</param>
|
||||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
public static Task<bool> SnapshotAsync(IMediaAnalysis source, string output, Size? size = null, TimeSpan? captureTime = null)
|
||||
public static Task<bool> 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<bool> SnapshotAsync(IMediaAnalysis source, string output, Siz
|
|||
/// <param name="source">Source video file.</param>
|
||||
/// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
|
||||
/// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
|
||||
/// <param name="videoStreamNumber">Number of video stream in input file. Default it is 0.</param>
|
||||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
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
|
|||
/// <param name="source">Source video file.</param>
|
||||
/// <param name="captureTime">Seek position where the thumbnail should be taken.</param>
|
||||
/// <param name="size">Thumbnail size. If width or height equal 0, the other will be computed automatically.</param>
|
||||
/// <param name="videoStreamNumber">Number of video stream in input file. Default it is 0.</param>
|
||||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
public static async Task<Bitmap> SnapshotAsync(IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null)
|
||||
public static async Task<Bitmap> 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);
|
||||
|
|
Loading…
Reference in a new issue