ND1010_
ND1010_

Reputation: 3841

FFMPEG - Overlay multipe videos over video at specified interval of time

I want to overlay multiple videos over a single video at specified interval of time.

have tried with different solution but it will not work as i aspect

i am use below command to overlay video over video

String[] cmdWorking3 = new String[]{"-i",yourRealPath,"-i",gifVideoFile1,"-i",gifVideoFile2,"-i",gifVideoFile3,
                "-filter_complex",
                "[0][1]overlay=100:100:enable='between(t,0,2)'[v1];" +
                        "[v1][2]overlay=130:130:enable='between(t,0,2)'[v2];" +
                        "[v2][3]overlay=150:150:enable='between(t,5,6)'[v3];",
                "-map","[v3]","-map" ,"0:a",
                "-preset", "ultrafast", filePath};

by using above command first two video completely works fine but last one will not enable

Edit:

//Working perfect

 String[] cmdWorking11 = new String[]
                {"-i",
                        yourRealPath,
                        "-i",
                        gifVideoFile1,
                        "-i",
                        gifVideoFile2,
                        "-i",
                        gifVideoFile3,
                        "-i",
                        gifVideoFile4,

                        "-filter_complex",

                        "[1]setpts=PTS+3/TB[1d];" +
                        "[2]setpts=PTS+7/TB[2d];" +
                        "[3]setpts=PTS+10/TB[3d];" +

                        "[0][1]overlay=100:100:enable='between(t,0,2)'[v1];" +
                        "[v1][1d]overlay=130:130:enable='between(t,3,6)'[v2];" +
                        "[v2][2d]overlay=130:130:enable='between(t,7,9)'[v3];" +
                        "[v3][3d]overlay=150:150:enable='between(t,10,13)'[v4];" +

                        "[1]asetpts=PTS+3/TB[1ad];" +
                        "[2]asetpts=PTS+7/TB[2ad];" +
                        "[3]asetpts=PTS+10/TB[3ad];" +
                        "[0:a][1ad][2ad][3ad]amix=4[a]",

                        "-map", "[v4]", "-map", "[a]", "-ac", "5",

                        "-preset",
                        "ultrafast",

                        filePath};

Above command is perfectly works fine but audio from the overlapped video is gone,can you please help me to solve this issue.

main Video time Duration is about 00:15 second and all overlay videos are about 3 second.

it would be great to helping out to solve this issue,Thanks in advance.

Upvotes: 7

Views: 2826

Answers (2)

dong
dong

Reputation: 21

ffmpeg -i test.mp4  -i test1.mp4 -itsoffset 2 -i test2.mp4  -i test3.mp4 -filter_complex "overlay=0:0,overlay=0:0:enable='between(t,2,15)',overlay=0:0" output.mp4 

where -itsoffset 2 mean that test3.mp4 start play at 2s, and enable='between(t,start_time,end_time)' mean this video display duration

Upvotes: 1

Gyan
Gyan

Reputation: 93329

You need to delay your 3rd overlay video to start at the time of overlay.

String[] cmdWorking3 = new String[]{"-i",yourRealPath,"-i",gifVideoFile1,"-i",gifVideoFile2,"-i",gifVideoFile3,
                "-filter_complex",
                "[3]setpts=PTS+5/TB[3d];" + 
                "[0][1]overlay=100:100:enable='between(t,0,2)'[v1];" +
                        "[v1][2]overlay=130:130:enable='between(t,0,2)'[v2];" +
                        "[v2][3d]overlay=150:150:enable='between(t,5,6)'[v3]",
                "-map","[v3]","-map" ,"0:a",
                "-preset", "ultrafast", filePath};

To keep audio as well, include in filter_complex

          [1]adelay=3000|3000[1ad];
          [2]adelay=7000|7000[2ad];
          [3]adelay=10000|10000[3ad];
          [0:a][1ad][2ad][3ad]amix=5[a]

Replace -map 0:a with -map '[a]' -ac 2

Upvotes: 6

Related Questions