首页 > 代码库 > ffmpeg获取文件的总时长(mp3/mp4/flv等)

ffmpeg获取文件的总时长(mp3/mp4/flv等)

使用ffmpeg.exe获取文件属性信息,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;    }}

 

ffmpeg获取文件的总时长(mp3/mp4/flv等)