4

Using ffmpeg command line I want to overlay 2 different videos on top of another (main video) at different time for different duration. I have successfully overlayed 1 video over the main video at specific time and for specific duration using following command:

ffmpeg -i main.mp4 -i first.mp4 \
-filter_complex "[1:v]setpts=PTS-32/TB[a]; \
                 [0:v][a]overlay=enable=gte(t\,5):eof_action=pass[out]; \
                 [1] scale=480:270 [over]; [0][over] overlay=400:400" \
-map [out] -map 0:a \
-c:v libx264 -crf 18 -pix_fmt yuv420p \
-c:a copy \
output.mp4

How can i modify the same command to apply the same operations on two secondary videos at the same time?

Qandeel Abbassi
  • 999
  • 7
  • 31
  • Your current command is generating two video steams in the output. If you don't want to scale the secondary video, omit `[1] scale=480:270 [over]; [0][over] overlay=400:400` – Gyan Mar 17 '18 at 07:37
  • i want to scale and position too, what should I do to correct it? (1 stream) – Qandeel Abbassi Mar 17 '18 at 08:02

1 Answers1

1

Corrected version of your command:

ffmpeg -i main.mp4 -i first.mp4 \
-filter_complex "[1:v]setpts=PTS-32/TB,scale=480:270[a]; \
                 [0:v][a]overlay=400:400:enable=gte(t\,5):eof_action=pass[out]" \
-map [out] -map 0:a \
-c:v libx264 -crf 18 -pix_fmt yuv420p \
-c:a copy \
output.mp4

For two secondary videos,

ffmpeg -i main.mp4 -i first.mp4 -i second.mp4 \
-filter_complex "[1:v]setpts=PTS-32/TB,scale=480:270[a]; \
                 [2:v]setpts=PTS-32/TB,scale=480:270[b]; \
                 [0:v][a]overlay=400:400:enable=gte(t\,5):eof_action=pass[out0]; \
                 [out0][b]overlay=400:400:enable=gte(t\,5):eof_action=pass[out]" \
-map [out] -map 0:a \
-c:v libx264 -crf 18 -pix_fmt yuv420p \
-c:a copy \
output.mp4

You'll have to adjust the PTS, scale, position and timing of 2nd overlay to see it doesn't overlap with first one.

Gyan
  • 85,394
  • 9
  • 169
  • 201