Suppose I have got two videos (AVI format if that matters), say
movie1.avi has a framerate of 10fps.
movie2.avi also has a framerate of 10fps, but has been speed up somewhere, such that it should be played by 5fps.
Now I want to create a new movie, which consists basically of
movie2.avi (slowed down) projected in the lower right corner of
What method can I use to compose these two movies like this? Do I need to decompose them in several frame, compose the images, and make a new movie? Would this keep the qualtity as it is? Are the easily accessible tools to obtain what I want?
Either a Windows or Linux suggestion would do the job for me.
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-overlay_w:main_h-overlay_h [out]" output.avi
For readability, I’ve split the command where the
are. To break it down:
-i movie1.aviis your big input movie.
-filter:v "movie=movie2.aviloads the small movie.
scale=iw/2:ih/2scales down that movie to half of its width and height.
ihare parameters that take the input width and height, respectively. Look at the
scalefilter options if you want to tweak that.
setpts=2.0*PTSlets the video appear twice as slow as the original by “expanding” the individual presentation time stamps of the frames. You could speed it up with
- This is assigned to the
[small]links are then combined with an
overlayfilter, positioning the top left corner of the smaller video at the middle of the frame. The
main_hparameters take the width and height of the frame, so here, you’re selecting the exact middle point.
- This is rendered to
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
You could do it by decomposing frame by frame, but there are a lot of free video-editing software that should allow you do to it mush more easily.
As examples, you may have a look to
Windows Movie Maker as Windows solution, or
kdenlive as a linux solution.
Almost every video-editing software can change playing speed of a video or compose two videos as you describe.