ndraycott 0 Newbie Poster


I am trying create a site to upload a video files from a file upload control and convert them into a single format before storing the file path in a database for easy retrieval. I have managed to do all of the uploading and storing file path part, but i'm struggling with the converting. I have listed my code below.

Please help as i'm new to asp and i'm really struggling with the ffmpeg thing??

Thanks in advance

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click 
        If IsPostBack Then 
            'declare the file path to store uploads 
            Dim path As String = Server.MapPath("~/UploadedVideos/") 
            Dim fileOK As Boolean = False 
            'If the file upload control has a file 
            If FileUploadVideo.HasFile Then 
                'check to see if the number of characters does not exceed 50 and is not empty 
                If Len(txtVideoName.Text) <= 50 And txtVideoName.Text IsNot "" Then 
                    'clear the error message 
                    lblErrorTitle.Text = "" 
                    'check to see if a course has been added to the list 
                    If lstCourses.SelectedIndex <> -1 Then 
                        lblErrorCourse.Text = "" 
                        'check to see if a module has been added to the list 
                        If lstModules.SelectedIndex <> -1 Then 
                            lblErrorModule.Text = "" 
                            'check to see if the number of characters does not exceed 50 and is not empty 
                            If Len(txtKeywords.Text) <= 50 And txtKeywords.Text IsNot "" And txtKeywords.Text = Replace(txtKeywords.Text, " ", "") Then 
                                'clear the error message 
                                lblErrorKeywords.Text = "" 
                                'check the file to make sure it is of the required type 
                                Dim fileExtension As String 
                                fileExtension = System.IO.Path. _ 
                                'declare the allowed extentions 
                                Dim allowedExtensions As String() = _ 
                                    {".mov", ".wmv", ".avi", ".vob", ".mp4"} 
                                'loop to check the extention type 
                                For i As Integer = 0 To allowedExtensions.Length - 1 
                                    If fileExtension = allowedExtensions(i) Then 
                                        '//////////////////////////// Convert File Here 
                                        Dim ffmpeg As Process 
                                        ' creating process 
                                        Dim video As String 
                                        'Dim mpg As String 
                                        video = Page.MapPath(FileUploadVideo.FileName) 
                                        ' setting video input name with path 
                                        'mpg = Page.MapPath("") & "\video.flv" 
                                        ' thumb name with path ! 
                                        ffmpeg = New Process() 
                                        ffmpeg.StartInfo.Arguments = " -i " & video & " -target pal-flv output.flv" 
                                        ' arguments ! 
                                        ffmpeg.StartInfo.FileName = Page.MapPath("ffmpeg.exe") 
                                        ' start ! 
                                        fileOK = True 
                                    End If 
                                    '////////////////////////////////Upload File path 
                                If fileOK Then 
                                    Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) 
                                            'open the database connection 
                                            Dim FilePath = System.AppDomain.CurrentDomain.BaseDirectory & "UploadedVideos\" & FileUploadVideo.FileName 
                                            'Dim FilePath = path & FileUploadVideo.FileName 
                                            'insert statement to add the video details to the database 
                                            Const SQL As String = "INSERT INTO [Video] ([VideoName], [CourseNo], [ModuleNo], [DateUploaded], [VideoUrl], [Keywords]) VALUES (@VideoName, @CourseNo, @ModuleNo, @DateUploaded, @VideoUrl, @Keywords)" 
                                            Dim cmd As New SqlCommand(SQL, Conn) 
                                            cmd.Parameters.AddWithValue("@VideoName", txtVideoName.Text.Trim()) 
                                            cmd.Parameters.AddWithValue("@CourseNo", cboCourse.SelectedValue()) 
                                            cmd.Parameters.AddWithValue("@ModuleNo", cboModule.SelectedValue()) 
                                            cmd.Parameters.AddWithValue("@DateUploaded", Date.Now) 
                                            cmd.Parameters.AddWithValue("@VideoUrl", FilePath) 
                                            cmd.Parameters.AddWithValue("@Keywords", txtKeywords.Text.Trim()) 
                                            FileUploadVideo.PostedFile.SaveAs(path & _ 
                                            'MsgBox("File Uploaded Successfully - Thank You", MsgBoxStyle.Information, "Video Upload") 
                                            'Successful upload message 
                                            lblError.Text = "File Uploaded Successfully - Thank You" 
                                            'clear the fields  
                                            lblHoldFilePath.Text = "" 
                                            txtVideoName.Text = "" 
                                            txtKeywords.Text = "" 
                                            cboCourse.Text = "" 
                                            cboModule.Text = "" 
                                            'close the database connection 
                                        Catch ex As Exception 
                                            'file can't be uploaded error message 
                                            lblError.Text = "File could not be uploaded." & ex.Message 
                                        End Try 
                                    End Using 
                                    'error message for incorrect file type 
                                    lblError.Text = "Cannot accept files of this type." 
                                End If 
                                'error message for too many characters in the video name field 
                                lblErrorKeywords.Text = "This is a required field with a maximum length of 50 characters and no spaces!" 
                            End If 
                            lblErrorModule.Text = "You must add at least 1 Module to the list" 
                        End If 
                        lblErrorCourse.Text = "You must add at least 1 course to the list" 
                    End If 
                        'error message for too many characters in the keywords field 
                        lblErrorTitle.Text = "This is a required field with a maximum length of 50 characters" 
                    End If 
                    'error message for no file selected 
                lblHoldFilePath.Text = "Please Choose A File!!" 
                End If 
            End If 
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.