bramp / ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
BSD 2-Clause "Simplified" License
1.68k stars 411 forks source link

Process stdout should not use CharStream.copy #354

Open Euklios opened 4 weeks ago

Euklios commented 4 weeks ago

Describe the bug setProcessOutputStream takes in an Appendable, and later uses CharStreams.copy to transfer the output as text. This does not work for most cases, as stdout is used to write the output streams. This means, an encoded file would be interpreted as chars, causing some bytes being lost due to interpretation.

To Reproduce

// appendable should be a handle to a file

FFmpeg ffmpeg = new FFmpeg();
ffmpeg.setProcessOutputStream(appenable);

ffmpeg.run(new FFmpegBuilder().addInput("input.mp4")).done().addStdoutOutput().done().build());

Expected behavior processOutputStream should be treated as binary.

Version (if applicable):

Euklios commented 4 weeks ago

It's a bit more nuanced then what I wrote above: FFmpeg will output to stderr and send the resulting file to stdout, but only if the command succeeded. If, for example, the output does not specify the format (no -f) or specifies a format that does not support seaking (-f mp4), it will still output to stdout.

However, replacing CharStreams with ByteStreams does not make a difference in that case, as the chars are just coppied as is

Euklios commented 4 weeks ago

Fix will be provided together with #334