C# 使用.net c压缩并从.mp4文件中获取缩略图#
我正在研究如何压缩mp4文件并从该文件生成缩略图,幸运的是,我找到了一个解决方案“MediaToolKit”,它可以完美地生成缩略图,但不适用于压缩 目前,我正在做的是生成.bat文件,其中包含FFmpeg的命令C# 使用.net c压缩并从.mp4文件中获取缩略图#,c#,.net,.net-core,ffmpeg,C#,.net,.net Core,Ffmpeg,我正在研究如何压缩mp4文件并从该文件生成缩略图,幸运的是,我找到了一个解决方案“MediaToolKit”,它可以完美地生成缩略图,但不适用于压缩 目前,我正在做的是生成.bat文件,其中包含FFmpeg的命令 using (var engine = new Engine(@"C:\ffmpeg.exe")) { int crf = 23; string resolution = "960:720"; string command = string.For
using (var engine = new Engine(@"C:\ffmpeg.exe"))
{
int crf = 23;
string resolution = "960:720";
string command = string.Format(@"-i {0} -vf scale={1} -c:v libx264 -preset
ultrafast -r 30 -crf {2} {3}", input, resolution, crf, output);
engine.CustomCommand(command);
}
ffmpeg-i%1-an-crf 25-vf fps=fps=30,比例=640x480%输出。mp4
但这不是什么好东西,我想用C语言编写一个程序,它将拍摄视频并压缩,生成缩略图
有人对此有想法吗?您可以使用FFMpegCore库
Nuget: Install-Package FFMpegCore
安装软件包后,您必须从这里下载二进制文件。
要更改根目录路径,请使用以下命令:
public Startup()
{
FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "./bin" });
}
这些都是引用到github中的
要进行压缩,请执行以下操作:
Startup();
string inputFile = @"yourVideoPath.mp4";
var encoder = new FFMpeg();
FileInfo outputFile = new FileInfo(@"newVideo.mp4");
var video = VideoInfo.FromPath(inputFile);
//track conversion progress
encoder.OnProgress += (percentage) => Console.WriteLine("Progress {0}%", percentage);
encoder.Convert(
video,
outputFile,
VideoType.Mp4,
Speed.UltraFast,
VideoSize.Ld,
AudioQuality.Low,
true
);
经过大量搜索,我发现MediaToolKit是最好的选择,因为 它提供了自定义命令的选项 通过自定义命令压缩视频的步骤 比如说
using (var engine = new Engine(@"C:\ffmpeg.exe"))
{
int crf = 23;
string resolution = "960:720";
string command = string.Format(@"-i {0} -vf scale={1} -c:v libx264 -preset
ultrafast -r 30 -crf {2} {3}", input, resolution, crf, output);
engine.CustomCommand(command);
}
要获得缩略图,它有一个方法
engine.GetThumbnail() // it will take 3 arguments inputFile, outputFile, conversionOptions