Conversion of jpg photo set to avi, empty video

Asked

Viewed 36 times

0

I am developing an application that captures images from Webcamera and named Imgp0.jpg ,Imgp1.jpg But when I try to convert these images to video using ffmpeg but the out put video 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
  • Only with this it is difficult to help, it can be so much...

  • @Maniero Thanks for respoder I will edit to by all the code

1 answer

0

Good Finally after a few hours of studying my code I discovered that I lacked a lot of code, so that this same works if . Now yes this working a thousand wonders since thanks for trying to help I will edit the post to be able to put the full code. Here’s the code working.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.