如何将视频转换为不同的格式? [英] How to convert video to different formats?
本文介绍了如何将视频转换为不同的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Visual Basic Professional 2010创建了一个视频转换器。现在我可以打开任何视频格式的文件,但是在保存文件时,它只能让我以.flv格式保存。我希望我的应用程序以多种视频格式转换。我做错了什么?
这是代码:
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:
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
推荐答案
检查这个开源库。
http://www.aforgenet.com/framework/samples/video.html [ ^ ]
Check this open source library.
http://www.aforgenet.com/framework/samples/video.html[^]
这篇关于如何将视频转换为不同的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文