Jump to content

Problems with run


chelo32
 Share

Recommended Posts

Question for forum scholars. I can't run a script that I have done in batch

this is the batch code, It works well

@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "dir C:\Mp4"

if not exist "%Dir%\*" md "%Dir%" || (timeout 3 & goto :ffmpeg)


endlocal

:ffmpeg

for %%a in ("*.ogg" , "*.mp3" , "*.m4a") do (
  "d:\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "d:\bin\img.jpg"
  "d:\bin\ffmpeg.exe" -loop 1 -i  "d:\bin\img.jpg" -i "%%a" -y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "%dir%\%%a.mp4" )
echo "%dir%\%%a.mp4" CREADO CON EXITO....
timeout 3
exit

I am trying this but with no result.

$jpg = "d:\bin\img.jpg"
$file = @ScriptDir & "KISSING A FOOL.m4a"
$ffmpeg = @ScriptDir & "ffmpeg.exe"
 Run(@ComSpec & " /C " & "ffmpeg.exe -i ""KISSING A FOOL.m4a"" -an -y -vcodec copy" & $jpg, @SW_SHOW)
  Run(@ComSpec & " /C " & "ffmpeg.exe" & '-loop 1 -i "' & $jpg & '" "' & '-i  & "KISSING A FOOL.m4a"'  & '-y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest' & 'tuna-vids.mp4', @SW_SHOW)
  
  ;Run(@ComSpec & " /C " & "ffmpeg.exe" & '-i "' & $jpg & '" "' & '-i  & "KISSING A FOOL.m4a"' & '-y & "xxx.mp4"', @ScriptDir, @SW_SHOW)

Thanks for the help

Link to comment
Share on other sites

Check your single/double quotes something like:

$jpg = "d:\bin\img.jpg"
$file = @ScriptDir & "\KISSING A FOOL.m4a"
$ffmpeg = @ScriptDir & "\ffmpeg.exe"
Run(@ComSpec & ' /c "' & $ffmpeg & ' -i "' & $file & '" -an -y -vcodec copy "' & $jpg & '"')
Run(@ComSpec & ' /c "' & $ffmpeg & ' -loop 1 -i "' & $jpg & '" -i  "' & $file & '"  -y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest tuna-vids.mp4')

 

Link to comment
Share on other sites

Here is an example of looping through multiple files as your batch file does (untested):

#include <File.au3>

Local $sDir = "C:\Mp4"
Local $sffmpeg = "D:\bin\ffmpeg.exe"
Local $simgjpg = "d:\bin\img.jpg"

If Not FileExists($sDir) Then DirCreate($sDir)

Local $aFiles = _FileListToArrayRec(@ScriptDir, "*.ogg;*.mp3;*.m4a", 1, 0, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to find any files")
For $i = 1 To $aFiles[0]
    Run(@ComSpec & ' /c "' & $sffmpeg & '" -i "' & $aFiles[$i] & '" -an -y -vcodec copy "' & $simgjpg & '"')
    Run(@ComSpec & ' /c "' & $sffmpeg & '" -loop 1 -i "' & $simgjpg & '" -i "' & $aFiles[$i] & '" -y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "' & $sDir & "\" & $aFiles[$i] & '.mp4"')
    ConsoleWrite('"' & $aFiles[$i] & '.mp4" CREADO CON EXITO....' & @CRLF)
Next

 

Link to comment
Share on other sites

Hey,

Was banging my head yesterday trying to figure this out in VBA (Excel). Maybe you are getting the same issue.

For me the cmd command is:

D:\LazyD Charter\Apps>ffmpeg -i "D:\LazyD Charter\Samples\Set\Drums\locymbal.mp3" -v quiet -stats -f null -

Only this worked (SamplePath is as above), looks a bit cryptic 😛 chr(34) = "

str = "ffmpeg" & " " & Chr(34) & "-i" & Chr(34) & " " & Chr(34) & SamplePath & Chr(34) & " " & Chr(34) & "-v" & Chr(34) & " " & Chr(34) & "quiet" & Chr(34) & " " & Chr(34) & "-stats" & Chr(34) & " " & Chr(34) & "-f" & Chr(34) & " " & Chr(34) & "null" & Chr(34) & " " & Chr(34) & "-" & Chr(34)

So, encapsulate all parameters with double quotes and leave no spaces in there, and add spaces with & " " & if you need to.

See if that works.

Edit: In my case, working directory is already where ffmpeg.exe is, so no need to put full path.

By the way, I couldn't get the cmd window to open silently in this case and processing too many files was not going to look good. So, I open 1 console window and send the commands using stdin. Terminate console once done. Maybe you can employ something similar.

A quick search resulted in:

https://www.autoitscript.com/forum/topic/199567-sending-data-to-cmd-window-using-stdin/

Edited by GokAy
Link to comment
Share on other sites

Thank, I was able to get ffmpeg running, it's simple but it gave me an idea of where my error was. Really thank you I was going crazy with so many quotes.

Local $sDir = @ScriptDir&"\Mp4.mp4"
Local $sffmpeg = "H:\bin\ffmpeg.exe"
Local $simgjpg = @ScriptDir&"\img.jpg"
Local $mp3 = @ScriptDir&"\KISSING.m4a"

Run($sffmpeg & ' -loop 1 -i "' & $simgjpg & '" -i "' & $mp3 & '" -c:a aac -ab 112k -c:v libx264 -shortest -strict -2 "' & $sDir, @ScriptDir, @SW_HIDE)

Thank you all for the help

Link to comment
Share on other sites

No problem, although you would also need a closing quote:

Run($sffmpeg & ' -loop 1 -i "' & $simgjpg & '" -i "' & $mp3 & '" -c:a aac -ab 112k -c:v libx264 -shortest -strict -2 "' & $sDir & '"', @ScriptDir, @SW_HIDE)

Normally I would use ConsoleWrite or MsgBox to check the command first something like:

Local $sDir = @ScriptDir&"\Mp4.mp4"
Local $sffmpeg = "H:\bin\ffmpeg.exe"
Local $simgjpg = @ScriptDir&"\img.jpg"
Local $mp3 = @ScriptDir&"\KISSING.m4a"

Local $sCommand = $sffmpeg & ' -loop 1 -i "' & $simgjpg & '" -i "' & $mp3 & '" -c:a aac -ab 112k -c:v libx264 -shortest -strict -2 "' & $sDir & '"'
ConsoleWrite($sCommand & @CRLF)
Run($sCommand, @ScriptDir, @SW_HIDE)

 

Link to comment
Share on other sites

Again asking for help from those who know.

I'm trying to make an audio to mp4 converter by putting a still image on the video, so I can upload it to youtube.
And the problem is in the output directory

since I need the "_FileListToArrayRec" to put the complete patch in order to convert the video.
How can I put the same output name by choosing another directory

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <Date.au3>

#Region ### START Koda GUI section ### Form=H:\bin\Form1.kxf
$Form1 = GUICreate("Form1", 694, 632, 529, 144)
$Title = GUICtrlCreatePic("", 0, 0, 692, 100)
$Pic = GUICtrlCreateInput("", 456, 352, 177, 21)
$Edit1 = GUICtrlCreateEdit("", 16, 112, 369, 433)

$Pic1 = GUICtrlCreatePic("", 440, 128, 201, 177)
$Progress1 = GUICtrlCreateProgress(16, 560, 654, 41)
$in = GUICtrlCreateInput("", 456, 384, 177, 21)
$out = GUICtrlCreateInput("", 456, 416, 177, 21)
$Label3 = GUICtrlCreateLabel("Dir IN", 400, 384, 51, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Dir Out", 400, 416, 51, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Picture", 400, 352, 51, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Start = GUICtrlCreateButton("Start", 600, 504, 75, 25)
$Exit = GUICtrlCreateButton("Exit", 496, 504, 75, 25)
$About = GUICtrlCreateButton("About", 400, 504, 75, 25)
$Pic_in = GUICtrlCreateButton("::::", 640, 352, 35, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Dir_in = GUICtrlCreateButton("::::", 640, 384, 35, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Dir_out = GUICtrlCreateButton("::::", 640, 416, 35, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$sStdErr = ""
$iTicksDuration = 0
$iTicksTime = 0
$ffmpeg = @ScriptDir&"\ffmpeg.exe"
If FileExists($ffmpeg) Then
    sleep(100)
Else
    MsgBox(4096, "Error", "ERROR, ffmpeg.exe not found.")
    Exit
    EndIf

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Exit
            Quit()

        Case $About
            _About()

        Case $Pic_in
             $img=FileOpenDialog("Open", "C:\","Picture (*.Jpg;*.jpeg;*.bmp;*.gif)")
             If @error Then MsgBox(4096, "Error", "No Picture was selected.")
                GUICtrlSetImage($pic1, $img)
                GUICtrlSetData($Pic, $img)

        Case $Dir_in
            $somefolder = FileSelectFolder("Select Encode Folder", "")
            If @error Then MsgBox(4096, "Error", "No folder was selected.")

            $Afiles = _FileListToArrayRec($somefolder, "*.ogg;*.mp3;*.m4a", 1, 0, 0, 2)
            If @error Then MsgBox(4096, "Error", "Unable to find any files")
            GUICtrlSetData($in, $somefolder)


        Case $Dir_out
            $Out_mp4 = FileSelectFolder("Select Encode Folder", "\")
            GUICtrlSetData($out, $Out_mp4)

        Case $Start
for $i = 1 to $Afiles[0]
    $file = $Afiles[$i]
    $hPid = Run($ffmpeg & ' -loop 1 -i "' & $img & '" -i "' & $file & '" -n -c:a aac -ab 112k -c:v libx264 -shortest -strict -2 "' & stringtrimright($file , 4) & '_out.mp4"', $Out_mp4, @SW_HIDE, 0x4)
    While 2
    Sleep(500)
    $sStdErr &= StderrRead($hPid)
    If @error Then
        Sleep(2000)
        ExitLoop
        EndIf
    GUICtrlSetData($Edit1,$sStdErr)
    If StringLen($sStdErr) > 0 Then
        If Not $iTicksDuration Then $iTicksDuration = _GetDuration($sStdErr)
        $iTicksTime = _GetTime($sStdErr)
        If Not @error Then $sStdErr = ""
        GUICtrlSetData($Progress1, $iTicksTime * 100 / $iTicksDuration)
    EndIf
WEnd
ProgressOff()
Next
EndSwitch
WEnd




Func _GetDuration($sStdErr)
    If Not StringInStr($sStdErr, "Duration:") Then Return SetError(1, 0, 0)
    Local $aRegExp = StringRegExp($sStdErr, "(?i)Duration.+?([0-9:]+)", 3)
    If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
    Local $sTime = $aRegExp[UBound($aRegExp) - 1]
    Local $aTime = StringSplit($sTime, ":", 2)
    If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
    Return _TimeToTicks($aTime[0], $aTime[1], $aTime[2])
EndFunc   ;==>_GetDuration

Func _GetTime($sStdErr)
    If Not StringInStr($sStdErr, "time=") Then Return SetError(1, 0, 0)
    Local $aRegExp = StringRegExp($sStdErr, "(?i)time.+?([0-9:]+)", 3)
    If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
    Local $sTime = $aRegExp[UBound($aRegExp) - 1]
    Local $aTime = StringSplit($sTime, ":", 2)
    If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
    Return _TimeToTicks($aTime[0], $aTime[1], $aTime[2])
EndFunc   ;==>_GetTime

Sorry for my bad english is not my native language
Thank you very much for the help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...