patriciaxxx
Programmer
I have the following code which loops through one or more files and copys audio mp3 from mp4 files using ffmpeg. The code works but the problem is it opens a new ffmpeg window process for each file it processes and this is not good.
Can any one show me how to do this in just one process ie one ffmpeg window opening up, better still one hidden window?
Dim ffmpegpath As String
ffmpegpath = CurrentProject.path & "\"
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim i As Long
Dim convertedFile As String
For i = 1 To UBound(sourcePaths)
convertedFile = Me.Text0 & "\" & Left(Mid(sourcePaths(i), InStrRev(sourcePaths(i), "\") + 1), InStrRev(Mid(sourcePaths(i), InStrRev(sourcePaths(i), "\") + 1), ".") - 1) & ".mp3"
wsh.Run """" & ffmpegpath & "ffmpeg.exe"" -i """ & sourcePaths(i) & """ -q:a 0 -map a """ & convertedFile & """"
Next i
On the same not but a different approach the following line in a bat file file does process many files but it only works if you click the bat file, i can't make it work from a vba fuction? ie my code above?
for %%a in (*.mp4) do ffmpeg -i "%%a" -q:a 0 -map a "files\%%~na.mp3"
Can any one show me how to do this in just one process ie one ffmpeg window opening up, better still one hidden window?
Dim ffmpegpath As String
ffmpegpath = CurrentProject.path & "\"
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim i As Long
Dim convertedFile As String
For i = 1 To UBound(sourcePaths)
convertedFile = Me.Text0 & "\" & Left(Mid(sourcePaths(i), InStrRev(sourcePaths(i), "\") + 1), InStrRev(Mid(sourcePaths(i), InStrRev(sourcePaths(i), "\") + 1), ".") - 1) & ".mp3"
wsh.Run """" & ffmpegpath & "ffmpeg.exe"" -i """ & sourcePaths(i) & """ -q:a 0 -map a """ & convertedFile & """"
Next i
On the same not but a different approach the following line in a bat file file does process many files but it only works if you click the bat file, i can't make it work from a vba fuction? ie my code above?
for %%a in (*.mp4) do ffmpeg -i "%%a" -q:a 0 -map a "files\%%~na.mp3"