C# 使用ffmpeg从视频中截取某一帧
/// <summary>
///
/// </summary>
/// <param name="mp4">视频路径</param>
/// <param name="jpg">截取后图片保存路径</param>
/// <param name="frames">截取哪一帧</param>
public void ffmpeg(string mp4,string jpg,int frames)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "\\ffmpeg.exe";
process.StartInfo.Arguments = $@"-i {mp4} -ss {frames} -f image2 {jpg}";
process.Start();
process.WaitForExit();
process.Close();
}
catch
{
}
}
更新:发现有的视频截不出来,研究了下是文件名的原因,文件或路径中的某些特殊字符可能会导致失败