B4J Question jShell: Quotes and spaces problem

jmon

Well-Known Member
Licensed User
Longtime User
I have a problem when using the command line for ffmpeg.exe ( https://trac.ffmpeg.org/wiki/Create a thumbnail image every X seconds of the video )

The command I need to send is "
B4X:
D:\B4J\QTFileListing\Objects>ffmpeg.exe -i "C:\folder\Out\WIP\2013_12_13\sh04_avc1.mov" -ss 00:00:01 -vframes 1 -f image2 img_15_%03d.jpg
That works perfectly in windows CMD.

This is my code in b4j:
B4X:
Dim js As Shell
Dim params As List: params.Initialize
params.Add("-i """ & fullPath & """")
params.Add("-ss 00:00:01")
params.Add("-vframes 1")
params.Add("-f image2")
params.Add("img_15_%03d.jpg")


js.Initialize("js", "ffmpeg.exe", params)
js.WorkingDirectory = File.DirApp
js.Run(-1)


The issue I have is that I get an error which shows that the spaces in the params are not interpreted correctly:
B4X:
'-i "C:\folder\Out\WIP\2013_12_17\sh04_avc1.mov' -ss: Invalid argument

the command reads until the -ss and stops there.

Is there a way to send a raw command and not using the params as a list? I have the feeling that the issue comes from there.

Thanks and Happy New year!
 

jmon

Well-Known Member
Licensed User
Longtime User
Ok... Sorry I figured out after posting my message that the issue wasn't from B4J but from Java, so here is the solution:

https://commons.apache.org/proper/commons-exec/commandline.html

and this is my code fixed:
B4X:
Dim js As Shell
Dim params As List: params.Initialize
params.Add("-i")
params.Add(fullPath)
params.Add("-ss")
params.Add("00:00:01")
params.Add("-vframes")
params.Add("1")
params.Add("-f")
params.Add("image2")
params.Add("img_15_%03d.jpg")

I just had to break every space into new params.

Thanks
 
Upvote 0
Top