0
votes
String[] code = new String[]{"ffmpeg", "-i","D:/ffmpeg/20170201_164127.mp4",

            "-i","D:/ffmpeg/cc.png", "-filter_complex",

            "[0:v][1:v]overlay=main_w-overlay_w-5:main_h-overlay_h-5",
            "drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'[email protected]:fontsize=70:x=10:y=H-th-10:box=1:[email protected]:boxborderw=5:x=10:y=H-th-10",

            "[out]","-map", "[out]", "-map", "2:0",
            "-acodec","mp3", "D:/ffmpeg/test7.mp4"};



            Process processDuration = new ProcessBuilder(code).redirectErrorStream(true).start();

            StringBuilder strBuild = new StringBuilder();

            try (BufferedReader processOutputReader = new BufferedReader(new InputStreamReader(processDuration.getInputStream(), Charset.defaultCharset()));) {

                String line;

                while ((line = processOutputReader.readLine()) != null) {

                    strBuild.append(line + System.lineSeparator());

                }

                processDuration.waitFor();

            }

            String outputJson = strBuild.toString().trim();

            System.out.println(outputJson);

            }

When i use only images the code is correctly. But when I use all the code this happens:

[NULL @ 00000000006abe60] Unable to find a suitable output format for 'drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'[email protected]:fontsize=70:x=10:y=H-th-10:box=1:[email protected]:boxborderw=5:x=10:y=H-th-10' drawtext=fontfile=/ffmpeg/Arial.ttf:text='TESTING'[email protected]:fontsize=70:x=10:y=H-th-10:box=1:[email protected]:boxborderw=5:x=10:y=H-th-10: Invalid argument

1
Please add more information: What happens if you try to run that command in CMD? What does this message come from (Exception is thrown, standard output stream, error stream)? - Dominik Kunicki
You're telling ffmpeg that the drawtext filter is the output file. I'm not a Java user, but it's likely a quoting, comma, and/or linebreak issue. Showing the actual ffmpeg command the code produces will show where the issue is. Also, use aac instead of mp3 for MP4: some mainstream, crappy players have trouble decoding that combination. - llogan
When i try with cmd code is fine the program work corectly. But when i try with java not work. - MaF

1 Answers

0
votes

If, as it seems, a space is inserted after each argument in the string, then that explains the error. You haven't enclosed the entire filter_complex in quotes, so a space is inserted between the overlay and drawtext. To FFmpeg, it looks like you terminated the filter_complex with the overlay and hence the drawtext string represents the output.

So either provide the entire filter_complex argument in one string including upto [out] with no whitespace in between OR add a opening double quote before [0:v] and closing quote after [out]. You probably have to escape those quotes.