0

I'm trying to feed FFMPEG with certain bytes with the pipe operator in cmd via a Java application which should send those bytes to the stdout, but when I try to do so and proceed to testing Eclipse freezes as the console is constantly full of bytes.

I've tried hiding all that output by clicking the button which doesn't refresh the console when stdout changes, but even after doing so the bytes keep appearing sometimes and the application keeps freezing.

This is the code which is generating the problems.

static PrintStream stdout = new PrintStream(System.out);

(...)

        try {
        line = (TargetDataLine) mixer.getLine(info);
        line.open(format);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int bytesRead, CHUNK_SIZE = 4096;
        byte[] data = new byte[line.getBufferSize() / 5];

        line.start();

        while (true) {
            bytesRead = line.read(data, 0, CHUNK_SIZE);
            line.read(data, 0, CHUNK_SIZE);
            stdout.write(data, 0, bytesRead);
        }

Is there any workaround for this kind of problem?

Niconoid
  • 107
  • 2
  • 12
  • How much data are we talking about? Eclipse's console is pretty quick, but it will choke when feeding it megabytes of data... – john16384 Feb 01 '17 at 14:13
  • It's a constant streaming of live audio data coming from the Stereo Mix or any other sysmixer so it's quite a lot @john16384 – Niconoid Feb 01 '17 at 14:18
  • You could perhaps run the Java program and redirect its output to /dev/null or something. It should be possible to do so in the Run/Debug dialog in Eclipse. – john16384 Feb 01 '17 at 14:24
  • 1
    Apart from the above duplicate (because - well - if it hurts when you send the data to the Eclipse console, you should stop sending it there) - why are you wrapping a `PrintStream` around your `OutputStream`? It's not providing you any benefits at all (you're not using the auto-flush capability) and a PrintStream is meant for writing text, not binary data (although it will work if you try it) so it's only confusing to the next person who has to maintain this code – Erwin Bolwidt Feb 01 '17 at 14:28
  • 2
    Oh and your code as a bug - you're doing `line.read(data, 0, CHUNK_SIZE);` twice in a row, and remembering the number of bytes read from the first call, but when you write the data, you use the buffer from the second `read` call, while using the byte count from the first call. – Erwin Bolwidt Feb 01 '17 at 14:30

0 Answers0