& ошибка строки оператора со строкой аргументов для processStartInfo

Мне нужно передать строку в ProcessStartInfo для ffmpeg, чтобы я мог вызвать dim.Argument и добавить в него строки и переменные из кода, когда я анализирую файлы.

У меня есть текущее имя файла.mp3, что код видит в movedFileInfo но это не позволит мне добавить его в строку, используя & операторы... помогите?

Я знаю, что может быть еще один способ сделать это, используя команду ffmpeg в отдельной функции, чтобы просто перебрать каталог, используя "for", но я не нашел успешной команды для запуска моего ffmpeg.exe или ffprompt в windows. Мне также нужно добавить возврат каретки, когда я пишу в 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

1 ответ

Решение

Проблема в том, что & оператор в VB используется только для объединения System.String объекты. Это более строгое чем использование + соединить Вы не можете использовать его для объединения String и System.IO.FileInfo возражать вместе Вы хотите получить имя файла из FileInfo объект. У него есть атрибут, FileInfo.FullName который вернет полный путь к файлу в виде String - из документации.

Попробуйте вместо этого:

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

Если вы хотите заменить .mts расширение с .mp4вместо простого добавления .mp4 как этот код, пожалуйста, смотрите этот вопрос.

Другие вопросы по тегам