2

I'm trying to run a Linux command in Java.

This is the command:

"ffmpeg -i rtmp://192.168.1.112/garage/stream26g -f mpegts -acodec libmp3lame -ar 48000 -ab 64000 -s 480x320 -r 30 -vcodec libx264 -b 544k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 2 -refs 0 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 544k -bufsize 544k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 30 -qdiff 4 -level 30 -aspect 480:320 -g 30 -async 2 - | vod - 10 stream/stream26g/sample stream/stream26g/stream.m3u8 http://www.tshizerbia.com//video/ 5";

But it gives me an error:

Unable to find a suitable output format for |

And I don't know what is the problem

I used this to run the command

Process p = Runtime.getRuntime().exec(command);

If I put \\| in the string the message error is:

Unable to find a suitable output format for \|

How can I escape this character? Any ideas?

matts
  • 6,738
  • 1
  • 33
  • 50
user1812668
  • 83
  • 1
  • 5
  • 1
    possible duplicate of [perform same operation as linux pipe in java?](http://stackoverflow.com/questions/10389632/perform-same-operation-as-linux-pipe-in-java) – jlordo Mar 15 '13 at 17:16
  • 1
    Possible duplicate of [Execute a linux terminal command in java?](http://stackoverflow.com/questions/12364315/execute-a-linux-terminal-command-in-java) – matts Mar 15 '13 at 17:19
  • Unrelated to your current issue, but declaring each libx264 option is not recommended. That's what the encoding presets are for. Instead your command could be: `ffmpeg -i input -f mpegts -acodec libmp3lame -ar 48000 -b:a 64k -s 480x320 -r 30 -vcodec libx264 -preset fast -b:v 544k -maxrate 544k -bufsize 544k -level 30 -g 30 -async 2 -`. See the [FFmpeg and x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide). – llogan Mar 15 '13 at 18:45

4 Answers4

1

Try quoting the pipe character. I don't think it needs to be Java-escaped; I think it needs to be shell-quoted. Of course then you'll have to Java-escape the double-quote characters:

...-async 2 - \"|\" vod - 10 ...
rgettman
  • 176,041
  • 30
  • 275
  • 357
1

The pipe "|" is shell specific. Try executing it through a shell instead, something like

String[] bashCommand = {"/bin/bash", "-c", command};

and execute this bashCommand instead.

Steinar
  • 5,860
  • 1
  • 25
  • 23
0
Process p = Runtime.getRuntime().exec("ffmpeg -i rtmp://192.168.1.112/garage/stream26g -f mpegts -acodec libmp3lame -ar 48000 -ab 64000 -s 480x320 -r 30 -vcodec libx264 -b 544k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 2 -refs 0 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 544k -bufsize 544k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 30 -qdiff 4 -level 30 -aspect 480:320 -g 30 -async 2 - \\| vod - 10 stream/stream26g/sample stream/stream26g/stream.m3u8 http://www.tshizerbia.com//video/ 5");
1218985
  • 7,531
  • 2
  • 25
  • 31
  • 1
    @syb0rg the question has been edited since to change from \ to \\ – Majid Laissi Mar 15 '13 at 17:23
  • 1
    @MajidLAISSI The question was only edited to add code-quotes (backticks). Without the code-quotes, Markdown renders a double backslash only once, because it treats the first one as an escape character. – matts Mar 15 '13 at 17:32
0

Try escaping it with \\|. Works for Java, but I'm not sure specifically for linux command as you're asking.

fcm
  • 6,305
  • 5
  • 24
  • 37