使用ffmpeg.exe获取文件属性信息,ffmpeg是java开发的用于多媒体文件编辑的命令行工具,有多个版本,功能比较强大,C#中可以在进程外异步调用这个工具 using (System.Diagnostics.Process pro = new System.Diagnostics.Process()) { pro.StartInfo.UseShellExecute = false; pro.StartInfo.ErrorDialog = false; pro.StartInfo.RedirectStandardError = true; pro.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe"; pro.StartInfo.Arguments = " -i " + fileName; pro.Start(); System.IO.StreamReader errorreader = pro.StandardError; pro.WaitForExit(1000); string result = errorreader.ReadToEnd(); if (!string.IsNullOrEmpty(result)) { result = result.Substring(result.IndexOf("Duration: ") + ("Duration: ").Length, ("00:00:00").Length); duration = result; } }
2021-05-12 16:05:51 3KB ffmpeg 视频音频时长
1