网上也有很多C#教程关于FFmpeg处理视频的,其实换到VB.net,还是一样的
先从网上下载到FFmpeg.exeFFmpeg-FFmpeg
再把FFmpeg.exe拖入自己的应用程序文件夹下
由于是跟类库有关的,可以翻我之前写的调用(类库1-5)
现在打开我们的类库,新建一个类(随便取名):VideoProcess
Public Class VideoProcess
''' <summary>
''' 给视频添加音频,注意视频和音频时长
''' </summary>
''' <param name="ffmpeg">给的FFmpeg绝对路径</param>
''' <param name="mp3">给的音频路径</param>
''' <param name="video">给的视频路径</param>
''' <param name="out">输出视频的路径</param>
''' <returns>null</returns>
Public Function AddAudio(ffmpeg As String, mp3 As String, video As String, out As String)
Process.Start(ffmpeg, "-i " & video & " -i " & mp3 & " -codec copy " & out)
Return vbNull
End Function
''' <summary>
''' 给视频删除音频,注意原视频的视频时长和原音频的时长
''' </summary>
''' <param name="ffmpeg">给的FFmpeg绝对路径</param>
''' <param name="video">给的视频路径</param>
''' <param name="out">输出视频的路径</param>
''' <returns>null</returns>
Public Function DeleteAudio(ffmpeg As String, video As String, out As String)
Process.Start(ffmpeg, "-i " & video & " -c:v copy -an " & out)
Return vbNull
End Function
End Class
提前在桌面上放一个音频,一个视频
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
GDIvid.AddAudio(Application.StartupPath & "\ffmpeg.exe", "C:\Users\Administrator\Desktop\105.mp3", "C:\Users\Administrator\Desktop\test.mp4", "C:\Users\Administrator\Desktop\test1.mp4")
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
GDIvid.DeleteAudio(Application.StartupPath & "\ffmpeg.exe", "C:\Users\Administrator\Desktop\test1.mp4", "C:\Users\Administrator\Desktop\test2.mp4")
End Sub
添加音频后,视频的时长会改变