0

我需要傳遞一個字符串到ProcessStartInfo ffmpeg,以便我可以調用dim.Argument,並讓它在代碼中追加字符串和變量,當我解析文件時。&運算符字符串錯誤與processStartInfo的參數字符串

我有當前的filename.mp3代碼在movedFileInfo看到,但它不會允許我使用&運算符將其附加到字符串...幫助?

我知道可能有另外一種方法來利用單獨函數中的ffmpeg命令來簡單地循環使用「for」目錄但我還沒有找到一個成功的命令來運行我的ffmpeg.exe或ffprompt在窗口中。我還需要在寫入merge.txt時附加回車符,但找不到示例...我是vba新手。

這些命令的工作,但vba抱怨我的字符串&運營商與錯誤The operator '&' is not defined for types 'String' and 'System.IO.FileInfo'錯誤。

所以我所理解的是我傳遞到psi.Arguments的字符串不喜歡我發送一個字符串和使用&運算符附加的變量的事實......我只是簡單地使用逗號或如何將變量movedFileInfo附加到ffmpeg -i? psi的定義如上ProcessStartInfo ...所以我不知道什麼類型的VB認識它...我還沒有找到ProcessStartInfo信息啓動我的ffmpeg EXE。

見下文代碼:

Imports System 
Imports System.IO 
Imports System.Text.RegularExpressions 


Public Class Form1 

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 

     'videos are from SD card always on I:\Private\AVCHD\BDMV\STREAM\ 
     'store files to RAID drives in folders structured as : 
     '  F:\BUILD\FLIGHT#\CAM#\<TAIL_NUMBER>_FLT_<FLT_NUMBER>_UTC_<START_UTC_TIME>_CAM_<CAM_NUMBER>.MTS 

     'set base dir as directory F:\ 
     Dim dir As String = "C:\" 
     Dim video_card_dir As String = "C:\1bak\" '"I:\Private\AVCHD\BDMV\STREAM\" 
     Directory.SetCurrentDirectory(dir) 

     Dim new_flightnum_directory = dir & Me.BUILD.Text & "\" & FLT.Text & "\" 
     'establish new video dir> F: \ BUILD  \  FLIGHT # \    CAM # \ 
     Dim new_video_directory = dir & Me.BUILD.Text & "\" & FLT.Text & "\" & Me.CAM.Text & "\" 
     'establish new filename to rename the video file 
     '        TAIL #    FLT # 
     Dim new_filename As String = TAIL.Text & "_" & FLT.Text & "_" & UTC.Text & "_" & CAM.Text 
     Dim ffmpeg As String = "C:\ffmpeg\bin\ffmpeg.exe" 
     '****FFMPEG required variables 
     Dim psi As ProcessStartInfo = New ProcessStartInfo("C:\ffmpeg\bin\ffmpeg.exe") 
     Dim proc As Process = Process.Start(psi) 

     psi.UseShellExecute = True 
     psi.CreateNoWindow = True 
     '****end FFMPEG required variables 



     '!!!!!!!!!!!!!!!!!!!!!!!!!!!need to add the processing below to the IF statement aboev so that if the folders exist, the video processing doesn't attempt to run on existing files 
     ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 





     '~~~~~~~~~~~~~~~~~~~~~~~~~~~~START - MOVE THIS DOWN BELOW CREATION OF FILE STRUCTURE WHEN DOEN DEBUGGING************ 


     '***START MOVING the files from the card to the new directory**** 
     For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS") 

      Dim foundFileInfo As New System.IO.FileInfo(foundFile) 
      My.Computer.FileSystem.MoveFile(foundFile, new_video_directory & foundFileInfo.Name) 


     Next 

     For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS") 

      Dim movedFileInfo As New System.IO.FileInfo(foundFile) 
      psi.Arguments = "ffmpeg -i " & movedFileInfo & " -vcodec -c libx264 " & movedFileInfo & ".mp4" 
      psi.ToString() 

      'proc = Process.Start(psi) 

      '***convert each MTS file in the new directory to MP4**** 
      'Writes filenames to merge.txt as " path\to\merge.txt ,    'file ' F:\path\to\    file1 .MP4   '" so that ffmpeg can merge, then rename 
      'My.Computer.FileSystem.WriteAllText(new_video_directory & "merge.txt", "file '" & movedFileInfo & ".mp4'" & vbCrLf, True) 
      '>>>>need to add carriage return to text file 

      'NOW CAPTURE FILENAMES OF MP4 and MERGE INTO 1 MP4 FILE 

      ' merge all F:\path\to\merge.txt to merge the files & merge them 
      'psi.Arguments = "ffmpeg -f concat -i " & new_video_directory & "merge.txt -c copy " & new_filename & ".mp4" 
      proc = Process.Start(psi) 

     Next 

     '***END MERGE FILES*** 


     '~~~~~~~~~~~~~~~~~~~~~~~~~~~~* END - MOVE 


     '***START CREATE STORAGE DIRECTORY STRUCTURE *** 
     'Verify if the build # directory exists? 
     If My.Computer.FileSystem.DirectoryExists(dir & Me.BUILD.Text) Then 
      MessageBox.Show("The build directory exists, moving on to create subdirectories") 
     Else 
      Try 
       'create the new directory    F:\ build \ FLIGHT # 
       My.Computer.FileSystem.CreateDirectory(dir & Me.BUILD.Text) 
       MessageBox.Show("The build directory" & dir & Me.BUILD.Text & " was created.") 
      Catch ex As Exception 
       MessageBox.Show("Doh! The build directory could not be created! Error: " & ex.Message, "Error creating directory.", _ 
           MessageBoxButtons.OK, MessageBoxIcon.Error) 
      End Try 

     End If 

     'verify if the flight num directory exists - or create it 
     If My.Computer.FileSystem.DirectoryExists(new_flightnum_directory) Then 
      MessageBox.Show("The flight # folder already exists! Check that you have the right Flight #.") 
     Else 
      Try 
       'create the new directory    F:\ BUILD \ FLIGHT # 
       My.Computer.FileSystem.CreateDirectory(new_flightnum_directory) 

       'Now create new subDirectories 
       My.Computer.FileSystem.CreateDirectory(new_video_directory) 

       MessageBox.Show("The new flight directory & video CAM subdirectories have been created! The videos will be moved and files converted now which will take some time.") 

      Catch ex As Exception 
       MessageBox.Show("Doh! The flight num or CAM directory could not be created! Error: " & ex.Message, "Error creating directory.", _ 
           MessageBoxButtons.OK, MessageBoxIcon.Error) 
      End Try 
     End If 


     '***END CREATE STORAGE DIRECTORY STRUCTURE *** 





     MessageBox.Show("new merged video file has been created in " & dir & Me.BUILD.Text & "\" & Me.CAM.Text) 

    End Sub 

End Class 
+0

當你說'抱怨我和操作員'時,你會得到什麼錯誤信息? –

+0

未爲'String'和'System.IO.FileInfo'類型定義運算符'&'。所以我理解的是我傳入的字符串psi.Arguments不喜歡我發送一個字符串和一個變量附加使用'&'操作符的事實...我只是使用逗號或如何將變量movedFileInfo追加到ffmpeg -i? psi的定義如上ProcessStartInfo ...所以我不知道什麼類型的VB認識它...我還沒有找到ProcessStartInfo啓動我的ffmpeg EXE信息。 –

+0

謝謝。您還應該編輯您的問題以包含此信息,以便其他答覆者更容易看到。 –

回答

2

的問題是,在操作者&在VB只用來連接System.String對象。它比使用+連接更嚴格。您不能使用它將StringSystem.IO.FileInfo對象連接在一起。你想要的是從FileInfo對象中獲取文件名。它有一個屬性FileInfo.FullName,它將返回文件的完整路徑,作爲String - 從documentation

嘗試,而不是:

For Each foundFile As String In My.Computer.FileSystem.GetFiles(video_card_dir, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.MTS") 
    Dim movedFileInfo As New System.IO.FileInfo(foundFile) 
    psi.Arguments = "ffmpeg -i " & movedFileInfo.FullName & " -vcodec -c libx264 " & movedFileInfo.FullName & ".mp4" 
    psi.ToString() 
    proc = Process.Start(psi) 
Next 

如果你想與.mp4更換.mts擴展,而不是簡單地追加.mp4,因爲這不代碼,請參閱this question

+0

這可以轉換爲字符串,然後轉換文件到.MTS.MP4,而不是使用movedFileInfo&「.mp4」...有沒有另一種選擇將最後一部分轉換爲字符串,但不利用文件類型.MTS? –

+0

謝謝。如果它適合您,請點擊答案左側的勾號將其標記爲「已接受」。正如我在我的答案中提到的,更改擴展名(而不是附加到它的mp4)是一個不同的問題,這是回答[這裏](http://stackoverflow.com/questions/7356205/remove-file-extension-from-一個字符串對的一檔)。我將編輯我的問題以包含鏈接。 –

+0

完美thx!在此期間,我只是使用了一個temp,然後調用了temp + = 1,因爲在這一點上如果我維護文件名並不重要......我的下一個問題是進度條,所以我會在這裏搜索下一個。 –