1

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 ?

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
mdtuyen
  • 4,470
  • 5
  • 28
  • 50
  • Can you give full result of ffprobe? – Gigone Lee Nov 02 '15 at 14:23
  • You should show the complete console output/log of each command. Otherwise it is not possible to provide an answer. – llogan Nov 02 '15 at 18:12
  • 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 Nov 03 '15 at 04:38

2 Answers2

2

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

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.

Gyan
  • 85,394
  • 9
  • 169
  • 201