Question Need a better way to create a GUI for ffmpeg

jdkoops

Member
Joined
Sep 5, 2008
Messages
17
Programming Experience
Beginner
Hi,

I'm new to VB Express 2008 and programming in general. I enjoy Audio/Video so my project is to create a simple GUI for a ffmpeg binary with presets for various formats (i.e. IPod,Divx etc) which the user selects from a few radiobuttons. That's it. Eventually I'll add other textboxes for bitrate,resize inputs etc.

My form is very simple it has two textboxes for input/output files and radio buttons which I use 'select case true' to
branch to the appropriate case (radiobutton.checked).

Basically, I enter a file I want to convert, the output textbox populates with the input path & filename then adds the file extension (avi for divx, mp4 for ipod)when I select the radiobutton. Then I press a button to execute Streamwriter to write the batch file, then process.start
gets it going.

This works fine but I would like to evolve this little app so it doesn't need batch files and eventually use a progress bar from reading console output.

This is were im stuck. Any recommendations?

Thanks!

edit: typos
 
Last edited:
ffmpeg process.start

This may not be the perfect way but it works for me.
VB.NET:
    Dim OneLine As String
    Dim p As New Process

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        ' Enable the ability to stop ffmpeg
        BackgroundWorker1.WorkerSupportsCancellation = True
        ' Lets you get ffmpeg output info
        BackgroundWorker1.WorkerReportsProgress = True
        ' Start the background worker. This method prevents your form from locking
        BackgroundWorker1.RunWorkerAsync()
    End Sub
    
    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ' Path to video
        Dim vidPath As String = Textbox1.Text
        ' Name output video
        Dim vidName As String = TextBox2.Text
        ' Path to new video
        Dim savePath As String = TextBox3.Text
        With p.StartInfo
            .Arguments = "-i " & vidPath & " -target ntsc-dvd -aspect 4:3 " & savePath & vidName & ".mpg"
            .FileName = Application.StartupPath() & "\ffmpeg.exe"
            ' Must be set to false in order to redirect output
            .UseShellExecute = False
            ' ffmpeg uses StandardError instead of StandardOutput
            .RedirectStandardError = True
            ' Uncomment this when code is working to hide the DOS window
            '.CreateNoWindow = True
        End With
        p.Start()
        Dim outputReader As StreamReader = p.StandardError
        Dim output As String

        While Not p.HasExited
            output = outputReader.ReadLine()
            BackgroundWorker1.ReportProgress(0, output)
            Threading.Thread.Sleep(500)
        End While

    End Sub
    
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ' Show the output in a RichTextbox
        Dim output As String = e.UserState.ToString
        RichTextBox1.Text &= output & Environment.NewLine
        RichTextBox1.SelectionStart = RichTextBox1.Text.Length
    End Sub
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Cancel the encoding
        p.Kill()
    End Sub
 
This works great thanks for sharing. I'm also learning about the BackgroundWorker (for use with progressbar) and your example helps me there too.
 
Back
Top