简体   繁体   English

截取一帧视频文件(.Net core)

[英]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.我花了一些时间找到了一个.Net Core 的库,并用它在某个特定点捕获一帧视频文件。 I know there are some out there, for example i used Mediatoolkit but it is not compatible with .net core.我知道那里有一些,例如我使用了 Mediatoolkit ,但它与 .net 核心不兼容。
All of them are compatible for .net framework.它们都与 .net 框架兼容。 Any Help?有帮助吗?

You can use ffmpeg to extract frames: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video您可以使用 ffmpeg 提取帧: 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.您必须知道您使用的是什么操作系统(Linux 或 Windows)才能提供兼容的 ffmpeg 二进制文件。

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使用此 API,您可以使用参数从 C# 调用 ffmpeg(适用于 .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.我使用了 Xabe.FFmpeg。 https://ffmpeg.xabe.net/docs.html 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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