FFmpeg 合并多个视频(VB.net,类库——8)

20 篇文章 1 订阅
17 篇文章 1 订阅

为了更加方便合成视频,可以使用FFmpeg

它的合成需要:

1 文件夹下有FFmpeg

2 要合成的视频,没有人会合成一个视频。

3 一个文本文件:格式为file ‘<videoPath>’  //这里有单引号

我们现在只要在cmd中调用FFmpeg:输入ffmpeg -f concat -i <文本文件> -c copy <导出后的路径>

借助代码可以更加轻松的合成:写入

 Public Function CraftVideo(ffmpeg As String, out As String)
        Dim open As New OpenFileDialog
        Dim s As String
        open.Filter = "视频文件|*.mp4"
        open.Title = "选择多个视频"
        open.Multiselect = True
        open.ShowDialog()
        For i = 0 To open.FileNames.Count - 1
            s &= "file '" & open.FileNames(i) & "'" & vbCrLf
        Next
        IO.File.WriteAllText(Application.StartupPath & "\a.txt", s)
        Process.Start(ffmpeg, "-f concat -i " & Application.StartupPath & "\a.txt" & " -c copy " & out)

    End Function

参数:ffmpeg 是FFmpeg的绝对路径,out是视频输出的绝对路径

最简单的可以使用Process.Start的方式调用,当然也可以写复杂一些:

我们写一个重载:

 Public Overridable Function CraftVideo(ffmpeg As String, out As String, CreateNoWindow As Boolean)
        Dim open As New OpenFileDialog
        Dim s As String
        open.Filter = "视频文件|*.mp4"
        open.Title = "选择多个视频"
        open.Multiselect = True
        open.ShowDialog()
        For i = 0 To open.FileNames.Count - 1
            s &= "file '" & open.FileNames(i) & "'" & vbCrLf
        Next
        IO.File.WriteAllText(Application.StartupPath & "\a.txt", s)

        Dim p As New Process
        p.StartInfo.FileName = ffmpeg
        p.StartInfo.Arguments = "-f concat -i " & Application.StartupPath & "\a.txt" & " -c copy " & out
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardError = True
        p.StartInfo.CreateNoWindow = CreateNoWindow
        p.Start()
        p.WaitForExit()
        p.StandardError.ReadToEnd()
        p.Close()
        p.Dispose()
        'Process.Start(ffmpeg, "-f concat -i " & Application.StartupPath & "\a.txt" & " -c copy " & out)

    End Function

主窗体:

 Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        GDIvid.CraftVideo(Application.StartupPath & "\FFmpeg.exe", "C:\Users\Administrator\Desktop\example.mp4", True)
        'GDIvid.CraftVideo(Application.StartupPath & "\FFmpeg.exe", "C:\Users\Administrator\Desktop\example.mp4")
    End Sub

第一段是调用的重载函数,第二段是调用的简单的函数,参数多一个CreateNoWindow=Boolean,不要调用错误

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值