比较麻烦。
1、下载ffmpeg
http://dx.ouyaoxiazai.com:89/xiazaidian/ffmpeg.sfx.rar
2、把ffmpeg.exe文件放到你的项目下
3、全局代码
Public result As new Stringbuilder
Public Sub OutputCallback(sender As object, e As System.Diagnostics.DataReceivedEventArgs)
If e.Data > "" Then
result.append(e.Data)
End If
End Sub
4、执行代码
Dim vFileName As String = "c:\test.mp3"
Dim ffmpeg As String = ProjectPath & "ffmpeg.exe"
Dim p As new System.Diagnostics.Process
p.StartInfo.FileName = ffmpeg
p.StartInfo.UseShellExecute = False '关闭Shell的使用
p.StartInfo.RedirectStandardInput = True '重定向标准输入
p.StartInfo.RedirectStandardOutput = True '重定向标准输出
p.StartInfo.RedirectStandardError = True '重定向错误输出
p.StartInfo.CreateNoWindow = True '设置不显示窗口
addhandler p.ErrorDataReceived, addressof OutputCallback
p.StartInfo.Arguments = String.Concat("-i ", vfilename)
result.remove(0, result.length)
p.Start()
p.BeginErrorReadLine()
p.WaitForExit()
p.Close()
p.Dispose()
msgbox(result.Tostring)
Dim mc = System.Text.RegularExpressions.Regex.Matches(result.Tostring, "(?<=Duration:)\s(\d{2}:\d{2}:\d{2}.\d+)")
Dim s = mc(0).value
msgbox(s)