How to do Picture in Picture with FFMPEG

This is a quick example of how you can take two videos and overlay one on the other to create a picture-in-picture scenario. Take the following example:

ffmpeg -i sample-video1.mp4 -i sample-video2.mp4 -filter_complex “[1]scale=iw/4:ih/4 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10″ -ar 44100 -f flv rtmp://localhost:1935/live/myOutStream

This will position the second video on the lower right hand corner of your screen as follows:

Note: The bitrate is horrible in my example so the screen is a bit pixelated. However this was just to demonstrate the basic function of PIP with FFMPEG.

scale=iw/4:ih/4 = The scale/size of the embedded video
overlay=main_w-overlay_w-10:main_h-overlay_h-10 = The position on screen
-f flv rtmp://localhost:1935/live/myOutStream = the destination Wowza server

You can also do this with two live streams, one live and one VOD, and one Live/VOD plus and image. Some examples:

Test with a logo:

ffmpeg -i sample-video1.mp4 -i your-logo.png -filter_complex “[1]scale=iw/4:ih/4 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10″ -ar 44100 -f flv rtmp://localhost:1935/live/myOutStream

Test with a live stream plus a VOD:

ffmpeg -i rtsp://[wowza-server-domain]/vod/mp4:BigBuckBunny_115k.mov -i sample-video2.mp4 -filter_complex “[1]scale=iw/4:ih/4 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10″ -ar 44100 -f flv rtmp://localhost:1935/live/myOutStream


Comments are closed.