0

I am trying to make a single video file with multiple Picture in Picture (PIP for short). I was able to get two picture in a pictures working. I am now trying to add a 4th input.

What I am hoping it will look like:

Mockup Image Example

My Attempted Command:

ffmpeg -i 444_remote_0.webm -i 444_remote_1.webm -i 444_remote_2.webm \
       -i 444_local_0.webm -filter_complex \
       "[1:v]scale=iw/4:-1:flags=lanczos[rem1]; \
        [2:v]scale=iw/4:-1:flags=lanczos[rem2]; \
        [3:v]scale=iw/4:-1:flags=lanczos[loc0]; \
        [0:v][loc0]overlay=main_w-overlay_w-10:main_h-overlay_h-10[bg]; \
        [bg][rem1]overlay=main_w-overlay_w-180:main_h-overlay_h-10[v]; \
        [bg][rem2]overlay=main_w-overlay_w-360:main_h-overlay_h-10[v]; \
        [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \
       -map "[v]" -map "[a]" -ac 2 -ar 44100 -vcodec libx264 -acodec aac 444.mp4

I am getting a new error: Invalid stream specifier: bg.

Console Output:

ffmpeg -i 444_remote_0.webm -i 444_remote_1.webm -i 444_remote_2.webm -i 444_local_0.webm -filter_complex "[1:v]scale=iw/4:-1:flags=lanczos[rem1]; [2:v]scale=iw/4:-1:flags=lanczos[rem2]; [3:v]scale=iw/4:-1:flags=lanczos[loc0]; [0:v][loc0]overlay=main_w-overlay_w-10:main_h-overlay_h-10[bg]; [bg][rem1]overlay=main_w-overlay_w-180:main_h-overlay_h-10[v]; [bg][rem2]overlay=main_w-overlay_w-360:main_h-overlay_h-10[v]; [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" -map "[v]" -map "[a]" -ac 2 -ar 44100 -vcodec libx264 -acodec aac 444.mp4
ffmpeg version N-80901-gfebc862 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from '444_remote_0.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from '444_remote_1.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #1:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #1:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Input #2, matroska,webm, from '444_remote_2.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #2:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #2:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Input #3, matroska,webm, from '444_local_0.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #3:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #3:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
[matroska,webm @ 0x35f5c40] Invalid stream specifier: bg.
    Last message repeated 1 times
Stream specifier 'bg' in filtergraph description [1:v]scale=iw/4:-1:flags=lanczos[rem1]; [2:v]scale=iw/4:-1:flags=lanczos[rem2]; [3:v]scale=iw/4:-1:flags=lanczos[loc0]; [0:v][loc0]overlay=main_w-overlay_w-10:main_h-overlay_h-10[bg]; [bg][rem1]overlay=main_w-overlay_w-180:main_h-overlay_h-10[v]; [bg][rem2]overlay=main_w-overlay_w-360:main_h-overlay_h-10[v]; [0:a][1:a][2:a][3:a]amerge=inputs=4[a] matches no streams.
2
  • You need to show the complete console output from your last command (without -loglevel fatal). – llogan Oct 4 '16 at 22:16
  • @LordNeckbeard Thanks for the input, I had not realized it was appropriate to post that much in the message. I've edited my original post with the full console output. – Daryl Oct 4 '16 at 22:51
2

Placement option 1: hanging to the right

Like your mockup where the pip are weighted to the right:

enter image description here

ffmpeg -i blue.webm -i green.webm -i red.webm -i orange.webm -filter_complex \
"[1:v]scale=iw/4:-1:flags=lanczos[pip1]; \
 [2:v]scale=iw/4:-1:flags=lanczos[pip2]; \
 [3:v]scale=iw/4:-1:flags=lanczos[pip3]; \
 [0:v][pip1]overlay=main_w-overlay_w-10:main_h-overlay_h-10[bg1]; \
 [bg1][pip2]overlay=main_w-overlay_w*2-20:main_h-overlay_h-10[bg2]; \
 [bg2][pip3]overlay=main_w-overlay_w*3-30:main_h-overlay_h-10,format=yuv420p[v]; \
 [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \
-map "[v]" -map "[a]" -ac 1 output.mp4

Placement option 2: centered

enter image description here

ffmpeg -i blue.webm -i green.webm -i red.webm -i orange.webm -filter_complex \
"[1:v]scale=iw/4:-1:flags=lanczos[pip1]; \
 [2:v]scale=iw/4:-1:flags=lanczos[pip2]; \
 [3:v]scale=iw/4:-1:flags=lanczos[pip3]; \
 [0:v][pip1]overlay=main_w-overlay_w-10:main_h-overlay_h-10[bg1]; \
 [bg1][pip2]overlay=(main_w-overlay_w)/2:main_h-overlay_h-10[bg2]; \
 [bg2][pip3]overlay=10:main_h-overlay_h-10,format=yuv420p[v]; \
 [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \
-map "[v]" -map "[a]" -ac 1 output.mp4

Notes

  • Lanczos scale algorithm will probably downscale better than the default.

  • The default number of inputs for amerge is 2, but it's best to always use the inputs option to avoid the issue you experienced.

  • Use a unique name for each output label in the filtergraph.

  • If your inputs don't have the same durations then refer to the overlay options eof_action, shortest, etc, to tell it how it should handle any duration discrepencies.

  • You can use pan and omit -ac to have more precise control over the downsampling layout.

9
  • Thank you so very much! That worked perfectly! I really really appreciate the info. Thanks! – Daryl Oct 5 '16 at 16:05
  • Thanks again. I tried adding a 4th input file, but it didn't seem to like me using the [bg] alias twice. It gave me error: Invalid stream specifier: bg. Alised the 3rd PIP: [3:v]scale=iw/4:-1:flags=lanczos[pip3]; Added another overlay: [bg][pip3]overlay=main_w-overlay_w-180:main_h-overlay_h-10[v]; Updated amerge: [0:a][1:a][2:a][3:a]amerge=inputs=4[a]. Should I post this as separate question? Its a bit long here in the comments. – Daryl Oct 6 '16 at 20:28
  • @Daryl You can edit your question with your new command and the corresponding complete console output. Also, from the answer, "Use a unique name for each output label in the filtergraph". Where do you want the 3rd pip to be placed? – llogan Oct 6 '16 at 21:25
  • thank you so very much. I edited the full console and added a image link to show you how I am trying to lay the videos out. Thanks! – Daryl Oct 6 '16 at 22:03
  • @Daryl What is your preference for the audio: which inputs channels should go to which output channels? What is your desired output channel layout? Mono, stereo? – llogan Oct 6 '16 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.