B4J Question JShell Problem

Firpas

Active Member
Licensed User
Longtime User
Hello to everybody

I`m trying to execute a command from my application through JShell but i can`t, however if i write it in system symbol window it run ok.

With this code:

B4X:
If File.Exists(FM.FotoDir, "test.mp4") Then
        File.Delete(FM.FotoDir, "test.mp4")
End If
       
Dim Sh As Shell
       
Sh.Initialize("Shell", File.Combine("C:\ffmpeg64\bin", "ffmpeg.exe"), Array As String(" -r 10", "-f image2", "-s 640x480", "-i "& File.Combine(FM.TempDir, "%08d.png"), "-vcodec libx264", "-crf 25", "-pix_fmt yuv420p " & File.Combine(FM.FotoDir, "test.mp4")))

Sh.WorkingDirectory = "C:\ffmpeg64"
Sh.Run(100)

Here is the result

Waiting for debugger to connect...
Program started.
ffmpeg version N-87871-g7480f232d2 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 79.100 / 55. 79.100
libavcodec 57.108.100 / 57.108.100
libavformat 57. 84.100 / 57. 84.100
libavdevice 57. 11.100 / 57. 11.100
libavfilter 6.108.100 / 6.108.100
libswscale 4. 9.100 / 4. 9.100
libswresample 2. 10.100 / 2. 10.100
libpostproc 54. 8.100 / 54. 8.100
Unrecognized option 'r 10'.
Error splitting the argument list: Option not found

It seems the option "-r 10" is passed as "r 10"

And with this code:

B4X:
If File.Exists(FM.FotoDir, "test.mp4") Then
       File.Delete(FM.FotoDir, "test.mp4")
 End If
       
Dim Sh As Shell
Sh.Initialize("Shell", File.Combine("C:\ffmpeg64\bin", "ffmpeg.exe") & " -r 10 -f image2 -s 640x480 -i "& File.Combine(FM.TempDir, "%08d.png")     & " -vcodec libx264 -crf 25 -pix_fmt yuv420p " & File.Combine(FM.FotoDir, "test.mp4"),Null)

Sh.WorkingDirectory = "C:\ffmpeg64"
Sh.Run(100)

The result is:

org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "C:\ffmpeg64\bin\ffmpeg.exe -r 10 -f image2 -s 640x480 -i C:\Users\Fran\AppData\Roaming\IpCam\Temp\%08d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p C:\Users\Fran\AppData\Roaming\IpCam\Images\test.mp4" (in directory "C:\ffmpeg64"): CreateProcess error=2, El sistema no puede encontrar el archivo especificado)

But if i copy and paste the command "C:\ffmpeg64\bin\ffmpeg.exe -r 10 -f image2 -s 640x480 -i C:\Users\Fran\AppData\Roaming\IpCam\Temp\%08d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p C:\Users\Fran\AppData\Roaming\IpCam\Images\test.mp4" in a system symbol window it run ok.

Thank in advance
 

stevel05

Expert
Licensed User
Longtime User
I haven't used it for a while, but I think you need to pass all the arguments using the Arguments method.
B4X:
sh.Arguments =

Edit : Sorry, you need to pass them to the intialize method as a list.

B4X:
Dim L As List = Array As String("-r 10","-f image2") 'etc.

sh.Initialize("Shell",File.Combine("C:\ffmpeg64\bin", "ffmpeg.exe"),L)
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Remove the space in front of the -r? You have " -r 10", try "-r 10".
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
"-pix_fmt yuv420p " & File.Combine(FM.FotoDir, "test.mp4")
I think this should be
B4X:
"-pix_fmt yuv420p", File.Combine(FM.FotoDir, "test.mp4")
making it
B4X:
Sh.Initialize("Shell", File.Combine("C:\ffmpeg64\bin", "ffmpeg.exe"), Array As String("-r 10", "-f image2", "-s 640x480", "-i "& File.Combine(FM.TempDir, "%08d.png"), "-vcodec libx264", "-crf 25", "-pix_fmt yuv420p", File.Combine(FM.FotoDir, "test.mp4")))
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Yes, i know the destination file is another option.
I've tried as you say, but it does not work.

Here is the log:

Waiting for debugger to connect...
Program started.
0
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Unrecognized option 'r 10'.
Error splitting the argument list: Option not found

Thanks for you reply
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It's this
B4X:
Array As String("-r","10", "-f", "image2", "-s", "640x480", "-i", File.Combine(File.DirTemp, "%08d.png"), "-vcodec", "libx264", "-crf", "25", "-pix_fmt", "yuv420p", File.Combine(File.DirApp, "test.mp4")
Anytime you have a space between parameters, even if they are values for the previous parameter, they are separate parameters. And no, it's not just FFmpeg (I also tried GraphicsMagick) and it's not just the new 1.5 version of JShell (the same happens with 1.3). In the end this really makes sense if you think about it.
 
Upvote 0

Alexander Vallecillo

Member
Licensed User
dHb27b

Nueva_imagen_de_mapa_de_bits.jpg


  1. alguien que me ayude con este problema porfa
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top