Conversion of jpg to avi picture set, empty video

0

I am developing an application that captures images of the webcamera and is called Imgp0.jpg, Imgp1.jpg But when I try to convert these images to video using ffmpeg but the video out put is empty. This is the code I use to convert

Imports System.IO

Public Class Form2
Dim mydataandtimeforsave As String = DateTime.Now.ToString("yyyyMMddHHmmss")

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If TextBox1.Text = "" Then
        TextBox1.Text = 1
    End If

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    capturex()
    save()
End Sub
Public Sub capturex()
    Dim area As Rectangle
    Dim capture As System.Drawing.Bitmap
    Dim graph As Graphics
    area = Form1.Bounds
    capture = New System.Drawing.Bitmap(area.Width, area.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    graph = Graphics.FromImage(capture)
    graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
    PictureBox1.Image = capture
End Sub
Public Sub save()
    Dim mydataandtimeforsave = DateTime.Now.ToString("yyyyMMddHHmmss")
    PictureBox1.Image.Save("C:\dirorg/" & mydataandtimeforsave & "Screenshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Me.Timer1.Interval = TimeSpan.FromSeconds(TextBox1.Text).TotalMilliseconds
    capturex()
    save()
End Sub

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


    '-framerate 3 -i "Imgp%%04d.jpg" -s 720x480 test.avi)
End Sub
Private Sub renameFilesInFolder()
    Dim sourcePath As String = "C:\dirorg/"
    Dim searchPattern As String = "*.jpg"
    Dim i As Integer = 0
    For Each fileName As String In Directory.GetFiles(sourcePath, searchPattern, SearchOption.AllDirectories)
        File.Move(Path.Combine(sourcePath, fileName), Path.Combine(sourcePath, "Imgp" & i & ".jpg"))
        i += 1
    Next
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    build()
End Sub
Public Sub build()
    Dim args As String 'declare args

    args = " -start_number -i C:\dirorg\Imgp%01d.jpg -c:v libx264 -r 1 -pix_fmt yuv420p C:\dirorg\out.mp4 "
    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.FileName = "C:\dirorg\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")

End Sub
End Class
    
asked by anonymous 14.08.2018 / 03:04

1 answer

0

Good Finally after a few hours of studying my code I discovered that I lacked a lot of code, so this even works if. Now it is working the marvels since thanks for the help attempt I will edit the post to be able to by the complete code. Here is the code to work.

Imports System.IO

Public Class Form2
Dim mydataandtimeforsave As String = DateTime.Now.ToString("yyyyMMddHHmmss")
Dim frame As Long 'individual frames
Dim tempdir As String = "C:\dirorg/" ' images temp directory
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If TextBox1.Text = "" Then
        TextBox1.Text = 1
    End If

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    capturex()
    'save()
End Sub
Public Sub capturex()
    Try

        Dim area As Rectangle
        Dim graph As Graphics
        Dim captured As Bitmap
        area = Screen.PrimaryScreen.Bounds
        captured = New System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        graph = Graphics.FromImage(captured)

        graph.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy)
        ' you will need IF statement if you have checkbox
        If CheckBox1.Checked = True Then
            Cursor.Draw(graph, New Rectangle(New Point(Cursor.Position.X - Cursor.HotSpot.X, Cursor.Position.Y - Cursor.HotSpot.Y), Cursor.Size))

        End If
        Dim strings As String

        strings = frame
        captured.Save(tempdir & "\" & strings & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
        frame += 1
        Label2.Text = "TIME: " & frame
    Catch ex As Exception

    End Try
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Start()
End Sub

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

    Me.Timer1.Interval = TimeSpan.FromSeconds(TextBox1.Text).TotalMilliseconds
    capturex()

End Sub

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


    '-framerate 3 -i "Imgp%%04d.jpg" -s 720x480 test.avi)
End Sub
Private Sub renameFilesInFolder()
    Dim sourcePath As String = "C:\dirorg/"
    Dim searchPattern As String = "*.jpg"
    Dim i As Integer = 0
    For Each fileName As String In Directory.GetFiles(sourcePath, searchPattern, SearchOption.AllDirectories)
        File.Move(Path.Combine(sourcePath, fileName), Path.Combine(sourcePath, "Imgp" & i & "d.jpg"))
        i += 1
    Next
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    With SaveFileDialog1
        .DefaultExt = ".avi"
        .FilterIndex = 1
        .Filter = "Avi Files (*.avi)|*.avi|All files (*.*)|*.*"
    End With
    SaveFileDialog1.ShowDialog()
End Sub

Private Sub SaveFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk

    Dim args As String 'declare args
    args = "-r 1/.1 -i " & "C:\dirorg" & "\%01d.jpg -c:v libx264 -r 80 -pix_fmt yuv420p " & Chr(34) & SaveFileDialog1.FileName & Chr(34) 'set ffmpeg arguments
    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.FileName = "C:\dirorg\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 = tempdir
    For Each deleteFile In Directory.GetFiles(directoryName, "*.jpg", SearchOption.TopDirectoryOnly)
        File.Delete(deleteFile)
    Next
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Timer1.Stop()
End Sub

End Class
    
14.08.2018 / 16:36