Imports System.IO Public Class Main Dim proc As New Process 'make it global so dat we can kill it from outside Function startConversion() Control.CheckForIllegalCrossThreadCalls = False Dim input As String = Me.dlgOpen.FileName Dim output As String = Me.dlgSave.FileName Dim exepath As String = Application.StartupPath + "\bin\ffmpeg.exe" Dim quality As Integer = TrackBar1.Value * 2 Dim startinfo As New System.Diagnostics.ProcessStartInfo Dim sr As StreamReader Dim cmd As String = " -i """ + input + """ -ar 22050 -qscale " & quality & " -y """ + output + """" 'ffmpeg commands -y replace Dim ffmpegOutput As String ' all parameters required to run the process startinfo.FileName = exepath startinfo.Arguments = cmd startinfo.UseShellExecute = False startinfo.WindowStyle = ProcessWindowStyle.Hidden startinfo.RedirectStandardError = True startinfo.RedirectStandardOutput = True startinfo.CreateNoWindow = True proc.StartInfo = startinfo proc.Start() ' start the process Me.lblInfo.Text = "Conversion in progress... Please wait..." sr = proc.StandardError 'standard error is used by ffmpeg Me.btnStart.Enabled = False Do If BackgroundWorker1.CancellationPending Then 'check if a cancellation request was made End If ffmpegOutput = sr.ReadLine Me.txtProgress.Text = ffmpegOutput Loop Until proc.HasExited And ffmpegOutput = Nothing Or ffmpegOutput = "" Me.txtProgress.Text = "Finished !" Me.lblInfo.Text = "Completed!" MsgBox("Completed!", MsgBoxStyle.Exclamation) Me.btnStart.Enabled = True Return 0 End Function Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click If txtOpen.Text = "" Or txtOpen.Text <> dlgOpen.FileName Then MsgBox("Select a file to convert", MsgBoxStyle.Information, "Select a file") Exit Sub ElseIf txtSave.Text = "" Or txtSave.Text <> dlgSave.FileName Then MsgBox("Select your output filename", MsgBoxStyle.Information, "Select a file") Exit Sub End If BackgroundWorker1.RunWorkerAsync() End Sub Private Sub dlgSave_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgSave.FileOk dlgSave.OverwritePrompt = True dlgSave.DereferenceLinks = True dlgSave.CreatePrompt = True dlgSave.DefaultExt = ".flv" txtSave.Text = dlgSave.FileName End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click dlgSave.ShowDialog() End Sub Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click dlgOpen.ShowDialog() End Sub Private Sub dlgOpen_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgOpen.FileOk dlgOpen.CheckFileExists = True txtOpen.Text = dlgOpen.FileName End Sub Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click On Error GoTo handle BackgroundWorker1.CancelAsync() If btnStart.Enabled = False Then lblInfo.Text = ("Conversion Canceled!") MsgBox("Conversion has been cancelled!", MsgBoxStyle.Exclamation) btnStart.Enabled = True Else MsgBox("Start conversion first", MsgBoxStyle.Critical) End If proc.Kill() handle: Exit Sub End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork startConversion() End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click MsgBox("Developed by Keith O. Williams for Greater Works Business Services. Based on flvConvert application created by Tunde Olabenjo" & vbCrLf & "greaterworksbs@gmail.com", MsgBoxStyle.Question, "About Ceieme Video Converter") End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Me.Close() End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)