vb.net - 我找不到任何方法在 vb.net 中使用 ffmpeg 将多个 jpg 或 png 转换为 gif

标签 vb.net ffmpeg

无论如何我可以在 vb.net 中使用 ffmpeg 将多个 png 或 jpg 图像转换为 gif
我已经启动了一个新应用程序来从视频中捕获某些帧,但现在我想使用 ffmpeg 获取在 gif 图像中提取的所有帧。
到目前为止,这是我的代码:
我实际上已经准备好像这样尝试但没有成功
我做了一些更改,我得到了 gif 文件但处于空状态
到目前为止,这是我的代码

Imports System.Diagnostics
Imports System.ComponentModel
Imports System
Imports System.IO
Public Class Form1
Dim video = ""
Dim startInfo As New ProcessStartInfo("ffmpeg.exe")
Dim frame As Long 'individual frames
Dim tempdir As String = "C:\avitogifconverter\" ' images temp directory
Dim DestPath As String = "C:\avitogifconverter\"
Public Declare Auto Function FindWindowNullClassName Lib "user32.dll" Alias "FindWindow" (ByVal lpClassname As Integer, ByVal lpWindownName As String) As Integer
Dim Counter As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    My.Computer.FileSystem.CreateDirectory(tempdir)
    TextBox1.Text = "exp:-->video.avi or webm or flv"
    TextBox1.Clear()



End Sub


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim p As Process = Process.Start("cmd", "/k ffmpeg.exe -i " + TextBox1.Text + " -filter:v fps=1/15 C:\avitogifconverter\out%02d.jpg")
    p.WaitForExit()

    If p.HasExited Then
        MsgBox("The Extraction Are Finish...")
    End If

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Label3.Text = "cmd" + "/k ffmpeg.exe -i " + TextBox1.Text + " -filter:v fps=1/15 C:\avi to gif converter\out%02d.jpg"
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


    If (OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK) Then
        'TextBox1.Text = OpenFileDialog1.FileName
        TextBox1.Text = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
    End If
    If TextBox1.Text = Nothing Then
        Return
    End If
    If TextBox1.Text <> Nothing Then
        'My.Computer.FileSystem.CopyFile(TextBox1.Text, DestPath)
    End If

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim args As String 'declare args
    args = " -framerate 1/5 -i C:\avitogifconverter\out%02d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p C:\avitogifconverter\out.gif "
    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.FileName = My.Application.Info.DirectoryPath & "\ffmpeg.exe"
    proci.Arguments = args
    proci.WindowStyle = ProcessWindowStyle.Hidden
    proci.CreateNoWindow = True
    proci.UseShellExecute = False
    proc.StartInfo = proci
    proc.Start()
    Do Until proc.HasExited = True
        Me.Text = "Saving"
    Loop
    Me.Text = "your video done"

    MsgBox("Done")

    'IO.Directory.Delete(tempdir, True)
End Sub
End Class

最佳答案

事实上,我刚刚完成了代码,我终于发现它出了什么问题。
这是将 mp4 转换为 gif 的工作代码
所以我决定首先将图像转换为 mp4 并将 mp4 转换为 gif

我尝试将文件移动到其他位置,但是当我尝试将文件移动到其他位置时,它说我找不到目录但目录存在。
我在这里想念什么
这是代码

Imports System.Diagnostics
Imports System.ComponentModel
Imports System
Imports System.IO
Imports System.IO.Compression
Imports System.Windows.Forms
Imports System.Net

Public Class Form1
Dim fpsx = 10
Dim video = ""
Dim startInfo As New ProcessStartInfo("ffmpeg.exe")
Dim frame As Long 'individual frames
Dim tempdir As String = "C:\avitogifconverter\" ' images temp directory
Dim DestPath As String = "C:\avitogifconverter\"
Public Declare Auto Function FindWindowNullClassName Lib "user32.dll" Alias "FindWindow" (ByVal lpClassname As Integer, ByVal lpWindownName As String) As Integer
Dim Counter As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    My.Computer.FileSystem.CreateDirectory(tempdir)
    TextBox1.Text = "exp:-->video.avi or webm or flv"
    TextBox1.Clear()
    TextBox2.Text = fpsx


End Sub


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    fpsx = TextBox2.Text
    TextBox2.Text = fpsx

    Dim p As Process = Process.Start("cmd", "/k ffmpeg.exe -i " + TextBox1.Text + " -framerate 5/1 -filter:v fps=" + TextBox2.Text + " C:\avitogifconverter\out%02d.jpg")
    p.WaitForExit()

    If p.HasExited Then
        MsgBox("The Extraction Are Finish...")
    End If

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs)

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


    If (OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK) Then
        'TextBox1.Text = OpenFileDialog1.FileName
        'TextBox1.Text = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
        TextBox1.Text = System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName)
        Dim newdialog As New OpenFileDialog()
        If newdialog.ShowDialog() = DialogResult.OK Then
            System.IO.File.Copy(newdialog.FileName, tempdir)
            MessageBox.Show(System.IO.Path.GetDirectoryName(newdialog.FileName) & "\" & System.IO.Path.GetFileName(newdialog.FileName))
        End If
    End If
    If TextBox1.Text = Nothing Then
        Return
    End If
    If TextBox1.Text <> Nothing Then
        'My.Computer.FileSystem.CopyFile(TextBox1.Text, DestPath)
    End If

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim args As String 'declare args
    args = " -i C:\avitogifconverter\out%02d.jpg -r 10 C:\avitogifconverter\out.gif "
    'args = " -i C:\avitogifconverter\out%02d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p C:\avitogifconverter\out.mp4 "
    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.FileName = My.Application.Info.DirectoryPath & "\ffmpeg.exe"
    proci.Arguments = args
    proci.WindowStyle = ProcessWindowStyle.Hidden
    proci.CreateNoWindow = True
    proci.UseShellExecute = False
    proc.StartInfo = proci
    proc.Start()
    Do Until proc.HasExited = True
        Me.Text = "Saving"
    Loop
    Me.Text = "your video done"

    MsgBox("Done")
    Dim directoryName As String = "C:\avitogifconverter\"
    For Each deleteFile In Directory.GetFiles(directoryName, "*.jpg", SearchOption.TopDirectoryOnly)
        File.Delete(deleteFile)
    Next

    'IO.Directory.Delete(tempdir, True)
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Form2.Show()

End Sub
End Class

关于vb.net - 我找不到任何方法在 vb.net 中使用 ffmpeg 将多个 jpg 或 png 转换为 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44892952/

相关文章:

.net - 在 VB.net 中将合并字段从一个 word 文档复制到另一个

vb.net - 如何通过网络在两个 VB.NET 应用程序之间进行通信

ffmpeg 的 av_read_frame 是否会阻塞?

ffmpeg - 用 libav/ffmpeg 替换 Bento4

android - 是否可以直接在 android 上录制 MJPEG?

video - 如何使用 rm/rmvb 支持编译 ffmpeg?

iphone - 什么是FFmpeg?

vb.net - Visual Studio 从哪里获取数据智能感知和命名空间补全

c# - 如何删除对象状态管理器中的重复实体

c# - 表中列值的总和 - Rdlc 报告