简体   繁体   中英

Capture a frame of video file (.Net core)

I spent some time to find a library for.Net Core and use it to capture a frame of video file at some certain point. I know there are some out there, for example i used Mediatoolkit but it is not compatible with .net core.
All of them are compatible for .net framework. Any Help?

You can use ffmpeg to extract frames: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video

You have to know what operating system you are on (Linux or Windows) to provide compatible ffmpeg binaries.

With this API you can invoke ffmpeg from C# with parameters (applies to .NET Core): https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netframework-4.7.2

var process = new Process
{
    StartInfo = new ProcessStartInfo()
    {
        CreateNoWindow = true,
        FileName = "ffmpeg", // or path to the ffmpeg
        WindowStyle = ProcessWindowStyle.Hidden,
        Arguments = "your arguments here"
    }
};

process.Start();
process.WaitForExit(10000); // wait for exit 10000 miliseconds

Now you just need to read the output (image file) from the file system.

I used Xabe.FFmpeg. https://ffmpeg.xabe.net/docs.html

// sudo apt install ffmpeg
FFmpeg.SetExecutablesPath("/usr/bin/");

var conversion = await FFmpeg.Conversions.FromSnippet.Snapshot(newPath1, newPath2, TimeSpan.FromSeconds(0));
var result = await conversion.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM