c# 调用 ffmpeg 获取音频时长
var arg = "-i \"" + filepath + "\" 2"; TimeSpan duration = TimeSpan.Zero; await FFMpeg.Xamarin.FFmpegLibrary.Run(this.BaseContext, arg, (line) => { System.Diagnostics.Debug.WriteLine("ffmpeg output:" + line); var regex = new Regex(@"Duration: (\d+):(\d\d):(\d\d)\.(\d+)"); var match = regex.Match(line); if (match.Success) { var hours = int.Parse(match.Groups[1].Value); var minutes = int.Parse(match.Groups[2].Value); var seconds = int.Parse(match.Groups[3].Value); var milliseconds = int.Parse(match.Groups[4].Value) * 10; duration = new TimeSpan(0, hours, minutes, seconds, milliseconds); } });
桂棹兮兰桨,击空明兮溯流光。