how to run this dos command?

BlitzMax Forums/BlitzMax Programming/how to run this dos command?

ImaginaryHuman(Posted 2015) [#1]
I am trying to run ffmpeg from blitz to do some batch video building, converting an image sequence to an mp4 video and adding an m4a audio to it. the command works perfectly fine from the dos prompt:

c:\ffmpeg\bin\ffmpeg.exe -framerate 30 -i M:\Video\AshleyLamps\Grabs\L201944\%06d.png -i M:\Video\Pressure-105.m4a -c:v libx264 -c:a copy -r 30 -pix_fmt yuv420p M:\Video\AshleyLamps\Grabs\test.mp4

However, getting this to run from blitz has been a total disaster. I've tried just about every method. System_ command, CreateProcess, etc, other exotic commands, even creating a batch file with this exact line in it and calling it from system_. None of them work. They do not accept the paramaters, and I think it's because they are hyphen-based rather than slash-based, and so the batch keeps interpreting them wrong or something. I also tried a 'START' "" within the batch file and that didn't take the paarmaters either.

What am I doing wrong? Why would this working command not work in a `test.bat` file called by the `system_` command? It will say like 'paramter framerate not found' or having trouble splitting the paramters, etc. How can I get blitz to execute ffmpeg to run this command correctly?


Floyd(Posted 2015) [#2]
Can you run cmd.exe? Maybe run that with the name of a batch file as an argument. You might need quotes around the batch file name if there are spaces in the path.

That's all guesswork based on no experience. Another possibility is to examine the source for MaxIDE, which must be calling command line tools.


grable(Posted 2015) [#3]
It should be able to, none of the methods you mentioned do any significant parsing of the commandline other than quotes and spaces.

I tried it on my end with fudged filenames and it ran without trouble.
The resulting test.mp4 didnt do much though with my bogus files, but ffmpeg didnt complain.

EDIT: The resulting commandline after my fudgning: c:\Program Files\FFmpeg For Audacity\ffmpeg.exe -framerate 30 -i C:\dump\%06d.png -i c:\dump\Pressure-105.m4a -c:v libx264 -c:a copy -r 30 -pix_fmt yuv420p C:\dump\test.mp4
With a random m4a file and 2 png images as input.

EDIT2: Alternativly you could try this:
Extern "C"
   Function system:Int( cmd$z)
EndExtern

system(...)

They all end up calling CreateProcess in the end anyway, its just that libc system runs the command via "cmd /c ..." explicitly.


markcw(Posted 2015) [#4]
I know this sort of thing sucks. So is there not a frontend for ffmpeg?


RustyKristi(Posted 2015) [#5]
I know this sort of thing sucks. So is there not a frontend for ffmpeg?


Avanti
http://www.avanti.arrozcru.org



-Easy access to all FFmpeg codecs and basic encode settings.
-All advanced options are available through FFmpeg scripting (built-in editor).
-All settings are saved and restored at the next session.
-All encoder settings, user additions and scripts can be saved in template files.
-Re-formatted FFmpeg log output at Avanti GUI for better readability.
-Display of estimated encode time, remaining time and encode speed.
-Option to auto-shutdown your system after encoding and job processing.
-Option to process system controlled 2-pass encoding.
-Advanced batch job processing (allows per job settings through user templates).
-ES option to encode elementary (mpeg2/mp2/ac3) streams for DVD authoring.
-Option to modify mpeg2 header flags (incl. 2:3 pulldown on 23.976 p).
-Option to modify AVI header fields (FourCC and frame rate).
-Selectable AviSynth AUTO and USER modes with built-in AviSynth Editor.... (supports --virtual source paths which allows scripts to run from templates).
-Internal Video Preview with AviSynth script preview (debug) option.
-Selectable FFmpeg/AviSynth advanced color correction (with preview).
-Selectable FFmpeg/AviSynth crop/scale/pad option (with preview and calculator).
-Selectable FFmpeg/AviSynth subtitle mux/burn option (with style editor/preview).
-Support for the VirtualDub (*.vdr) frameserver format through AviSynth wrapper.
-Option to convert PAL video source to NTSC destination and vice-versa.
-Option to convert audio from PAL to NTSC and vice-versa (with pitch correction).
-Option to modify luminance level from 16-235 to 0-255 and vice-versa.
-18-bands audio equalizer with feq preset editor and preview option.
-Off-line context sensitive chm help (direct access to related topic at F1 press).


ImaginaryHuman(Posted 2015) [#6]
Ok thanks for the input and trying it. What I'm doing is I need to build multiple mp4's with m4a audio added, from folders filed with image files. So far I have not found any software frontend that can do more than one such video at a time, that's why I'm in blitzmax. If you know of a video tool that can create multiple videos from multiple sets of images + audio totally unattended, please let me know.

For me the ffmpeg command works fine also, in cmd.exe... which is not my question. The question is, how do I get this working command to work from blitzmax. That's where it just does not want to seem to cooperate no matter how I launch it. System_, createprocess, whatever, none of them will work and the console that opens will just report various errors with interpreting the options.

As far as doing this in a batch file goes.. I dont have experience with batches but I did generate a test.bat file with the exact same command in it, and then run it from system_ etc... the batch will run but, once again, it will have problems interpreting the options. ffmpeg will run but either the batch executor messes up the options or something.


ImaginaryHuman(Posted 2015) [#7]
Like here is the contents of my temp.bat file that I output... it's exactly the same as the text I type directly into the command prompt.

C:\ffmpeg\bin\ffmpeg.exe -framerate 30 -i M:\Video\Pressure-105.m4a -i M:\Video\AshleyLamps\Grabs\L201944\%06d.png -c:v libx264 -c:a copy -r 30 -pix_fmt yuv420p M:\Video\AshleyLamps\Grabs\L201944.mp4

If I then manually run this batch from the command prompt ie `temp.bat` ... the output is a bunch of ffmpeg info and then a red error message:

"Option framerate not found."

Yet this exact same command run from the command prompt itself has absolutely no problem running.

So how does putting it into a batch file cause it to fail?


Henri(Posted 2015) [#8]
Hi,

hmm... I downloaded ffmpeg binary from http://ffmpeg.zeranoe.com/builds/ and listing the options with -h long I could not see -framerate option. -r option is setting the framerate for output.
Does one need to set framerate for input ?

EDIT: OK, framerate is used probably on picture duration. What if you put your picture include right after -framerate option instead of audio file?

-Henri


degac(Posted 2015) [#9]
Hi

In many Bmax applications I'm using at work I need to run external cmd tools (like xls2csv.exe, pdftk etc).

Basically I'm using CreateProcess to handle this (below my implementation, copied from some thread & modified in time for my needs).
Some times I got problems with 'strange' file name... but it works.

Just an idea.
I never used FFMPEG from cmd, but have you tried some 'short' commands (like the one on the main page of FFMPEG - ffmpeg -i input.mp4 output.avi) to see if it didn't work in general or only with specific combination of parameters?



DoProcess(AppDir+"/dati/pdftk.exe "+Chr(34)+dest_file+Chr(34)+" burst output")


DoProcess("cl-csv2xls.exe -i~q"+so+"~q -o~q"+de+"~q -s59 -n2.3.4.5")




ImaginaryHuman(Posted 2015) [#10]
It seems not to work in general from a batch file. Regardless of whatever the first option is.

'framerate' is a valid option and the command has absolutely nothing wrong with it. As I've said twice now, it absolutely works fine when you type this into the command prompt. The ONLY problem I am having is that it is not working from a batch file, or some other method to pass the parameters from blitz. I tried the createprocess using exactly the same string of commands and it doesn't appear to work either.


ImaginaryHuman(Posted 2015) [#11]
I think I found part of the problem. In the image filename I am using a pattern %06d which means a 6-digit padded number in the filename. It seems the batch file does not like this and strips out the `%06`. When I replace that with a full filename it works (provided I remove the `-framerate 30`) which does seem to also be a problem.

Question now is how to get the batch to now be affected by the wildcard.


ImaginaryHuman(Posted 2015) [#12]
Ok i got it solved. Thanks for the tip about -framerate, I took that out. Then I found that in batch files a % sign is interpreted to mean an input paramter, so the batch itself was stripping that from the command and using it (replacing it with the name of the batch file). Using %% in place of % is an escape sequence version of %, which now works.

Thanks all!


Henri(Posted 2015) [#13]
Hi,

as I studied a bit further I found that -framerate option exists (it's bit older and i believe -r can be used in it's place) and it's used to effect frame/picture duration like for example "-framerate 1/5" equals 5 seconds. But it doesn't apply to audio.

I believe that your original problem was this:


When I run this (as seen in your post #7) from cmd prompt:
C:\ffmpeg\bin\ffmpeg.exe -framerate 30 -i G:\Videos\Pressure-105.m4a -i G:\Videos\AshleyLamps\Grabs\L201944\%06d.png -c:v libx264 -c:a copy -r 30 -pix_fmt yuv420p G:\Videos\AshleyLamps\Grabs\L201944.mp4

... I get 'Option framerate not found' error.


When I run this (as seen in your first post) from cmd prompt:
c:\ffmpeg\bin\ffmpeg.exe -framerate 30 -i G:\Videos\AshleyLamps\Grabs\L201944\%06d.png -i G:\Videos\Pressure-105.m4a -c:v libx264 -c:a copy -r 30 -pix_fmt yuv420p G:\Videos\AshleyLamps\Grabs\test.mp4

... it runs ok.

-Henri


xlsior(Posted 2015) [#14]
Another issue that you may be running into calling it directly from blitz (without batch files, etc.) could be that it can't tell the difference between the command and the parameters - it's interpreting the entire string as your executable name, which doesn't exists.

To address that, try putting double quotes around the path\ffmpeg.exe part of the command.

(e.g. chr$(34)+"c:\ffmpeg.exe"+chr$(34)+" -a -b -c -d -whatever"


Matty(Posted 2015) [#15]
I use ffmpeg all the time and ran into similar problems that you describe. There is a way around it - handling the % s since these are used as arguments from the commandline.

Instead - put the batch file in a .txt file or similar and call it like this cmd < mybatchfile.txt


Fielder(Posted 2015) [#16]
you can use this: (just an example)
temp_proc:Tprocess = CreateProcess(windowsfolder+"\sysnative\reg.exe QUERY "+Chr(34)+"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"+Chr(34),1)



ImaginaryHuman(Posted 2015) [#17]
Well I got it working... just FYI .... to do it in a batch file, any % in the command, which I was using as a wildcard thing for the image filenames, must be escaped, like %% instead of %. Once that was done, I still had an issue of it saying parameter 'framerate' was not found. But what I discovered was a) i had to add a `-f image2` at the beginning, plus then also the order in which the input files are listed is important - you must list the image input file before the audio input, otherwise the framerate command seems to try to apply to the length of the audio file and not produce the proper framerate result (it was defaulting to 25 instead of 30 that I wanted). It works fine now.

I cannot, however, get it to work with CreateProcess. It works with system_ and openurl().