调用Java从命令行/ shell脚本调用ffmpeg会引发“过滤器后的尾部垃圾”错误。

huangapple go评论92阅读模式
英文:

Calling ffmpeg from Java calling command line/ shell script throws "Trailing garbage after a filter" Error

问题

The error message "Trailing garbage after a filter" in ffmpeg typically occurs when there is an issue with the filter_complex parameter. It indicates that there might be a problem with the filter chain you've defined in your ffmpeg command.

To solve this issue, you should carefully review and correct the filter_complex parameter in your ffmpeg command. Ensure that there are no extra or incorrect characters in the filter chain, and make sure that the filter_complex parameter is properly formatted with the correct filter syntax.

Additionally, you can check if there are any special characters in your command that might need escaping, as this can sometimes lead to parsing errors in ffmpeg.

If you need further assistance with the specific ffmpeg command and its filter_complex parameter, please provide more details about the intended video processing, and I can offer more specific guidance.

英文:

Calling ffmpeg from Java throws "Trailing garbage after a filter" Error

I tried to call from Java application command string over dockerized ffmpeg, same result.

docker run --rm  -v sample-test:/config linuxserver/ffmpeg  -loop 1 -t 5 -i  config/1.jpeg  -loop 1 -t 5 -i  config/3.jpeg  -y -filter_complex "[0:v]fade=t=out:st=4:d=1[v0];  [1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1];  [v0][v1]concat=n=2:v=1:a=0,format=yuv420p[v];" -map "[v]"  config/output/video_java.mp4

My goal is to run such a query from Java application

ffmpeg \
-loop 1 -t 5 -i input0.png \
-loop 1 -t 5 -i input1.png \
-loop 1 -t 5 -i input2.png \
-loop 1 -t 5 -i input3.png \
-loop 1 -t 5 -i input4.png \
-filter_complex \
"[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v0]; \
 [1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [4:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
 [v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4


Runtime.getRuntime().exec(String.format("/bin/sh -c " + ffmpegCommand));

Why it happens and how to solve? Appreciating

答案1

得分: 0

把这个复杂的命令放入脚本中并执行以下操作。对我有效:

import java.io.*;

public class Animator {
    private static final String[] COMMAND = {
        "/bin/bash",
        "mkvid.sh"
    };
    public static void main(String[] args) throws Exception {
        Process p = new ProcessBuilder(COMMAND).redirectError(new File("ffmpeg.err.log")).redirectOutput(new File("ffmpeg.out.log")).start();
        int exitVal = p.waitFor();
        System.exit(exitVal);
    }
}
英文:

Put that complex command in a script and do the following. Works for me:

import java.io.*;

public class Animator {
    private static final String[] COMMAND = {
        "/bin/bash",
        "mkvid.sh"
    };
    public static void main(String[] args) throws Exception {
        Process p = new ProcessBuilder(COMMAND).redirectError(new File("ffmpeg.err.log")).redirectOutput(new File("ffmpeg.out.log")).start();
        int exitVal = p.waitFor();
        System.exit(exitVal);
    }
}

huangapple
  • 本文由 发表于 2023年6月29日 06:34:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定