2

Suppose I have got two videos (AVI format if that matters), say movie1.avi and movie2.avi.

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 movie1.avi.

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.

2 Answers 2

2

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.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 and ih are parameters that take the input width and height, respectively. Look at the scale 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 with 0.5*PTS. See setpts.
  • This is assigned to the [small] link.
  • The [in] and [small] links are then combined with an overlay filter, positioning the top left corner of the smaller video at the middle of the frame. The main_w and main_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
    
1
  • Wow, I did not know ffmpeg was capable of doing this. I will have to play around a bit, as my movies are also completely different in dimension, but with scale and overlay this is something I can certainly fix. I will download the newest ffmpeg :)
    – Bernhard
    Commented Jul 30, 2013 at 15:08
1

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.

1
  • 1
    I'd be interested to know if Windows Movie Maker really lets you do both: composing videos and reduce playback speed of one. Have you tried it? (Same for Kdenlive?)
    – slhck
    Commented Jul 30, 2013 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .