7

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.

ND1010_
  • 3,743
  • 24
  • 41

2 Answers2

6

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

ND1010_
  • 3,743
  • 24
  • 41
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • it will crash Log: Error initializing complex filters. Invalid argument – ND1010_ Mar 19 '18 at 12:53
  • [AVFilterGraph @ 0xf26d4740] No such filter: '' Error initializing complex filters. Invalid argument – ND1010_ Mar 19 '18 at 12:54
  • What i need to do is overlay multiple videos over single video the inputs may contains are more than 3 – ND1010_ Mar 19 '18 at 12:58
  • i did not understand the concept for the same bro – ND1010_ Mar 19 '18 at 13:06
  • why need to put delay to last added video ? – ND1010_ Mar 19 '18 at 13:08
  • and can you please tell me the breaf info for this line '[3]setpts=PTS+5/TB[3d];' – ND1010_ Mar 19 '18 at 13:10
  • Your overlay video is 3 seconds long but you're overlaying it at 5 seconds. Now, ffmpeg overlay takes the frame with timestamp 5s from both inputs but that's beyond the EOF of the overlay input. So, we need to change timestamps so that start of overlay video happens at timestamp 5. The syntax for that is `setpts=PTS+X/TB` where X is delay in seconds. – Gyan Mar 19 '18 at 13:17
  • ok that means i should have to put time delay to last added video ? – ND1010_ Mar 19 '18 at 13:24
  • You have to add time delay to any overlay video whose overlay doesn't start at time 0 of the base video. – Gyan Mar 19 '18 at 13:26
  • ok can we talk this by tomorrow ? because my input video is dynamic and i have to manage those thanks for your support – ND1010_ Mar 19 '18 at 13:28
  • hey @Mulvya i can not getting sound of overlay video – ND1010_ Mar 20 '18 at 05:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/167144/discussion-between-nd1010-and-mulvya). – ND1010_ Mar 20 '18 at 07:18
  • need your help can you please join into chat room – ND1010_ Mar 20 '18 at 12:49
  • thank you for your support can you please edit answer with that command which i want because i am new for FFMPEG – ND1010_ Mar 20 '18 at 12:56
  • You have to add the new lines, not change existing ones. – Gyan Mar 20 '18 at 13:27
  • as you tell me i have added at to the new line but only first video overlay with sound others are still not with sound overlay – ND1010_ Mar 20 '18 at 13:36
  • As you told me i have update my command with existing one and added new command to new line but still getting only first video sound (Updated cmd is in question) – ND1010_ Mar 21 '18 at 04:38
  • Sorry, forgot about amix requirements. Use edited lines. If you have more channels in an input, add those many entries e.g. for 5 channels, `adelay=30000|30000|30000|30000|30000` – Gyan Mar 21 '18 at 05:31
  • can i increase the process speed in this command i have already used **-preset** **ultrafast** command for increasing command speed – ND1010_ Apr 09 '18 at 11:13
1
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

dong
  • 21
  • 1