1

I have videos as follows

video   time
======= =========
Area 1:
video1a    0-2000
video1b 2500-3000
video1c 3000-4000

Area 2:
video2a  300- 400
video2b  800- 900

Area 3:
video3a  400- 500
video3b  700- 855

Area 4:
video4a  400- 500
video4b  800- 900

Basically these are security camera outputs and should display in 4 areas:

So far I have the following:

ffmpeg
    -i 1.avi -i 2.avi -i 3.avi -i 4.avi
    -filter_complex "
        nullsrc=size=640x480 [base];
        [0:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft];
        [1:v] setpts=PTS-STARTPTS, scale=320x240 [upperright];
        [2:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft];
        [3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerright];
        [base][upperleft] overlay=shortest=1 [tmp1];
        [tmp1][upperright] overlay=shortest=1:x=320 [tmp2];
        [tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3];
        [tmp3][lowerright] overlay=shortest=1:x=320:y=240
    "
    -c:v libx264 output.mp4

But there are two things I am missing:

  • The above is only for 4 video files, I need a way to add additional files to each area (for example video1b should play at its corresponding time after video1a in the same area)
  • How do I specify the beginning/ending time as shown above for each file?
Zoe
  • 27,060
  • 21
  • 118
  • 148
Robert Smith
  • 634
  • 1
  • 8
  • 22
  • Are those times in seconds? – Gyan May 25 '18 at 06:30
  • Hi Gyan thank you, yes it is. Not all videos would start at zero as you can see. Basically screen should be black for that area if its not the time to play that video. As you can see there would be 4 areas. Thank you. – Robert Smith May 25 '18 at 12:10

1 Answers1

2

Use

ffmpeg
    -i video1a -i video2a -i video3a -i video4a
    -i video1b -i video2b -i video3b -i video4b
    -i video1c
    -filter_complex "
        nullsrc=size=640x480 [base];
        [0:v] setpts=PTS-STARTPTS+   0/TB, scale=320x240 [1a];
        [1:v] setpts=PTS-STARTPTS+ 300/TB, scale=320x240 [2a];
        [2:v] setpts=PTS-STARTPTS+ 400/TB, scale=320x240 [3a];
        [3:v] setpts=PTS-STARTPTS+ 400/TB, scale=320x240 [4a];
        [4:v] setpts=PTS-STARTPTS+2500/TB, scale=320x240 [1b];
        [5:v] setpts=PTS-STARTPTS+ 800/TB, scale=320x240 [2b];
        [6:v] setpts=PTS-STARTPTS+ 700/TB, scale=320x240 [3b];
        [7:v] setpts=PTS-STARTPTS+ 800/TB, scale=320x240 [4b];
        [8:v] setpts=PTS-STARTPTS+3000/TB, scale=320x240 [1c];
        [base][1a] overlay=eof_action=pass [o1];
        [o1][1b] overlay=eof_action=pass [o1];
        [o1][1c] overlay=eof_action=pass:shortest=1 [o1];
        [o1][2a] overlay=eof_action=pass:x=320 [o2];
        [o2][2b] overlay=eof_action=pass:x=320 [o2];
        [o2][3a] overlay=eof_action=pass:y=240 [o3];
        [o3][3b] overlay=eof_action=pass:y=240 [o3];
        [o3][4a] overlay=eof_action=pass:x=320:y=240[o4];
        [o4][4b] overlay=eof_action=pass:x=320:y=240"
    -c:v libx264 output.mp4

The shortest option should be applied to the overlay which processes the stream ending at the latest time.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thank you Gyan! I am going to give that a try. One question, is there a way that ffmpeg can determine which video has sound and add the sound from that video? (Even if multiple videos have sound) – Robert Smith May 25 '18 at 13:52
  • @RobertSmith You can `ffprobe` beforehand to determine audio streams, then build `ffmpeg` command from the resulting info. [Example commands](https://stackoverflow.com/a/32289198/1109017). IIRC, I made a simple bash script example doing this somewhere on SE, but I can't find it. – llogan May 25 '18 at 18:56
  • Thank you Gyan and LordNeckBeard. Once I identify the videos that have sound, how would I change above? For example lets say I find that video2a and video3b have sound, what would be the change above? Thank you both. – Robert Smith May 25 '18 at 20:11
  • Gyan, marked as answer! Could you possibly help me with this one https://stackoverflow.com/questions/50590901/specifying-audio-video-for-a-multiple-stream-multiple-file-setup-using-ffmpeg thank you – Robert Smith May 30 '18 at 13:13