1
votes

I use ffmpeg to merge mp4 and png, I use two way:

  1. use command

    String cmd = "-y -i " + in.mp4 + " -i " + in.png + " -filter_complex [0:v][1:v]overlay=0:0[out] -preset veryfast -map [out] -map 1:0 -map 0:0 -codec:a copy " + out.mp4;

output file missing audio:

  1. use command:

    String cmd = "-y -i " + in.mp4 + " -i " + in.png + " -filter_complex [0:v][1:v]overlay=0:0[out] -preset veryfast -map [out] -map 0:a -codec:a copy " + out.mp4;

=> There is audio but some mp4 file cannot merge with png file Log: Stream map '0:a' matches no streams.

What is my command missing here ?

2
Can you give full result of ffprobe?Gigone Lee
You should show the complete console output/log of each command. Otherwise it is not possible to provide an answer.llogan
I found problem here. If video don't have sound, we can't put map 0:a for it (Log: Stream map '0:a' matches no streams.). Now i check to detect this video have audio or not to make filter correct. But it make more time.mdtuyen

2 Answers

2
votes

The first, you need use ffmpeg to check mp4 info. Then you will select command with 0:a or not

            ffmpeg.execute(("-i " + filepath).split(" "), new ExecuteBinaryResponseHandler() {
                    boolean hasAudio = false;

                    @Override
                    public void onProgress(String s) {

                       if (s.matches("^\\s+Stream.+Audio.+")) {
                            hasAudio = true;
                        }
                    }

                    @Override
                    public void onFinish() {

                    }
                });
2
votes

You can do this with one command:

String cmd = "-y -i " + in.mp4 + " -i " + in.png + " \
              -filter_complex [0:v][1:v]overlay=0:0[out] -preset veryfast \
              -map [out] -map 0:a? -codec:a copy " + out.mp4;

The ? teels ffmpeg to only map the stream if it exists.