0

This following command not working in my java module (this takes snap from live stream and save it) Runtime.getRuntime().exec("ffmpeg -i \"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\" -f image2 -vframes 1 /snaps/testo.jpg");

If I use same command on Ubuntu 14.0.4 console it works. Same command working in my red5pro module on Window but not on Ubuntu.

When I use String[] execStr = {"/usr/local/bin/ffmpeg","-i","rtmp://127.0.0.1:1935/live/mytest","live=1","timeout=2","-f","image2","-vframes","1","/snaps/tt.jpg"}; ProcessBuilder pb = new ProcessBuilder("ffmpeg -i rtmp://localhost/live/mytest live=1 timeout=2 -f image2 -vframes 1 /snaps/testo.jpg");

It always throw stream not found ( in red5pro console)

Atul
  • 44
  • 1
  • 8
  • I think your problem is `"rtmp://127.0.0.1:1935/live/mytest","live=1","timeout=2"`. You probably combine this to one parameter as `"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2"` – the kamilz Jan 23 '18 at 14:03
  • I think I did try that but let me try it again – Atul Jan 23 '18 at 14:22
  • now when I do that I get following error --->RTMP_ReadPacket, failed to read RTMP packet header --->rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2: Invalid data found when processing input – Atul Jan 23 '18 at 14:30
  • Try this too: `rtmp://127.0.0.1:1935/live/mytest?live=1&timeout=2` – the kamilz Jan 23 '18 at 14:30
  • Now said: --->rtmp server sent error Following is my code String[] execStr = {"/usr/bin/ffmpeg", "-i", "rtmp://127.0.0.1:1935/live/mytest?live=1&timeout=2", "-f", "image2" ,"-vframes", "1" ,"/snaps/ff.jpg"}; ProcessBuilder pb = new ProcessBuilder(execStr); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream())); String line2 = null; while ((line2 = in.readLine()) != null) { System.out.println("--->"+line2); } if (p.waitFor() == 0) { } – Atul Jan 23 '18 at 15:17
  • ok finally: `"\"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\""` – the kamilz Jan 23 '18 at 15:46
  • >"rtmp://127.0.0.1:1935/live/mytest?live=1&timeout=2": No such file or directory – Atul Jan 23 '18 at 15:52
  • Did you try this double quoted (") version here, inner quotes are escaped with (\") ?: `"\"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\""` – the kamilz Jan 24 '18 at 07:07
  • This is what I have used String[] execStr = {"/usr/bin/ffmpeg", "-i", "\"rtmp://127.0.0.1:1935/live/mytest?live=1&timeout=2\"", "-f", "image2" ,"-vframes", "1" ,"/snaps/ff.jpg"}; ProcessBuilder pb = new ProcessBuilder(execStr); but error is No such file or directory Now please read following points: (1)same command works when I fire on Ubuntu console. Even this works in php shell_exec(command) on same ubuntu machine.Same command also works on my window machine. I am thanking you for all your help. If you could get it work then it will be big help for me. – Atul Jan 24 '18 at 14:06

1 Answers1

0

I don't know Java (except a little, I'm experienced with FFmpeg) but I think you should write the code like this:

String[] execStr = {"/usr/local/bin/ffmpeg", "-i", "rtmp://127.0.0.1:1935/live/mytest", "live=1", "timeout=2", "-f", "image2", "-vframes", "1", "/snaps/tt.jpg"};
ProcessBuilder pb = new ProcessBuilder(execStr);

or like this:

String[] execStr = {"/usr/local/bin/ffmpeg", "-i", "\"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\"", "-f", "image2", "-vframes", "1", "/snaps/tt.jpg"};
ProcessBuilder pb = new ProcessBuilder(execStr);

I checked from here: https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

the kamilz
  • 1,860
  • 1
  • 15
  • 19
  • I did try that. You mentioned that spaces among every parameter and yes I tried that but no luck. Same problem here mentioned: https://stackoverflow.com/questions/22909434/read-rtmp-live-streaming-vido-data-using-java-code – Atul Jan 24 '18 at 14:42
  • I will have to work for it but following were errors rtmp sent errors. NetStrea.Play.StreamNotFound. No such directory exist ( this when we use quote). Invalid header found connection close ( this when we do not use live=1 that says stream is live) – Atul Jan 24 '18 at 15:51