Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a video converter using Visual Basic Professional 2010. Now I am able to open a file in any video format, but when it comes to saving a file, it will only let me save it in .flv format. I want my app to convert in multiple video format. What am I doing wrong?

Here is the code:

VB
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
Posted
Updated 15-Jul-14 7:35am
v2
Comments
ArunRajendra 15-Jul-14 1:39am    
Might be you need to have different codec if i am not wrong.
Keith O. Williams 18-Jul-14 15:33pm    
What codec should I be using and how do I incorporated to my code?

1 solution

Check this open source library.

http://www.aforgenet.com/framework/samples/video.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900