Video to Gif, Command Prompt Correct Syntax Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DMDComposer
Posts: 12
Joined: 14 Jul 2018, 18:55
Contact:

Video to Gif, Command Prompt Correct Syntax

10 Dec 2019, 22:49

Hi,

I'm trying to get a commandprompt line to work in AHK but I can't figure out the correct syntax.

Code: Select all

FFMpeg:="C:\Program Files (x86)\FFmpeg\bin\ffmpeg.exe"
Magick:="C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe"
New_File_Name:="TESTING"

gif_param = -ss 2 -t 3 -i "%A_ScriptDir%\%New_File_Name%.mp4" -vf fps=30 -c:v pam -f image2pipe pipe:1 | "%Magick%" convert -delay 3.33 - -loop 0 -layers optimize "%A_ScriptDir%\%New_File_Name%.gif"
Runwait, "%FFMPeg%" %gif_param%
I've tried using comspec in this fashion but get the following error
'C:\Program' is not recongized as an internal or external command, operable program or batch file.
Is my syntax wrong and it's something to do with the spaces in my dir paths? Or, is it not possible to pipe through the run command?

My workaround for now is just to create a temp bat file and run it and everything works just dandy. But was curious if anyone had any thoughts on if and how this is possible via the Run command prompt?

Thanks,
DMDComposer
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Video to Gif, Command Prompt Correct Syntax

11 Dec 2019, 01:11

The pipe symbol is the syntax of the batch language, you need to run the command in cmd.exe.

Code: Select all

Runwait, cmd /c "%FFMPeg%" %gif_param%
DMDComposer
Posts: 12
Joined: 14 Jul 2018, 18:55
Contact:

Re: Video to Gif, Command Prompt Correct Syntax  Topic is solved

11 Dec 2019, 10:02

tmplinshi wrote:
11 Dec 2019, 01:11
The pipe symbol is the syntax of the batch language, you need to run the command in cmd.exe.

Code: Select all

Runwait, cmd /c "%FFMPeg%" %gif_param%
Thank you for your help. That makes sense as I think about it. However, I still can't get the code to work with the Runwait. However, with some digging and messing around I did get it to work the following way:

Code: Select all

#SingleInstance,Force

FFMpeg:="C:\Program Files (x86)\FFmpeg\bin\ffmpeg.exe"
Magick:="C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe"
New_File_Name:="TESTING"

gif_param = -ss 2 -t 3 -i "%A_ScriptDir%\%New_File_Name%.mp4" -vf fps=30 -c:v pam -f image2pipe pipe:1 | "%Magick%" convert -delay 3.33 - -loop 0 -layers optimize "%A_ScriptDir%\%New_File_Name%.gif"
Video_to_Gif:= """" FFMPEG """ " gif_param
RunWaitTwo("""" Video_to_Gif """ ")
;~ Runwait, cmd /c %Video_to_Gif%

RunWaitTwo(command) {
	; WshShell object: http msdn.microsoft.com /en-us/library/aew9yb99  Broken Link for safety
	shell := ComObjCreate("WScript.Shell")
	launch := "cmd.exe /c " . command
	exec := shell.Run(launch, 0, true)
	; Read and return the command's output
	Return
}

ExitApp
Return
It took some messing around for sure with this Runwait function for creating a shell object I found online. In the end to get this work I had to put quotations around my whole "command" for it to actually work. When I related that idea to your Runwait line you provided, it worked perfectly.

Here is the final short script using your Runwait Line.

Code: Select all

#SingleInstance,Force

FFMpeg:="C:\Program Files (x86)\FFmpeg\bin\ffmpeg.exe"
Magick:="C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe"
New_File_Name:="TESTING"

gif_param = -ss 2 -t 3 -i "%A_ScriptDir%\%New_File_Name%.mp4" -vf fps=30 -c:v pam -f image2pipe pipe:1 | "%Magick%" convert -delay 3.33 - -loop 0 -layers optimize "%A_ScriptDir%\%New_File_Name%.gif"
Video_to_Gif:= """" FFMPEG """ " gif_param
Runwait, cmd /c "%Video_to_Gif%"

ExitApp
Return

Thank you very much,
DMDComposer
Sweet Alert 2 for AHK - A Beautiful JS Popup MSG & Toast Notifications
https://github.com/DMDComposer/SweetAlert2-AHK
Master Search Box aka Master Script Commands v1 - AHK Gui for user commands
https://github.com/DMDComposer/MasterSearchBox
Master Script Commands v2 - AHK Gui using G33kdude's neutron for user commands
https://github.com/DMDComposer/MasterScriptCommands

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Frogrammer, jameswrightesq and 279 guests