You can use ffmpeg
filters to overlay the video and create a Picture-in-Picture effect. To overlay the movie2.avi
, we'll have to scale it down, and to play it back with a lower frame rate, we'll use another filter.
Your command looks something like this:
ffmpeg -i movie1.avi \
-filter:v "movie=movie2.avi, scale=iw/2:ih/2, setpts=2.0*PTS [small];\
[in][small] overlay=main_w*0.5overlay=main_w-overlay_w:main_h*0.5main_h-overlay_h [out]" output.avi
For readability, I've split the command where the \
are. To break it down:
-i movie1.avi
is your big input movie.-filter:v "movie=movie2.avi
loads the small movie.scale=iw/2:ih/2
scales down that movie to half of its width and height.iw
andih
are parameters that take the input width and height, respectively. Look at thescale
filter options if you want to tweak that.setpts=2.0*PTS
lets the video appear twice as slow as the original by "expanding" the individual presentation time stamps of the frames. You could speed it up with0.5*PTS
. Seesetpts
.- This is assigned to the
[small]
link. - The
[in]
and[small]
links are then combined with anoverlay
filter, positioning the top left corner of the smaller video at the middle of the frame. Themain_w
andmain_h
parameters take the width and height of the frame, so here, you're selecting the exact middle point. - This is rendered to
[out]
.
It could look something like this:
Here are some tips:
Always use a recent version of
ffmpeg
, not the one provided by your Linux distribution. The FFmpeg download page has a list of static builds for each operating system.The command, by default, will use some basic settings regarding video and audio codecs. This can result in the quality looking worse than the original. You can tweak the quality by setting a higher bit rate, or a variable quality flag with
-qscale
. Have a look at the XviD/MPEG-4 encoding guide for AVI video, or choose MP4 as output with the x264 encoder.In practice, this could look like the following:
ffmpeg -i movie1.avi … -c:v libxvid -qscale 2 output.avi ffmpeg -i movie1.avi … -c:v libx264 -crf 21 output.mp4